mqtt.sh
1.18 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
#!/bin/bash
export LD_LIBRARY_PATH="/opt/stack/lib/mqtt_lib"
user=mosquitto
PIDFILE=/opt/stack/mqtt/log/mqtt.pid
pid=$(ps -u $user |tail -n 1 |awk '{print $1}')
case $1 in
start) echo -n "Starting MQTT: "
if [ "$pid" = "PID" ]; then
test -f $PIDFILE && rm $PIDFILE
/opt/stack/mqtt/sbin/mosquitto -d -c /opt/stack/mqtt/conf/mosquitto.conf 2>/dev/null
if [ $? -eq 0 ]; then
#ps -u $user |tail -n 1 |awk '{print $1}' 1>$PIDFILE
echo "success"
else echo "failed"
exit 1
fi
else echo "running"
fi
;;
stop) echo -n "Stoping MQTT: "
if [ "$pid" = "PID" ]; then
echo "inactive"
else kill -SIGTERM $pid 2>/dev/null && rm "$PIDFILE"
echo "stopped"
fi
;;
status)
if [ -s $PIDFILE ]; then
if ps -p $(cat $PIDFILE) > /dev/null; then
echo "mqtt is running"
STATUS=0
else echo "found PID file but not running"
STATUS=1
fi
elif [ -f $PIDFILE ]; then
echo "PID file size is zero and not running"
STATUS=2
else echo "mqtt is not running"
STATUS=3
fi
;;
*) echo "not im"
esac