Did I say that I hate systemd?
authorEugene Crosser <crosser@average.org>
Sat, 26 Dec 2015 11:52:32 +0000 (14:52 +0300)
committerEugene Crosser <crosser@average.org>
Sat, 26 Dec 2015 11:52:32 +0000 (14:52 +0300)
linux/pulsecounter.service [new file with mode: 0644]
linux/rc.pulsecounter [new file with mode: 0644]

diff --git a/linux/pulsecounter.service b/linux/pulsecounter.service
new file mode 100644 (file)
index 0000000..941a6c3
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=Water meter pulse counter
+
+[Service]
+Type=forking
+Environment="SENSOR_MAC=xx:xx:xx:xx:xx:xx"
+ExecStart=/usr/local/bin/pulsecounter -d -b ${SENSOR_MAC}
+
+[Install]
+WantedBy=multi-user.target
diff --git a/linux/rc.pulsecounter b/linux/rc.pulsecounter
new file mode 100644 (file)
index 0000000..3e241e2
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides:             pulsecounter
+# Required-Start:       $local_fs $remote_fs $syslog $network
+# Required-Stop:        $local_fs $remote_fs $syslog $network
+# Default-Start:        2 3 4 5
+# Default-Stop:         0 1 6
+# Short-Description:    Water meter pulse counter
+### END INIT INFO
+
+PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"
+DAEMON="/usr/local/bin/pulsecounter"
+
+test -x "$DAEMON" || exit 0
+
+NAME="pulsecounter"\
+DESC="Water meter pulse counter"
+PIDFILE="/var/run/pulsecounter.pid"
+DEFAULTS="/etc/default/pulsecounter"
+
+set -e
+
+[ -r "$DEFAULTS" ] && . "$DEFAULTS"
+
+. /lib/lsb/init-functions
+
+do_start()
+{
+       start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- \
+               -d -b $SENSOR_MAC
+}
+
+do_stop ()
+{
+       start-stop-daemon --stop --quiet --oknodo --name $NAME
+}
+
+case "$1" in
+       start)
+               init_is_upstart > /dev/null 2>&1 && exit 1
+               log_daemon_msg "Starting $DESC" "$NAME"
+               do_start
+               log_end_msg $?
+               ;;
+       stop)
+               init_is_upstart > /dev/null 2>&1 && exit 0
+               log_daemon_msg "Stopping $DESC" "$NAME"
+               do_stop
+               log_end_msg $?
+               ;;
+       restart|force-reload)
+               init_is_upstart > /dev/null 2>&1 && exit 1
+               log_daemon_msg "Restarting $DESC" "$NAME"
+               do_stop
+               sleep 1
+               do_start
+               log_end_msg $?
+               ;;
+       status)
+               status_of_proc $DAEMON $NAME
+               ;;
+       *)
+               echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
+               exit 3
+               ''
+esac
+