--- org/apcupsd.init.4 2016-08-24 21:45:16.762802491 +0200 +++ new/apcupsd.init.4 2016-08-25 00:18:55.221622606 +0200 @@ -3,47 +3,37 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -INSTANCE="${SVCNAME#*.}" -if [ -z "${INSTANCE}" ] || [ "${SVCNAME}" = "apcupsd" ]; then - INSTANCE="apcupsd" -fi +INSTANCE="${RC_SVCNAME#*.}" -dir="/run/apcupsd" +APCUPSD_RUN_DIR="/run/apcupsd" +POWERFAIL_FILE="/etc/apcupsd/powerfail" +INSTANCE_CONF_FILE="/etc/apcupsd/${INSTANCE}.conf" + +description="APC UPS daemon" +name="${description}" +command="/sbin/apcupsd" +pidfile="${APCUPSD_RUN_DIR}/${RC_SVCNAME}.pid" +command_args="-f ${INSTANCE_CONF_FILE} -P ${pidfile}" depend() { - use net + use net mta } -start_pre() { - checkpath -d -m 0775 -o root:uucp ${dir} +_mng_powerfail() { + local UPSNAME=$(awk '{if($1 == "UPSNAME"){print $2}}' ${INSTANCE_CONF_FILE}) + [ -z "${UPSNAME}" ] && UPSNAME=$(hostname) + /etc/apcupsd/apccontrol offbattery ${UPSNAME} + rm -f ${POWERFAIL_FILE} } -start() { - rm -f /etc/apcupsd/powerfail - - export SERVICE="${SVCNAME}" - - if [ ! -d "${dir}" ]; then - einfo " Creating ${dir}" - /bin/mkdir -p "${dir}" - /bin/chown root:uucp "${dir}" - fi - - ebegin "Starting APC UPS daemon" - start-stop-daemon \ - --start --pidfile "${dir}/${SVCNAME}.pid" \ - --exec /sbin/apcupsd -- \ - -f "/etc/apcupsd/${INSTANCE}.conf" \ - -P "${dir}/${SVCNAME}.pid" - eend $? +start_pre() { + checkpath -d -m 0775 -o root:uucp ${APCUPSD_RUN_DIR} } -stop() { - ebegin "Stopping APC UPS daemon" - start-stop-daemon \ - --stop --pidfile "${dir}/${SVCNAME}.pid" \ - --retry TERM/5/TERM/5 \ - --exec /sbin/apcupsd - eend $? +start_post() { + if [ "${INSTANCE}" = "apcupsd" -a -f ${POWERFAIL_FILE} ] + then + sleep 2 + _mng_powerfail + fi } -