-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmqtt-control
More file actions
51 lines (46 loc) · 1.08 KB
/
Copy pathmqtt-control
File metadata and controls
51 lines (46 loc) · 1.08 KB
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
#!/bin/sh
PIDFILE="/run/mqtt-control.pid"
if [ ! -f /opt/config/mqtt.conf ]; then
echo "You have to configure mqtt first. Please see /opt/config/mqtt.conf.dist for further instructions"
fi
status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
fi
}
start()
{
if [ -f $PIDFILE ]; then
echo "MQTT Control already running";
else
. /opt/config/mqtt.conf
if [ -z ${AUTODISCOVERY_PREFIX+x} ];
then echo "MQTT autodiscovery is not enabled";
else
echo "MQTT autodiscovery is enabled - now publishing initial configurations";
/opt/scripts/mqtt-autodiscovery.sh
fi
echo "Starting MQTT - Control"
/opt/bin/busybox nohup /opt/scripts/mqtt-control.sh &>/dev/null &
echo "$!" > "$PIDFILE"
fi
}
stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill "$pid" && rm "$PIDFILE"
killall mosquitto_sub 2>/dev/null
killall mosquitto_sub.bin 2>/dev/null
fi
}
if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi