Dear maintainers,
can you please apply the following patch to the mosquitto init script?
I fixed the problem with the PID file and made the code formatting more
consistent.
The PID file cannot be created directly in /run as sergio suggested
because mosquitto has no root privileges.
Thank you very much in advance!
Best regards,
Ethan
Index: mosquitto-2.0.11/debian/mosquitto.init
===================================================================
--- mosquitto-2.0.11.orig/debian/mosquitto.init 2021-06-09
14:54:33.000000000 +0200
+++ mosquitto-2.0.11/debian/mosquitto.init 2022-11-08 23:38:28.973747203
+0100
@@ -1,16 +1,16 @@
-#! /bin/sh
+#!/bin/sh
### 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 v3.1 message broker
-# Description:
+# 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 v3.1 message broker
+# Description:
# This is a message broker that supports version 3.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
@@ -20,12 +20,17 @@
set -e
-PIDFILE=/run/mosquitto/mosquitto.pid
+NAME=mosquitto
+USER=mosquitto
DAEMON=/usr/sbin/mosquitto
+PIDDIR=/run/mosquitto
+PIDFILE="${PIDDIR}/mosquitto.pid"
+LOGDIR=/var/log/mosquitto
+CONFFILE=/etc/mosquitto/mosquitto.conf
# /etc/init.d/mosquitto: start and stop the mosquitto MQTT message broker
-test -x ${DAEMON} || exit 0
+test -x "$DAEMON" || exit 0
umask 022
@@ -38,101 +43,110 @@
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
+create_dirs() {
+ mkdir -p "$PIDDIR"
+ chown "$USER" "$PIDDIR"
+ mkdir -p "$LOGDIR"
+ chown "$USER" "$LOGDIR"
+}
+
case "$1" in
- start)
- if init_is_upstart; then
- exit 1
- fi
- log_daemon_msg "Starting network daemon:" "mosquitto"
- if start-stop-daemon --start --quiet --oknodo --background
--make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c
/etc/mosquitto/mosquitto.conf ; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- stop)
- if init_is_upstart; then
- exit 0
- fi
- log_daemon_msg "Stopping network daemon:" "mosquitto"
- if start-stop-daemon --stop --quiet --oknodo --pidfile ${PIDFILE}; then
- log_end_msg 0
- rm -f ${PIDFILE}
- else
- log_end_msg 1
- fi
- ;;
-
-
- reload|force-reload)
- if init_is_upstart; then
- exit 1
- fi
- log_daemon_msg "Reloading network daemon configuration:" "mosquitto"
- if start-stop-daemon --stop --signal HUP --quiet --oknodo
--pidfile $PIDFILE; then
+ start)
+ if init_is_upstart; then
+ exit 1
+ fi
+ create_dirs
+ log_daemon_msg "Starting network daemon" "$NAME"
+ if start-stop-daemon --user "$USER" --chuid "$USER" --start
--quiet --oknodo --background --pidfile "$PIDFILE" --exec "$DAEMON" --
-c "$CONFFILE" ; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+
+ stop)
+ if init_is_upstart; then
+ exit 0
+ fi
+ log_daemon_msg "Stopping network daemon" "$NAME"
+ if start-stop-daemon --user "$USER" --chuid "$USER" --stop
--quiet --oknodo --pidfile "$PIDFILE"; then
+ log_end_msg 0
+ rm -f "$PIDFILE"
+ else
+ log_end_msg 1
+ fi
+ ;;
+
+ reload|force-reload)
+ if init_is_upstart; then
+ exit 1
+ fi
+ log_daemon_msg "Reloading network daemon configuration" "$NAME"
+ if start-stop-daemon --user "$USER" --stop --signal HUP --quiet
--oknodo --pidfile "$PIDFILE"; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+
+ restart)
+ if init_is_upstart; then
+ exit 1
+ fi
+ log_daemon_msg "Restarting network daemon" "$NAME"
+ if start-stop-daemon --user "$USER" --stop --quiet --oknodo
--retry 30 --pidfile "$PIDFILE"; then
+ rm -f "$PIDFILE"
+ fi
+ create_dirs
+ if start-stop-daemon --user "$USER" --chuid "$USER" --start
--quiet --oknodo --background --pidfile "$PIDFILE" --exec "$DAEMON" --
-c "$CONFFILE" ; then
log_end_msg 0
else
log_end_msg 1
- fi
- ;;
+ fi
+ ;;
- restart)
- if init_is_upstart; then
- exit 1
- fi
- log_daemon_msg "Restarting network daemon:" "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
/etc/mosquitto/mosquitto.conf ; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
-
- try-restart)
- if init_is_upstart; then
- exit 1
- fi
- log_daemon_msg "Restarting Mosquitto message broker" "mosquitto"
- set +e
- start-stop-daemon --stop --quiet --retry 30 --pidfile ${PIDFILE}
- RET="$?"
- set -e
- case $RET in
- 0)
- # old daemon stopped
- rm -f ${PIDFILE}
- if start-stop-daemon --start --quiet --oknodo --background
--make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c
/etc/mosquitto/mosquitto.conf ; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- 1)
- # daemon not running
- log_progress_msg "(not running)"
- log_end_msg 0
- ;;
- *)
- # failed to stop
- log_progress_msg "(failed to stop)"
- log_end_msg 1
- ;;
- esac
- ;;
-
- status)
- if init_is_upstart; then
- exit 1
- fi
- status_of_proc -p ${PIDFILE} ${DAEMON} mosquitto && exit 0 || exit $?
- ;;
-
- *)
- log_action_msg "Usage: /etc/init.d/mosquitto
{start|stop|reload|force-reload|restart|try-restart|status}"
- exit 1
+ try-restart)
+ if init_is_upstart; then
+ exit 1
+ fi
+ log_daemon_msg "Trying to restart network daemon" "$NAME"
+ set +e
+ start-stop-daemon --user "$USER" --stop --quiet --retry 30
--pidfile "$PIDFILE"
+ RET="$?"
+ set -e
+ case "$RET" in
+ 0)
+ # old daemon stopped
+ rm -f "$PIDFILE"
+ if start-stop-daemon --user "$USER" --chuid "$USER"
--start --quiet --oknodo --background --pidfile "$PIDFILE" --exec
"$DAEMON" -- -c "$CONFFILE" ; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+ 1)
+ # daemon not running
+ log_progress_msg "(not running)"
+ log_end_msg 0
+ ;;
+ *)
+ # failed to stop
+ log_progress_msg "(failed to stop)"
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+
+ status)
+ if init_is_upstart; then
+ exit 1
+ fi
+ status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 ||
exit "$?"
+ ;;
+
+ *)
+ log_action_msg "Usage: /etc/init.d/mosquitto
{start|stop|reload|force-reload|restart|try-restart|status}"
+ exit 1
esac
exit 0