Argh Systemd - where to start with that…
It’s supposed to be the fix-all solution to everything, and to some extent it is, but we’re at the point where there are some stupid dependancies relating to desktop type services that now rely on systemd, crazy IMO.
As for logging - there are usually two way to specify the log, in the unit file or in the config for the application / process.
Looking at the old init.d init script - you were setting the log file there previously;
NAME=mqtt_input
DESC="Daemon for the emoncms MQTT script"
PIDFILE="/var/run/${NAME}.pid"
LOGFILE="/var/log/${NAME}.log"
DAEMON="/usr/bin/php"
DAEMON_OPTS="/var/www/emoncms/scripts/phpmqtt_input.php"
Since this is the case, we should be doing the same in the systemd unit file, and this is where you run into problems.
Using the init.d - you were actually redirecting the output from the application to STDOUT to a log file, you can replicate that in systemd - kinda…
I have modified my version of the unit file as follows;
# Systemd unit file for mqtt input script
# INSTALL:
# sudo cp /var/www/emoncms/scripts/mqtt_input.service /etc/systemd/system/mqtt_input.service
# RUN AT STARTUP
# sudo systemctl daemon-reload
# sudo systemctl enable mqtt_service
# START / STOP With:
# sudo systemctl start mqtt_input
# sudo systemctl stop mqtt_input
# VIEW STATUS / LOG
# sudo systemctl status mqtt_input -n50
# where -nX is the number of log lines to view
###
#
# All Emoncms code is released under the GNU Affero General Public License.
# See COPYRIGHT.txt and LICENSE.txt.
#
# ---------------------------------------------------------------------
# Emoncms - open source energy visualisation
# Part of the OpenEnergyMonitor project:
# http://openenergymonitor.org
###
[Unit]
Description=Emoncms MQTT Input Script
After=mosquitto.service mysql.service redis.service
[Service]
Type=forking
ExecStart=/bin/sh -c '/usr/bin/php /var/www/emoncms/scripts/phpmqtt_input.php 2>&1 > /var/log/mqtt_input.log &'
# Restart script if stopped
#Restart=always
Restart=on-failure
# Wait 60s before restart
RestartSec=60
[Install]
WantedBy=multi-user.target
One other note - running the update failed on my Pi - the init.d script was removed, but the systemd unit file was not added to /etc/systemd/system - check that you have the file system writable at that point in the script…
Also because you are modifying systemd - make sure you call “systemctl daemon-reload” after adding the file, and then make it active with “systemctl enable mqtt_input”.
I have not checked your update script yet to see where these errors come from yet…