From ea9fc7071245b9b3142bcadf92c02873be6f80fd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 26 Aug 2021 05:33:05 -0400 Subject: [PATCH] Added service monitoring functionality to tmux-idle. --- README.md | 2 +- bash/tmux-idle | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f1543a..c1b29c4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This simple script shows the hardware model of a raspberry pi. That is all. This isn't so much a script as some small quality of life improvements I've made to my WSL Ubuntu 20.04 systems and Ubuntu 20.04 server. Add whichever you like to the end of your .profile and use 'source ~/.profile' to load it immediately. **tmux-idle** -This script just chills in one of my idle tmux windows and shows me the weather. Planning to update it internally to also show the status of my services. +This script just chills in one of my idle tmux windows and shows me the weather. Also added functionality to allow a quick glance at any services that I want to monitor. (All user-configurable options at the top of the file) ### AutoHotKey diff --git a/bash/tmux-idle b/bash/tmux-idle index 120c295..19168bd 100755 --- a/bash/tmux-idle +++ b/bash/tmux-idle @@ -2,6 +2,8 @@ # Enter your zipcode here for local weather. zipcode=20001 +# Add the services you want to monitor here as an array +servicelist=('apache2' 'gitea' 'postfix') # Colors are nice blk=$(tput setaf 0) @@ -25,7 +27,7 @@ rows=$(tput lines) trap ctrl_c INT function ctrl_c() { - clear + #clear tput cnorm echo "${rst}${red}CTRL+C Detected, exiting.${rst}" exit @@ -54,6 +56,39 @@ function dothething() { tput cup 0 0 } +# This be where we check the services +function servicecheck(){ + # If we're not monitoring any services, return + [ ${#servicelist[@]} -eq 0 ] && return + # These are the allowed rows + # TODO? determine lines from after weather print? + servicerow=(15 16 17 18 19) + # These are the allowed columns + # TODO? allow column count instead of static assignments? + servicecol=(1 25 50) + # Loop over the number of services that we're monitoring + # https://askubuntu.com/a/1340735 + for index in $(seq 0 $((${#servicelist[@]}-1))); do + # Determine the position of the current service + # we go across and then down + # TODO? allow for variable columns? + let echocol="${servicecol[${index}%3]}" + let echorow="${servicerow[${index}/3]}" + # Put our cursor where we can print + tput cup $echorow $echocol + # Clear the variables we use + unset echocol echorow + # Do the actual service check. is-active returns + # active or inactive. Easy peasy + servicestatus=`systemctl is-active ${servicelist[${index}]}` + # Print out the status, green with a dot (\U25CF) if it's online + # and red with a square (\U25A0) if it's stopped + [ "${servicestatus}" == "active" ] && echo -en "${grn}\U25CF ${servicelist[${index}]}${rst}" || echo -en "${red}\U25A0 ${servicelist[${index}]}${rst}" + done + tput cup 0 0 +} + + # Clear the screen and let's get going clear # Make the cursor invisible for the terminal @@ -73,6 +108,8 @@ while true; do dothething fi fi + # I don't think checking every second is a problem... yet... + servicecheck # Sleep for a second so we're not hammering the system # with date checks. sleep 1