1#! /bin/sh
2
3# Based on the Debian initscript for mosquitto
4
5### BEGIN INIT INFO
6# Provides:         mosquitto
7# Required-Start:   $remote_fs $syslog
8# Required-Stop:    $remote_fs $syslog
9# Default-Start:    2 3 4 5
10# Default-Stop:     0 1 6
11# Short-Description:    mosquitto MQTT message broker
12# Description:
13#  This is a message broker that supports version 3.1/3.1.1 of the MQ Telemetry
14#  Transport (MQTT) protocol.
15#
16#  MQTT provides a method of carrying out messaging using a publish/subscribe
17#  model. It is lightweight, both in terms of bandwidth usage and ease of
18#  implementation. This makes it particularly useful at the edge of the network
19#  where a sensor or other simple device may be implemented using an arduino for
20#  example.
21### END INIT INFO
22
23set -e
24
25PIDFILE=@LOCALSTATEDIR@/run/mosquitto.pid
26DAEMON=@SBINDIR@/mosquitto
27
28# start and stop the mosquitto MQTT message broker
29
30test -x ${DAEMON} || exit 0
31
32umask 022
33
34. @SYSCONFDIR@/init.d/functions
35
36export PATH="${PATH:+$PATH:}@SBINDIR@:@BASE_SBINDIR@"
37
38case "$1" in
39    start)
40        echo "Starting Mosquitto message broker" "mosquitto"
41        if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c @SYSCONFDIR@/mosquitto/mosquitto.conf ; then
42            exit 0
43        else
44            exit 1
45        fi
46        ;;
47    stop)
48        echo "Stopping Mosquitto message broker" "mosquitto"
49        if start-stop-daemon --stop --quiet --oknodo --pidfile ${PIDFILE}; then
50            rm -f ${PIDFILE}
51            exit 0
52        else
53            exit 1
54        fi
55        ;;
56
57
58    reload|force-reload)
59        if [ -f ${PIDFILE} ] ; then
60            echo "Reloading configuration for mosquitto"
61            pid=`cat ${PIDFILE}`
62            kill -HUP $pid
63        else
64            echo "mosquitto does not seem to be running"
65        fi
66        ;;
67
68    restart)
69        echo "Restarting Mosquitto message broker" "mosquitto"
70        if start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${PIDFILE}; then
71            rm -f ${PIDFILE}
72        fi
73        if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c @SYSCONFDIR@/mosquitto/mosquitto.conf ; then
74            exit 0
75        else
76            exit 1
77        fi
78        ;;
79
80    status)
81        status ${DAEMON} && exit 0 || exit $?
82        ;;
83
84    *)
85        echo "Usage: $0 {start|stop|reload|force-reload|restart|status}"
86        exit 1
87esac
88
89exit 0
90