mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-26 19:00:34 +02:00
Imported nut changes from glotzi.
This commit is contained in:
173
src/initscripts/init.d/nut
Normal file
173
src/initscripts/init.d/nut
Normal file
@@ -0,0 +1,173 @@
|
||||
#! /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 <aquette@debian.org>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||
|
||||
NAME=nut
|
||||
DESC="Network UPS Tools"
|
||||
DEFAULT=/etc/sysconfig/nut
|
||||
CONFIG=/etc/nut/nut.conf
|
||||
|
||||
. /etc/sysconfig/rc
|
||||
. $rc_functions
|
||||
|
||||
# set upsd specific options. use "man upsd" for more info
|
||||
UPSD_OPTIONS=""
|
||||
|
||||
# set upsmon specific options. use "man upsmon" for more info
|
||||
UPSMON_OPTIONS=""
|
||||
|
||||
# Include defaults if available (transition period)
|
||||
if [ -f $DEFAULT ] ; then
|
||||
. $DEFAULT
|
||||
fi
|
||||
|
||||
# Include NUT nut.conf
|
||||
if [ -f $CONFIG ] ; then
|
||||
. $CONFIG
|
||||
fi
|
||||
|
||||
# Explicitly require the configuration to be done in /etc/nut/nut.conf
|
||||
if [ "x$MODE" = "xnone" ] ; then
|
||||
log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
|
||||
log_failure_msg "and then set MODE to a suitable value in $CONFIG to enable it."
|
||||
# exit success to avoid breaking the install process!
|
||||
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)
|
||||
case "$1" in
|
||||
start)
|
||||
! $upsdrvctl start >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
|
||||
$upsd $UPSD_OPTIONS >/dev/null 2>&1
|
||||
;;
|
||||
stop)
|
||||
$upsd -c stop >/dev/null 2>&1
|
||||
! $upsdrvctl stop >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
none|netclient|*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
start_stop_client () {
|
||||
case "$MODE" in
|
||||
standalone|netserver|netclient)
|
||||
case "$1" in
|
||||
start)
|
||||
$upsmon $UPSMON_OPTIONS >/dev/null 2>&1
|
||||
;;
|
||||
stop)
|
||||
$upsmon -c stop >/dev/null 2>&1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
none|*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
||||
start)
|
||||
boot_mesg "Starting $DESC"
|
||||
check_var_directory
|
||||
start_stop_server start
|
||||
start_stop_client start
|
||||
;;
|
||||
|
||||
stop)
|
||||
boot_mesg "Stopping $DESC"
|
||||
start_stop_server stop
|
||||
start_stop_client stop
|
||||
;;
|
||||
|
||||
reload)
|
||||
$upsd -c reload >/dev/null 2>&1
|
||||
$upsmon -c reload >/dev/null 2>&1
|
||||
;;
|
||||
|
||||
restart|force-reload)
|
||||
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
|
||||
;;
|
||||
|
||||
poweroff)
|
||||
flag=`sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf`
|
||||
wait_delay=`sed -ne 's#^ *POWEROFF_WAIT= *\(.*\)$#\1#p' $CONFIG`
|
||||
if [ -f "$flag" ] ; then
|
||||
if $upsmon -K >/dev/null 2>&1 ; then
|
||||
boot_mesg "Shutting down the UPS ..."
|
||||
sleep 1
|
||||
if $upsdrvctl shutdown ; then
|
||||
sleep 5
|
||||
boot_mesg "Waiting for UPS to cut the power"
|
||||
else
|
||||
boot_mesg "Shutdown failed."
|
||||
boot_mesg "Waiting for UPS batteries to run down"
|
||||
fi
|
||||
if [ "$wait_delay" ] ; then
|
||||
boot_mesg " (will reboot after $wait_delay) ..."
|
||||
sleep "$wait_delay"
|
||||
/etc/init.d/reboot stop
|
||||
fi
|
||||
else
|
||||
boot_mesg "Power down flag is not set (UPS shutdown not needed)"
|
||||
fi
|
||||
else
|
||||
if [ -z "$flag" ] ; then
|
||||
boot_mesg "##########################################################"
|
||||
boot_mesg "## POWERDOWNFLAG is not defined in /etc/nut/upsmon.conf ##"
|
||||
boot_mesg "## ##"
|
||||
boot_mesg "## Please read the Manual page upsmon.conf(5) ##"
|
||||
boot_mesg "##########################################################"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
N=/etc/init.d/$NAME
|
||||
echo "Usage: $N {start|stop|reload|restart|force-reload|poweroff}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
31
src/paks/nut/install.sh
Normal file
31
src/paks/nut/install.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
############################################################################
|
||||
# #
|
||||
# This file is part of the IPFire Firewall. #
|
||||
# #
|
||||
# IPFire is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation; either version 2 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# IPFire is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with IPFire; if not, write to the Free Software #
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
# #
|
||||
# Copyright (C) 2007 IPFire-Team <info@ipfire.org>. #
|
||||
# #
|
||||
############################################################################
|
||||
#
|
||||
. /opt/pakfire/lib/functions.sh
|
||||
|
||||
extract_files
|
||||
restore_backup ${NAME}
|
||||
|
||||
groupadd nut
|
||||
|
||||
start_service --background ${NAME}
|
||||
27
src/paks/nut/uninstall.sh
Normal file
27
src/paks/nut/uninstall.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
############################################################################
|
||||
# #
|
||||
# This file is part of the IPFire Firewall. #
|
||||
# #
|
||||
# IPFire is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation; either version 2 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# IPFire is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with IPFire; if not, write to the Free Software #
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
# #
|
||||
# Copyright (C) 2007 IPFire-Team <info@ipfire.org>. #
|
||||
# #
|
||||
############################################################################
|
||||
#
|
||||
. /opt/pakfire/lib/functions.sh
|
||||
stop_service ${NAME}
|
||||
make_backup ${NAME}
|
||||
remove_files
|
||||
26
src/paks/nut/update.sh
Normal file
26
src/paks/nut/update.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
############################################################################
|
||||
# #
|
||||
# This file is part of the IPFire Firewall. #
|
||||
# #
|
||||
# IPFire is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation; either version 2 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# IPFire is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with IPFire; if not, write to the Free Software #
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
# #
|
||||
# Copyright (C) 2007 IPFire-Team <info@ipfire.org>. #
|
||||
# #
|
||||
############################################################################
|
||||
#
|
||||
. /opt/pakfire/lib/functions.sh
|
||||
./uninstall.sh
|
||||
./install.sh
|
||||
Reference in New Issue
Block a user