motd-gen

my Message of the Day scripts
git clone git://git.ckyln.com/motd-gen
Log | Files | Refs | README | LICENSE

commit ddfdcf47e1e9b46732604da17ec9c8feeb14654c
parent 46ee7d7e42e0d86a145531361b2f1c4319f0802d
Author: Cem Keylan <cem@ckyln.com>
Date:   Thu,  2 Jan 2020 13:52:58 +0300

add services

Diffstat:
ASHAREDIR/60-services.motd | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+), 0 deletions(-)

diff --git a/SHAREDIR/60-services.motd b/SHAREDIR/60-services.motd @@ -0,0 +1,59 @@ +CHECKFILE=/etc/motd-check +COLUMNS=3 + +# So the checkfile is a csv file +# the first value is what service it +# is. + +# For a runit service, it starts with r +# For a docker container it starts with d +# For a systemd service, it starts with s + +systemdcheck() { + printf "\033[1;00m$1: " + if systemctl is-active "$1" >/dev/null 2>&1 ;then + printf "\033[1;32mActive " + else + printf "\033[1;31mInactive " + fi + printf "\033[0;00m" +} + +runitcheck() { + printf "\033[1;00m$1: " + if sv stat "$1" | grep -q down ; then + printf "\033[1;31mInactive " + else + printf "\033[1;32mActive " + fi + printf "\033[0;00m" +} + +dockercheck() { + printf "\033[1;00m$1: " + if docker container ls | grep -q "$1"; then + printf "\033[1;32mActive " + else + printf "\033[1;31mInactive " + fi + printf "\033[0;00m" +} + +check() { + local number + number=0 + while IFS=, read -r service program ; do + number=$(( $number + 1 )) + case "$service" in + s) systemdcheck "$program" ;; + r) runitcheck "$program" ;; + d) dockercheck "$program" ;; + esac + [ $(( $number % $COLUMNS )) -eq 0 ] && printf "\n" + done < "$CHECKFILE" + printf "\n" +} + +[ -n "$CHECKFILE" ] && check + +# vim:filetype=sh