/etc/init.d/laptopbat2ups


#! /bin/sh
### BEGIN INIT INFO
# Provides:          laptopbat2ups
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     S 2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Laptop battery to NUT-ups converter
# Description:       Installs a service that converts information
#                    from /sys/class/power_supply/?*[0-9] into the
#                    NUT format, maintaining the file
#                    /var/tmp/laptop-battery-status.
#                    The latter file is the port of some dummy-ups
#                    such that the battery can be monitored by NUT.
### END INIT INFO

# Author: Stephan Seidl <stephan.seidl@stfmc.de>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="laptop battery to NUT-ups converter"
NAME=laptopbat2ups
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

test -x "$DAEMON" || exit 0

. /lib/lsb/init-functions

case "$1" in
	start)
		log_daemon_msg "Starting $DESC" "$NAME"
		start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo 2>/dev/null
		start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON
		log_end_msg ${?}
		;;
	stop)
		log_daemon_msg "Stopping $DESC" "$NAME"
		start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo 2>/dev/null
		log_end_msg 0
		;;
	status)
		status_of_proc "$DAEMON" "$NAME"
		;;
	restart|force-reload)
		log_daemon_msg "Restarting $DESC" "$NAME"
		start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo 2>/dev/null
		start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON
		log_end_msg ${?}
		;;
	*)
		log_success_msg "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}"
		exit 1
		;;
	esac

Stephan K.H. Seidl