Bug#993048: mosquitto init script broken with bullseye update

2022-11-08 Thread Ethan Trevor

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.0 +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 

Bug#993048: mosquitto init script broken with bullseye update

2021-10-16 Thread sergio
I believe the pidfile should be moved to the /run directly as this done 
for others.


--- mosquitto.orig  2021-10-16 20:12:03.825565077 +0300
+++ mosquitto   2021-10-16 20:11:06.149857678 +0300
@@ -20,7 +20,7 @@

 set -e

-PIDFILE=/run/mosquitto/mosquitto.pid
+PIDFILE=/run/mosquitto.pid
 DAEMON=/usr/sbin/mosquitto

 # /etc/init.d/mosquitto: start and stop the mosquitto MQTT message broker


--
sergio.



Bug#993048: mosquitto init script broken with bullseye update

2021-08-26 Thread Chris Zubrzycki
Package: mosquitto
Version: 2.0.11-1
Severity: important
Tags: patch

Dear Maintainer,

With the 2.0 upgrade, mosquitto now writes a pid file on it's own as the
mosquitto user. This breaks the init script as the run directory is root
writable, and on top of that the init script uses s-s-d to also write a
root-owned pid file. The attached patch should match the behavior of the
systemd file, which is let the daemon write it's own pid file in
/var/run/mosquitto/ and chowns the dir to allow it. I have disabled
s-s-d from making a root owned file, and also added a match to the
mosquitto user for stopping/reloading as the new policy says non-root
pid files are insecure unless additional matches are present.


Oh, and listener 1883 needs to be added ito the config otherwise mosquitto
only listens on loopback which will break most existing installs.

references:
https://issues.apache.org/jira/secure/attachment/13001569/0001-Fix-init-script-for-debian-Buster.patch
https://github.com/eclipse/mosquitto/issues/1950

-- System Information:
Debian Release: 11.0
 APT prefers stable
 APT policy: (700, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-8-amd64 (SMP w/4 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to en_US.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)
LSM: AppArmor: enabled

Versions of packages mosquitto depends on:
ii  adduser3.118
ii  libc6  2.31-13
ii  libcjson1  1.7.14-1
ii  libdlt22.18.6-1
ii  libelogind0 [libsystemd0]  246.9.1-1+debian1
ii  libmosquitto1  2.0.11-1
ii  libssl1.1  1.1.1k-1
ii  libwebsockets164.0.20-2
ii  libwrap0   7.6.q-31
ii  lsb-base   11.1.0

mosquitto recommends no packages.

Versions of packages mosquitto suggests:
ii  apparmor  2.13.6-10

-- Configuration Files:
/etc/init.d/mosquitto changed:
set -e
PIDFILE=/run/mosquitto/mosquitto.pid
DAEMON=/usr/sbin/mosquitto
USER=mosquitto
test -x ${DAEMON} || exit 0
umask 022
. /lib/lsb/init-functions
run_by_init() {
   ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
}
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
 start)
if init_is_upstart; then
exit 1
fi
log_daemon_msg "Starting network daemon:" "mosquitto"
/bin/mkdir -m 740 -p /var/log/mosquitto
/bin/chown mosquitto /var/log/mosquitto
/bin/mkdir -m 740 -p /run/mosquitto
/bin/chown mosquitto /run/mosquitto
if start-stop-daemon --start --quiet --oknodo --background  --user 
${USER} --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 --user ${USER} --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 --user ${USER} 
--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:" "mosquitto"
if start-stop-daemon --stop --quiet --oknodo --retry 30 --user ${USER} 
--pidfile ${PIDFILE}; then
rm -f ${PIDFILE}
fi

/bin/mkdir -m 740 -p /var/log/mosquitto
/bin/chown mosquitto /var/log/mosquitto
/bin/mkdir -m 740 -p /run/mosquitto
/bin/chown mosquitto /run/mosquitto
if start-stop-daemon --start --quiet --oknodo --background --pidfile 
${PIDFILE} --user ${USER} --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 
--pidfile ${PIDFILE} --user ${USER} --exec ${DAEMON} -- -c 
/etc/mosquitto/mosquitto.conf ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
1)