Why does net/mosquitto not save the pid on system restart?

I’m encountering this issue with net/mosquitto on FreeBSD.

[empty dan ~] % grep mosquitto /etc/rc.conf
mosquitto_enable="YES"
mosquitto_user="mosquitto"
mosquitto_pidfile="/var/run/mosquitto/mosquitto.pid"
[empty dan ~] % sudo service mosquitto status
mosquitto is not running.
[empty dan ~] % cat /var/run/mosquitto/mosquitto.pid
cat: /var/run/mosquitto/mosquitto.pid: No such file or directory
[empty dan ~] % ps auwwx | grep mosq
mosquitto  8964  0.0  0.0 39944 20464  -  SsJ  18:08   0:00.69 /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf -d
dan       92313  0.0  0.0 12840  2328  1  S+J  19:41   0:00.00 grep mosq
[empty dan ~] % 

Clearly, mosquitto is running, but not storing the pid.

If I restart, it silently fails to start, the old process is still there:

[empty dan ~] % sudo service mosquitto restart
mosquitto not running? (check /var/run/mosquitto/mosquitto.pid).
Starting mosquitto.
[empty dan ~] % sudo service mosquitto status
mosquitto is not running.
[empty dan ~] % cat /var/run/mosquitto/mosquitto.pid                                                                                                                     19:44:01
cat: /var/run/mosquitto/mosquitto.pid: No such file or directory
[empty dan ~] % ps auwwx | grep mosq
mosquitto  8964  0.0  0.0 39944 20464  -  SsJ  18:08   0:00.71 /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf -d
dan       93161  0.0  0.0 12840  2328  1  S+J  19:44   0:00.00 grep mosq

If I manually kill and start, all is good:

[empty dan ~] % sudo kill -TERM 8964
[empty dan ~] % ps auwwx | grep mosq
dan    94952  0.0  0.0 12840 2328  1  S+J  19:48   0:00.00 grep mosq
[empty dan ~] % sudo service mosquitto start
Starting mosquitto.
[empty dan ~] % cat /var/run/mosquitto/mosquitto.pid
94964%                                                                                                                                                                            [empty dan ~] % ps auwwx | grep mosq
mosquitto 94964  0.0  0.0 39944 21192  -  SsJ  19:48   0:00.01 /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf -d
dan       94968  0.0  0.0 12840  2328  1  S+J  19:48   0:00.00 grep mosq
[empty dan ~] % 

Why?

I suspect rc.d.

Let’s look at some of the output of this command:

[empty dan ~] % rcorder /etc/rc.d/* /usr/local/etc/rc.d/*
/etc/rc.d/sysctl
/etc/rc.d/natd
/etc/rc.d/dhclient
/etc/rc.d/dumpon
...
/etc/rc.d/utx
/usr/local/etc/rc.d/mosquitto
/usr/local/etc/rc.d/mosquitto.origin
/usr/local/etc/rc.d/openntpd~
/usr/local/etc/rc.d/git_daemon
/etc/rc.d/sdpd
...
/etc/rc.d/bgfsck
/etc/rc.d/securelevel
[empty dan ~] %

Umm, what’s that extra file in there? I think it’s a backup. Let’s compare:

[empty dan ~] % diff /usr/local/etc/rc.d/mosquitto.origin /usr/local/etc/rc.d/mosquitto                                                                                  19:52:39
33,43c33,35
< extra_commands="reload"
< stop_postcmd=stop_postcmd
< stop_postcmd()
< {
<   rm -f $pidfile
< }
< start_precmd=start_precmd
< start_precmd()
< {
< 	install -o ${mosquitto_user} -m 644 /dev/null ${pidfile}
< }
---
> extra_commands=reload
> stop_postcmd="rm -f $pidfile"
> start_precmd="install -o ${mosquitto_user} -m 644 /dev/null ${pidfile}"

Let’s move that away and test by restarting this jail.

[empty dan ~] % sudo mv /usr/local/etc/rc.d/mosquitto.origin ~/tmp
[empty dan ~] % 

After the restart:

[air01 dan ~] % ssh empty
Last login: Mon Jan 16 19:49:56 2023 from air01.example.org
[empty dan ~] % cat /var/run/mosquitto/mosquitto.pid
97421%                                                                                                                                                                            
[empty dan ~] % ps auwwx | grep mosq
mosquitto 97421  0.0  0.0 39944 21192  -  SsJ  19:53   0:00.05 /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf -d
dan       99421  0.0  0.0 12840  2328  1  S+J  19:58   0:00.00 grep mosq

That’s correct. OK, phew, that’s better. It’s not what I thought it would be though. I thought it might be something missing from REQUIRE in the rc.d script.

I suspect the removed script was overwriting what the first script created.

Thanks for coming to my TED talk.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top