#!/sbin/openrc-run # Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ INSTANCE="${RC_SVCNAME#*.}" 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 mta } _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_pre() { checkpath -d -m 0775 -o root:uucp ${APCUPSD_RUN_DIR} } start_post() { if [ "${INSTANCE}" = "apcupsd" -a -f ${POWERFAIL_FILE} ] then sleep 2 _mng_powerfail fi }