From ad67879975d692a6ef9ab7436e93132b00d4d058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radoslav=20Bod=C3=B3?= Date: Wed, 12 Jun 2024 17:18:26 +0200 Subject: [PATCH] packaging: add statusd daemon refactored https://github.com/eLvErDe/hwraid/blob/master/packaging/debian/megaclisas-status/megaclisas-status.megaclisas-statusd.init --- .gitignore | 1 + Makefile | 3 +- debian/control | 6 +- debian/dirs | 1 + debian/perccli-statusd.init | 202 ++++++++++++++++++++++++++++++++++++ debian/rules | 9 +- 6 files changed, 210 insertions(+), 12 deletions(-) create mode 100644 debian/dirs create mode 100644 debian/perccli-statusd.init diff --git a/.gitignore b/.gitignore index f388972..001bfac 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ dist debian/.debhelper/ debian/debhelper-build-stamp debian/files +debian/perccli-status.debhelper.log debian/perccli-status.substvars debian/perccli-status/ venv/ diff --git a/Makefile b/Makefile index cd2d396..8657862 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,7 @@ coverage: install: - mkdir -p $(DESTDIR)/usr/bin - install -m0755 perccli_status.py $(DESTDIR)/usr/bin/perccli-status + install -m0755 perccli_status.py $(DESTDIR)/usr/sbin/perccli-status install-build: apt-get update && apt-get install -y build-essential devscripts diff --git a/debian/control b/debian/control index dbc4ab7..d30161e 100644 --- a/debian/control +++ b/debian/control @@ -4,15 +4,13 @@ Priority: optional Maintainer: Radoslav Bodó Rules-Requires-Root: no Build-Depends: - debhelper-compat (= 13), + debhelper-compat (= 13) Standards-Version: 4.6.2 Homepage: https://github.com/bodik/perccli-status -#Vcs-Browser: https://salsa.debian.org/debian/perccli-status -#Vcs-Git: https://salsa.debian.org/debian/perccli-status.git Package: perccli-status Architecture: any -Depends: perccli2 +Depends: perccli2, daemon Description: The perccli-status software is a query tool to access the running configuration and status of PERC SAS HBAs. . diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..62015e5 --- /dev/null +++ b/debian/dirs @@ -0,0 +1 @@ +/usr/sbin \ No newline at end of file diff --git a/debian/perccli-statusd.init b/debian/perccli-statusd.init new file mode 100644 index 0000000..514d046 --- /dev/null +++ b/debian/perccli-statusd.init @@ -0,0 +1,202 @@ +#! /bin/sh + +# Author: Petter Reinholdtsen +# Author: Radoslav Bodó +# License: GNU General Public License v2 or later +# +### BEGIN INIT INFO +# Provides: perccli-statusd +# Description: Check perccli-status values in the background. +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Check perccli-status values in the background. +### END INIT INFO + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +DESC="perccli-status monitor" +NAME=perccli-statusd +PIDFILE=/var/run/$NAME.pid +STATUSFILE=/var/run/$NAME.status +SCRIPTNAME=/etc/init.d/$NAME + + +# Do not touch you can configure this in /etc/default/perccli-statusd +MAILTO=root # Where to report problems +PERIOD=600 # Seconds between each check (default 10 minutes) +REMIND=7200 # Seconds between each reminder (default 2 hours) +RUN_DAEMON=yes + +[ -e /etc/default/perccli-statusd ] && . /etc/default/perccli-statusd + +# Gracefully exit if the package has been removed. +test -x /usr/sbin/perccli-status || exit 0 + +. /lib/lsb/init-functions +[ -e /etc/default/rcS ] && . /etc/default/rcS + +if [ $RUN_DAEMON = "no" ] ; then + log_begin_msg "perccli-statusd is disabled in /etc/default/perccli-statusd, not starting." + log_end_msg 0 + exit 0 +fi + +check_perccli() { + echo $$ > $PIDFILE.new && mv $PIDFILE.new $PIDFILE + while true ; do + # Check ever $PERIOD seconds, send email on every status + # change and repeat ever $REMIND seconds if the raid is still + # bad. + if (perccli-status); then + BADRAID=false + else + BADRAID=true + logger -t perccli-statusd "detected non-optimal RAID status" + fi + STATUSCHANGE=false + if [ true = "$BADRAID" ] ; then + # RAID not OK + (perccli-status) > $STATUSFILE.new + if [ ! -f $STATUSFILE ] ; then # RAID just became broken + STATUSCHANGE=true + mv $STATUSFILE.new $STATUSFILE + elif cmp -s $STATUSFILE $STATUSFILE.new ; then + # No change. Should we send reminder? + LASTTIME="`stat -c '%Z' $STATUSFILE`" + NOW="`date +%s`" + SINCELAST="`expr $NOW - $LASTTIME`" + if [ $REMIND -le "$SINCELAST" ]; then + # Time to send reminder + STATUSCHANGE=true + mv $STATUSFILE.new $STATUSFILE + else + rm $STATUSFILE.new + fi + else + STATUSCHANGE=true + mv $STATUSFILE.new $STATUSFILE + fi + else + # RAID OK + if [ -f $STATUSFILE ] ; then + rm $STATUSFILE + STATUSCHANGE=true + fi + fi + + if [ true = "$STATUSCHANGE" ]; then + hostname="`uname -n`" + ( + cat < /dev/null 2>&1 + rm -f $PIDFILE + else + log_progress_msg "Daemon is already stopped." + return 0 + fi +} + +# This is a workaround function which does not directly exit and +# therefore can be used by a restart +d_stop_by_restart() { + if [ -f $PIDFILE ] ; then + start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE + rm -f $PIDFILE + log_end_msg 0 + else + log_progress_msg "Daemon is already stopped." + log_end_msg 0 + fi +} + +case "$1" in + start) + echo -n "" + log_begin_msg "Starting $DESC: $NAME" + d_start ; CODE=$? + log_end_msg $CODE + ;; + stop) + log_begin_msg "Stopping $DESC: $NAME" + d_stop ; CODE=$? + log_end_msg $CODE + ;; + check_perccli) + check_perccli + ;; + status) + status_of_proc /usr/bin/daemon $NAME + exit $? + ;; + restart|force-reload) + log_begin_msg "Restarting $DESC: $NAME" + d_stop_by_restart + sleep 1 + d_start || CODE=$? + log_end_msg $CODE + ;; + *) + # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/debian/rules b/debian/rules index 6207097..bc7b52d 100755 --- a/debian/rules +++ b/debian/rules @@ -1,13 +1,10 @@ #!/usr/bin/make -f -# See debhelper(7) (uncomment to enable). -# Output every command that modifies files on the build system. export DH_VERBOSE = 1 - - -# See FEATURE AREAS in dpkg-buildflags(1). export DEB_BUILD_MAINT_OPTIONS = hardening=+all - %: dh $@ + +override_dh_installinit: + dh_installinit --name=perccli-statusd