From: Dirk Wagner Date: Mon, 9 Nov 2009 20:22:19 +0000 (+0100) Subject: nut: Added status option, some installation fixed X-Git-Tag: v2.9-beta1~615 X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=commitdiff_plain;h=df2aa8e12aed36334236a5ad355a388b90ea5b4b;hp=9dfa84ec02919f45bf9c8142a7bd08f6a6173841 nut: Added status option, some installation fixed --- diff --git a/config/rootfiles/packages/nut b/config/rootfiles/packages/nut index 146d320a32..c4ebe19921 100644 --- a/config/rootfiles/packages/nut +++ b/config/rootfiles/packages/nut @@ -1,4 +1,5 @@ var/ipfire/backup/addons/includes/nut +var/state/ups etc/rc.d/init.d/nut #etc/nut etc/nut/nut.conf.sample diff --git a/lfs/nut b/lfs/nut index 3ecf78de9c..93672d9374 100644 --- a/lfs/nut +++ b/lfs/nut @@ -82,6 +82,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) --with-wrap=no --with-udev-dir=/etc/udev cd $(DIR_APP) && make $(MAKETUNING) cd $(DIR_APP) && make install + -mkdir -p /var/state/ups install -v -m 644 $(DIR_SRC)/config/backup/includes/nut \ /var/ipfire/backup/addons/includes/nut @rm -rf $(DIR_APP) diff --git a/src/initscripts/init.d/nut b/src/initscripts/init.d/nut old mode 100644 new mode 100755 index 43f7092c22..8aba4ff1b4 --- a/src/initscripts/init.d/nut +++ b/src/initscripts/init.d/nut @@ -1,17 +1,4 @@ #! /bin/sh -### BEGIN INIT INFO -# Provides: nut -# Required-Start: $local_fs $syslog $network -# Required-Stop: $local_fs $syslog $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Network UPS Tools initscript -# Description: This script take care of starting and stopping the -# Network UPS Tools components. When needed, it also -# handle the UPS hardware shutdown. -### END INIT INFO - -# Author: Arnaud Quette PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin @@ -47,21 +34,11 @@ if [ "x$MODE" = "xnone" ] ; then exit 0 fi -pid_dir=/var/run/nut -upsmon_pid=${pid_dir}/upsmon.pid -upsd_pid=${pid_dir}/upsd.pid upsd=/usr/sbin/upsd upsdrvctl=/usr/bin/upsdrvctl upsmon=/usr/sbin/upsmon log=">/dev/null 2>/dev/null" -# Check if /var/run/nut exists and has the correct perms -check_var_directory() { - [ ! -d ${pid_dir} ] && mkdir -p ${pid_dir} \ - && chown root:nut ${pid_dir} \ - && chmod 770 ${pid_dir} -} - start_stop_server () { case "$MODE" in standalone|netserver) @@ -69,9 +46,11 @@ start_stop_server () { start) ! $upsdrvctl start >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)" $upsd $UPSD_OPTIONS >/dev/null 2>&1 + evaluate_retval ;; stop) $upsd -c stop >/dev/null 2>&1 + evaluate_retval ! $upsdrvctl stop >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)" ;; esac @@ -88,9 +67,11 @@ start_stop_client () { case "$1" in start) $upsmon $UPSMON_OPTIONS >/dev/null 2>&1 + evaluate_retval ;; stop) $upsmon -c stop >/dev/null 2>&1 + evaluate_retval ;; esac ;; @@ -100,17 +81,39 @@ start_stop_client () { esac } +status_server () { + case "$MODE" in + standalone|netserver) + statusproc $upsd + statusproc $upsmon + ;; + none|netclient|*) + return 1 + ;; + esac +} + +status_client () { + case "$MODE" in + standalone|netclient) + statusproc $upsmon + ;; + none|*) + return 1 + ;; + esac +} + case "$1" in start) - boot_mesg "Starting $DESC" - check_var_directory + boot_mesg "Starting $DESC ..." start_stop_server start start_stop_client start ;; stop) - boot_mesg "Stopping $DESC" + boot_mesg "Stopping $DESC ..." start_stop_server stop start_stop_client stop ;; @@ -120,12 +123,16 @@ case "$1" in $upsmon -c reload >/dev/null 2>&1 ;; + status) + status_server + status_client + ;; + restart|force-reload) - boot_mesg "Restarting $DESC" + boot_mesg "Restarting $DESC ..." start_stop_client stop start_stop_server stop sleep 5 - check_var_directory start_stop_server start start_stop_client start ;; @@ -165,7 +172,7 @@ case "$1" in *) N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|reload|restart|force-reload|poweroff}" >&2 + echo "Usage: $N {start|stop|status|reload|restart|force-reload|poweroff}" >&2 exit 1 ;; esac diff --git a/src/paks/nut/install.sh b/src/paks/nut/install.sh index 2a07532f7a..d117ad88fc 100644 --- a/src/paks/nut/install.sh +++ b/src/paks/nut/install.sh @@ -28,4 +28,8 @@ restore_backup ${NAME} groupadd nut +ln -svf ../init.d/nut /etc/rc.d/rc0.d/K20nut +ln -svf ../init.d/nut /etc/rc.d/rc3.d/S20nut +ln -svf ../init.d/nut /etc/rc.d/rc6.d/K20nut + start_service --background ${NAME} diff --git a/src/paks/nut/uninstall.sh b/src/paks/nut/uninstall.sh index a7b8a5370f..2cce359738 100644 --- a/src/paks/nut/uninstall.sh +++ b/src/paks/nut/uninstall.sh @@ -25,3 +25,5 @@ stop_service ${NAME} make_backup ${NAME} remove_files + +rm -rf /etc/rc.d/rc*.d/*nut \ No newline at end of file