Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mosquitto Service #176

Closed
Testato opened this issue May 28, 2016 · 7 comments
Closed

Mosquitto Service #176

Testato opened this issue May 28, 2016 · 7 comments

Comments

@Testato
Copy link

Testato commented May 28, 2016

The mosquitto service autostart at boot, but do not autostart on crash.

You can test it by
sudo pkill mosquitto

The service do not auto restart itself.

P.S. I'm on Ubuntu16, so SystemD

@ralight
Copy link
Contributor

ralight commented May 30, 2016

I'm not sure what the change to systemd has done for packages that don't directly support it, I'll take a look.

@Testato
Copy link
Author

Testato commented May 31, 2016

SystemD do not support etc/inittab for respawn.
So autostart after boot continue to wirk, but you loose autostart on crash.

I solved by deactivate your service and creating a new systemD .service

If you want i can post it.

Is it possibile test during mosquitto installation if is present systemD or other init system ? So if you found systemD you install the .service for systemD

@ralight
Copy link
Contributor

ralight commented May 31, 2016

I presume you're referring to the Ubuntu packages here by the way, rather than self compiled.

Ubuntu used upstart prior to systemd and the upstart script specified that mosquitto should be restarted. The system-v init script does not do this. I suspect what is happening is that systemd is using the system-v script to control mosquitto, but without support for restarting.

There is already a service file in service/systemd, the package just needs updating. Bookmark for this is https://wiki.debian.org/Teams/pkg-systemd/Packaging

@mikini
Copy link

mikini commented May 4, 2018

We have had similar experiences of mosquitto shutting down and not being restarted in our setup of Ubuntu 16.04 servers (mostly due to segfault and gp fault in libwebsockets).
Adding to the confusion is how systemd reports the state of a legacy service in this situation with a green icon and using the word active ("Active: active (exited)"), maybe this is part of the frustration expressed in #509, #597? I have attempted to discuss the latter issue with systemd maintainers at systemd/systemd#6767.

I do see systemd service descriptions and code changes to the daemon in the service/systemd dir of the develop branch in what seems to involve signalling to systemd right before the main loop is entered. Eclipse bug #471053 suggest this is old unreleased work, but I also see it mentioned in the 1.5 changelog entry (which has a date on mosquitto.org but not on develop branch, is a tag/merge/push missing?).
I've tried using the mosquitto.service.simple from develop with the current ppa for xenial/16.04 (1.4.15-0mosquitto1~xenial1) which doesn't seem to handle restarting properly when the broker is being pulled.

Our systems are using supervisord (Ubuntu 16.04/xenial package) for control of other services so I'm experimenting with a supervisord configuration for mosquitto. The simple case, not thoroughly tested, like the below in /etc/supervisor/conf.d/mosquitto.conf seems to do the expected when mosquitto is killed (remove /etc/init{.d,}/mosquitto{,.conf} to avoid conflict):

[program:mosquitto]
command                 = /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
autostart               = true
autorestart             = true
startretries            = 50
startsecs               = 10
user                    = root
stdout_logfile          = /var/log/supervisor/mosquitto.log
stdout_logfile_maxbytes = 1MB
stderr_logfile          = /var/log/supervisor/mosquitto-error.log
stderr_logfile_maxbytes = 1MB

@mikini
Copy link

mikini commented May 7, 2018

I've tried using the mosquitto.service.simple from develop with the current ppa for xenial/16.04 (1.4.15-0mosquitto1~xenial1) which doesn't seem to handle restarting properly when the broker is being pulled.

I saw the same after compiling 1.5 and I've now learned that systemd doesn't restart a service on sigterm. Pulling it hard with sigkill however does. The broker notification to systemd is only significant for other systemd units that is depending on mosquitto and notifies that mosquitto is completely up and running.

@dustin
Copy link

dustin commented Sep 16, 2018

For anyone interested, after my outage from #965, I did the following in /lib/systemd/system/mosquitto.service:

[Unit]
Description=Mosquitto MQTT Broker daemon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
After=network.target
Requires=network.target

[Service] 
StartLimitInterval=0 
PIDFile=/var/run/mosquitto.pid 
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=always
RestartSec=2

[Install] 
WantedBy=multi-user.target

@ralight
Copy link
Contributor

ralight commented Dec 22, 2020

I'm quite certain that this has been fixed for a while for Debian and Ubuntu systems, so I'm closing this.

@ralight ralight closed this as completed Dec 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants