diff options
Diffstat (limited to 'package/apcupsd/files')
| -rw-r--r-- | package/apcupsd/files/apccontrol | 74 | ||||
| -rw-r--r-- | package/apcupsd/files/apcupsd.conffiles | 1 | ||||
| -rw-r--r-- | package/apcupsd/files/apcupsd.init | 38 | ||||
| -rw-r--r-- | package/apcupsd/files/apcupsd.postinst | 3 | 
4 files changed, 116 insertions, 0 deletions
| diff --git a/package/apcupsd/files/apccontrol b/package/apcupsd/files/apccontrol new file mode 100644 index 000000000..e402c513d --- /dev/null +++ b/package/apcupsd/files/apccontrol @@ -0,0 +1,74 @@ +#!/bin/sh +# +# A custom apccontrol for use in embedded systems: just make sure there's no +# data in-flight and wait for the blackout to shut us down. + +# these filesystems are not relevant +IGNORE_FS="tmpfs proc sysfs devtmpfs devpts nfsd" + +get_rw_mounts() { +	local excl='\((ro,\|type \(' +	local sep="" +	for fs in $IGNORE_FS; do +		excl+="${sep}$fs" +		sep='\|' +	done +	excl+='\)\)' +	mount | grep -v "$excl" | while read dev on mnt opts; do +		echo "$mnt" +	done +} + +log() { +	logger -s -t "$(basename $0)" -p daemon.crit "$*" +} +__mount() { # (ro/rw, txt, mnt) +	local opt=$1 +	local txt=$2 +	local mnt="$3" + +	mount -o remount,$opt "$mnt" +	rc=$? +	case $rc in +	0) log "remounted $mnt $txt" +	*) log "failed to remount $mnt $txt: rc=$rc" +	esac +	return $rc +} +mount_ro() { +	__mount ro read-only "$1" +} +mount_rw() { +	__mount rw read-write "$1" +} + +romounts="/tmp/apcupsd.romounts" + +case "$1" in +	emergency|failing) +		log "UPS error condition happening" +		;& # fall through +	doshutdown) +		log "bracing for upcoming blackout" + +		rm -f "$romounts" +		sync +		get_rw_mounts | while read mnt; do +			mount_ro "$mnt" && echo "$mnt" >>"$romounts" +		done +		;; +	mainsback) +		log "returning to routine after near blackout" + +		touch "$romounts" +		while read mnt; do +			mount_rw "$mnt" +		done <"$romounts" +		rm "$romounts" +		;; +	*) +		log "Called for $1" +		;; +esac + +exit 0 diff --git a/package/apcupsd/files/apcupsd.conffiles b/package/apcupsd/files/apcupsd.conffiles new file mode 100644 index 000000000..7bae4c961 --- /dev/null +++ b/package/apcupsd/files/apcupsd.conffiles @@ -0,0 +1 @@ +/etc/apcupsd.conf diff --git a/package/apcupsd/files/apcupsd.init b/package/apcupsd/files/apcupsd.init new file mode 100644 index 000000000..a9817f1be --- /dev/null +++ b/package/apcupsd/files/apcupsd.init @@ -0,0 +1,38 @@ +#!/bin/sh +#PKG apcupsd +#INIT 15 +. /etc/rc.conf + +pidfile=$(echo "$apcupsd_flags" | \ +	  sed -n 's/.*\(-P\|--pid-file\) \([^ ]\+\).*/\2/p') +[ "$pidfile" ] || pidfile="/var/run/apcupsd.pid" + +case $1 in +autostop) ;; +autostart) +	test x"${apcupsd:-NO}" = x"NO" && exit 0 +	test x"$apcupsd" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start +	exec sh $0 start +	;; +start) +	mkdir -p /var/lock +	/usr/sbin/apcupsd $apcupsd_flags +	;; +stop) +	if [ -f "$pidfile" ]; then +		kill $(<$pidfile) +		rm -f $pidfile +	else +		kill $(pgrep -f /usr/sbin/apcupsd) +	fi +	;; +restart) +	sh $0 stop +	sleep 1 +	sh $0 start +	;; +*) +	echo "usage: $0 (start | stop | restart)" +	exit 1 +esac +exit $? diff --git a/package/apcupsd/files/apcupsd.postinst b/package/apcupsd/files/apcupsd.postinst new file mode 100644 index 000000000..299fabc0f --- /dev/null +++ b/package/apcupsd/files/apcupsd.postinst @@ -0,0 +1,3 @@ +#!/bin/sh +. $IPKG_INSTROOT/etc/functions.sh +add_rcconf apcupsd NO | 
