aboutsummaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-connectivity/mosquitto/files/mosquitto.init
blob: 9d5963c418d8859dbb8de5450a099aa83feb17cf (plain)
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
81
82
83
84
85
86
87
88
89
#! /bin/sh

# Based on the Debian initscript for mosquitto

### BEGIN INIT INFO
# Provides:         mosquitto
# Required-Start:   $remote_fs $syslog
# Required-Stop:    $remote_fs $syslog
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
# Short-Description:    mosquitto MQTT message broker
# Description: 
#  This is a message broker that supports version 3.1/3.1.1 of the MQ Telemetry
#  Transport (MQTT) protocol.
#  
#  MQTT provides a method of carrying out messaging using a publish/subscribe
#  model. It is lightweight, both in terms of bandwidth usage and ease of
#  implementation. This makes it particularly useful at the edge of the network
#  where a sensor or other simple device may be implemented using an arduino for
#  example.
### END INIT INFO

set -e

PIDFILE=@LOCALSTATEDIR@/run/mosquitto.pid
DAEMON=@SBINDIR@/mosquitto

# start and stop the mosquitto MQTT message broker

test -x ${DAEMON} || exit 0

umask 022

. @SYSCONFDIR@/init.d/functions

export PATH="${PATH:+$PATH:}@SBINDIR@:@BASE_SBINDIR@"

case "$1" in
    start)
        echo "Starting Mosquitto message broker" "mosquitto"
        if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c @SYSCONFDIR@/mosquitto/mosquitto.conf ; then
            exit 0
        else
            exit 1
        fi
        ;;
    stop)
        echo "Stopping Mosquitto message broker" "mosquitto"
        if start-stop-daemon --stop --quiet --oknodo --pidfile ${PIDFILE}; then
            rm -f ${PIDFILE}
            exit 0
        else
            exit 1
        fi
        ;;


    reload|force-reload)
        if [ -f ${PIDFILE} ] ; then
            echo "Reloading configuration for mosquitto"
            pid=`cat ${PIDFILE}`
            kill -HUP $pid
        else
            echo "mosquitto does not seem to be running"
        fi
        ;;

    restart)
        echo "Restarting Mosquitto message broker" "mosquitto"
        if start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${PIDFILE}; then
            rm -f ${PIDFILE}
        fi
        if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c @SYSCONFDIR@/mosquitto/mosquitto.conf ; then
            exit 0
        else
            exit 1
        fi
        ;;

    status)
        status ${DAEMON} && exit 0 || exit $?
        ;;

    *)
        echo "Usage: $0 {start|stop|reload|force-reload|restart|status}"
        exit 1
esac

exit 0