Created
February 4, 2018 06:42
-
-
Save MansoorMajeed/bdba4f82f1fb84f7ecfa81b8d377eeb9 to your computer and use it in GitHub Desktop.
Init script for mosquitto (Tested on Ubuntu 14.04)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: mosquitto | |
# Required-Start: $local_fs $remote_fs $network | |
# Required-Stop: $local_fs $remote_fs $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start or stop the mosquitto service | |
### END INIT INFO | |
USER="mosquitto" | |
CONFIG="/etc/mosquitto/mosquitto.conf" | |
NAME=mosquitto | |
DAEMON="/usr/sbin/mosquitto" | |
OPTIONS="-c ${CONFIG}" | |
PIDFILE="/var/run/${NAME}.pid" | |
. /lib/lsb/init-functions | |
do_start() { | |
echo "Starting daemon $NAME..." | |
start-stop-daemon --start --background \ | |
--chuid $USER \ | |
--name $NAME \ | |
--make-pidfile --pidfile $PIDFILE \ | |
--startas /bin/bash -- -c "exec $DAEMON $OPTIONS 1>/dev/null" || return 2 | |
} | |
do_stop () { | |
echo "Stopping daemon $NAME.." | |
start-stop-daemon --stop --signal INT --quiet \ | |
--chuid $USER \ | |
--exec $DAEMON --pidfile $PIDFILE --retry 30 \ | |
--oknodo | |
RETVAL="$?" | |
sleep 1 | |
return "$RETVAL" | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_stop | |
sleep 5 | |
do_start | |
;; | |
status) | |
status_of_proc "$DAEMON" "$NAME" | |
exit $? | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment