-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.d-example.currentcost-power
executable file
·69 lines (62 loc) · 1.56 KB
/
init.d-example.currentcost-power
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
### BEGIN INIT INFO
# Provides: currentcost-power
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: mqtt client to publish current cost power data
### END INIT INFO
# configure the following and copy this file to: /etc/init.d/currentcost-power
# then run: update-rc.d smib defaults
NAME=currentcost-power
SCRIPT=/home/name/mqtt-clients/currentcost-power
RUNAS=name
PIDFILE=/var/run/${NAME}.pid
start() {
if [ -f /var/run/$PIDFILE ] && kill -0 $(cat /var/run/$PIDFILE); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
su -c "$SCRIPT 2>&1 | logger -t '$NAME' & jobs -p" "$RUNAS" >"$PIDFILE"
echo 'Service started' >&2
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service…' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}
uninstall() {
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
local SURE
read SURE
if [ "$SURE" = "yes" ]; then
stop
rm -f "$PIDFILE"
echo "Notice: log file is not be removed: '$LOGFILE'" >&2
update-rc.d -f smib remove
rm -fv "$0"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
uninstall)
uninstall
;;
retart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac