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

Service will not start without existing /var/log/mosquitto folder (tmpfs /var/log) #821

Closed
hvanmegen opened this issue May 17, 2018 · 5 comments

Comments

@hvanmegen
Copy link

I run mosquitto on my raspberry pi with /var/log/ as a tmpfs folder; I did this by adding the following line to my /etc/fstab file:

tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0

After a reboot, the mosquitto service won't restart until I manually create the folder /var/log/mosquitto.

Also, it doesn't give any relevant warning message to this issue when I use the systemctl command as stated below, only that is has been started:

[email protected]:/var/log
#> systemctl status mosquitto.service 
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
   Active: active (exited) since Thu 2018-05-17 15:20:26 CEST; 1h 29min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 331 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service

May 17 15:20:26 pi.home systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker...
May 17 15:20:26 pi.home mosquitto[331]: Starting network daemon:: mosquitto.
May 17 15:20:26 pi.home systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
[email protected]:/var/log
#>

Right now, I'm creating the folder after booting and restarting mosquitto, but I think a more elegant solution (in the service script itself) would be better. I'll see if I can come up with something later this week and send in a pull request, but I don't know if I know how to fix this in the most compatible way (with other distributions than just raspbian alone).

@hvanmegen hvanmegen changed the title Mosquitto service will not start without existing /var/log/mosquitto folder (tmpfs /var/log) Service will not start without existing /var/log/mosquitto folder (tmpfs /var/log) May 17, 2018
@toast-uz
Copy link
Contributor

toast-uz commented Aug 1, 2018

I'd like to clarify your intent.

  • It is a bug to be resolved?
  • It is not a bug but you want submit the improvement.
  • You are just asking the workaround more elegantly.

@toast-uz toast-uz added the Status: Blocked Another issue needs to be resolved first label Aug 1, 2018
@hvanmegen
Copy link
Author

A bugfix that would create the logging directory if it doesn't exist post-install (or at least show a decent error message in the logs somewhere without crashing) would be nice, as I've already found out that my fluency with the used programming language is far from being useful.

@toast-uz
Copy link
Contributor

toast-uz commented Aug 2, 2018

I don't think mosquitto should auto-create the logging directory. I tried another famous network software, and confirmed it behaved as same as mosquitto.

Regarding error message, you can look the message "Unable to open log file /nodir/mosquitto.log for writing." by running mosquitto on the shell.

@toast-uz toast-uz added not a bug and removed Status: Blocked Another issue needs to be resolved first labels Aug 2, 2018
@Nephiel
Copy link

Nephiel commented May 1, 2019

FWIW, a workaround is to add the lines marked with +:

  • For sysv-init, in /etc/init.d/mosquitto:
[...]
  set -e

  PIDFILE=/var/run/mosquitto.pid
  DAEMON=/usr/sbin/mosquitto
+ LOGDIR=/var/log/mosquitto

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

  test -x ${DAEMON} || exit 0
+ test -d ${LOGDIR} || /bin/mkdir -p ${LOGDIR} && /bin/chown mosquitto:adm ${LOGDIR} && /bin/chmod 740 ${LOGDIR}

  umask 022
[...]
  • For systemd, in /lib/sytemd/system/mosquitto.service and/or /etc/systemd/system/multi-user.target.wants/mosquitto.service (assuming user mosquittoand group adm for the log file):
[...]
  [Service]
  Type=notify
  NotifyAccess=main
  ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
  ExecReload=/bin/kill -HUP $MAINPID
  Restart=on-failure
+ User=mosquitto
+ PermissionsStartOnly=true
+ ExecStartPre=-/bin/mkdir -p /var/log/mosquitto
+ ExecStartPre=-/bin/chown mosquitto:adm /var/log/mosquitto
+ ExecStartPre=-/bin/chmod 740 /var/log/mosquitto

  [Install]
  WantedBy=multi-user.target
[...]

@mondo2020
Copy link

Thanks a lot! Solved the problem. But, I think, this is a bug and should be fixed in the standard installation. Otherwise, Mosquitto does not start after reboot. I've installed a fresh oh3 with mosquitto and have had exactly the described issue.

@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