motd-gen

my motd scripts
git clone git://git.ckyln.com/~cem/motd-gen.git
Log | Files | Refs | README | LICENSE

60-services.motd (1231B)


      1 CHECKFILE=/etc/motd-check
      2 COLUMNS=3
      3 
      4 # So the checkfile is a csv file
      5 # the first value is what service it
      6 # is.
      7 
      8 # For a runit service, it starts with r
      9 # For a docker container it starts with d
     10 # For a systemd service, it starts with s
     11 
     12 systemdcheck() {
     13 	printf "\033[1;00m$1: "
     14 	if systemctl is-active "$1" >/dev/null 2>&1 ;then
     15 		printf "\033[1;32mActive      "
     16 	else
     17 		printf "\033[1;31mInactive    "
     18 	fi
     19 	printf "\033[0;00m"
     20 }
     21 
     22 runitcheck() {
     23 	printf "\033[1;00m$1: "
     24 	if sv stat "$1" | grep -q down ; then 
     25 		printf "\033[1;31mInactive    "
     26 	else
     27 		printf "\033[1;32mActive      "
     28 	fi
     29 	printf "\033[0;00m"
     30 }
     31 
     32 dockercheck() {
     33 	printf "\033[1;00m$1: "
     34 	if docker container ls | grep -q "$1"; then 
     35 		printf "\033[1;32mActive      "
     36 	else
     37 		printf "\033[1;31mInactive    "
     38 	fi
     39 	printf "\033[0;00m"
     40 }
     41 
     42 check() {
     43 	printf "\033[1mSystem Services\033[0;00m\\n"
     44 	local number
     45 	number=0
     46 	while IFS=, read -r service program ; do
     47 		number=$(( $number + 1 ))
     48 		case "$service" in
     49 			s) systemdcheck "$program" ;;
     50 			r) runitcheck "$program" ;;
     51 			d) dockercheck "$program" ;;
     52 		esac
     53 		[ $(( $number % $COLUMNS )) -eq 0 ] && printf "\n"
     54 	done < "$CHECKFILE" | column -t
     55 	printf "\n\n"
     56 }
     57 
     58 [ -n "$CHECKFILE" ] && check
     59 
     60 # vim:filetype=sh