-
Notifications
You must be signed in to change notification settings - Fork 0
/
yocto_exporter.init
executable file
·80 lines (70 loc) · 1.74 KB
/
yocto_exporter.init
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
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
### BEGIN INIT INFO
# Provides: yocto_exporter
# 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: Yoctopuce sensor exporter for prometheus
### END INIT INFO
DAEMON=/opt/YoctoSensors/bin/yocto_exporter
NAME=yocto_exporter
PIDFILE=/var/run/prometheus/$NAME.pid
LOGFILE=/var/log/prometheus/$NAME.log
# optionally override defaults
# ARGS="--bind_ip=192.169.1.1 --bind_port=8000"
ARGS=""
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
do_start_prepare()
{
mkdir -p `dirname $PIDFILE` || true
mkdir -p `dirname $LOGFILE` || true
chown -R $USER: `dirname $LOGFILE`
chown -R $USER: `dirname $PIDFILE`
}
do_start_cmd()
{
do_start_prepare
echo -n "Starting daemon: "$NAME
start-stop-daemon -C --background --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $ARGS >> $LOGFILE 2>&1
echo "."
}
do_stop_cmd()
{
echo -n "Stopping daemon: "$NAME
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
rm $PIDFILE
echo "."
}
status() {
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
printf "%s\n" "The process appears to be dead but pidfile still exists"
else
echo "Running, the PID is $PID"
fi
else
printf "%s\n" "Service not running"
fi
}
case "$1" in
start)
do_start_cmd
;;
stop)
do_stop_cmd
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: $1 {start|stop|status|restart}"
exit 1
esac
exit 0