Following from @borpin’s maintenance mode thread, I’ve added a systemd service script for feedwriter (same as method used for phpmqtt_input), which works a treat for automatic restarting of feedwriter. This will make its way into an emonpi/emonbase update soon.
Removal of existing /etc/init.d feedwriter service:
Yes happy with that. No instructions updated yet, just initial creation of systemd service script, with the intention of clarifying installation etc with @glyn.hudson next week.
I’ve moved the service file to services, but not the feedwriter.php script for now as that would likely be a breaking change. I’ve also updated the service file to mirror @Greebo’s service file as close as applicable:
Are there any manual steps required to change an existing installation to use the changes made to the feedwriter & service-runner? Not everyone will be using a pre-configured emonpi image file.
If so, could the readme’s please be edited include the steps necessary.
Perhaps I should have noted that the above post was a development thread rather than a launch of a finished item. I will amend the title. Would appreciate help with readme’s for non pre-configured emonpi installs. Will be discussing this with Glyn this coming week as to emonpi steps.
That is surely a responsibility of whoever introduced the changes, as they are most aware of the implications?
I’m not aware myself, so not really able to help in this instance.
Are the steps I outlined above (with your recommended amendment @borpin) sufficient for self-build installs? It worked fine for me, disabling the existing script and installing the new service?
Strictly (and for consistency), the command to start should be
sudo systemctl start feedwriter.service
and I would add in a
sudo systemctl status feedwriter.service
and a note on what the user should see (i.e. running) with this command.
I will say it yet again, the daemon-reload is not required and does nothing as, until you use the enable command, systemctl does not know the service exists (i.e. the enable loads it into the list of units to start; daemon-reload tells the system to check all the enabled units are loaded correctly by reloading them).
I cannot comment on what steps might be needed to switch from the cron based to systemd based running mechanism as I have never installed it.
I suspect I need a setting in settings.php but I deliberately did not do that to test how this works
Note The docs state the service is run by the user=pi and non Rasbian users will need to change the user in the service file. This is not correct as the service file does not (now) have a user entry.
So initial issues:
There are no errors in the EmonCMS error log.
There are no errors in the SystemCtl status to help me.
On checking the log using journalctl I could see that the error messages were being created (not sure why the status command was not showing them).
Started Emoncms feedwriter script.
Error: setting must be true: feed_settings['redisbuffer']['enabled']
feedwriter.service: Service hold-off time over, scheduling restart.
Stopped Emoncms feedwriter script.
I checked the systemd docs and I think the restart command should be changed from always to on-failure.
On doing that I get the following on doing a status command which makes much more sense to the user.
● feedwriter.service - Emoncms feedwriter script
Loaded: loaded (/var/www/emoncms/scripts/services/feedwriter/feedwriter.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2018-12-27 11:02:27 GMT; 583ms ago
Docs: https://github.com/emoncms/emoncms
Process: 25040 ExecStart=/usr/bin/php /var/www/emoncms/scripts/feedwriter.php (code=exited, status=0/SUCCESS)
Main PID: 25040 (code=exited, status=0/SUCCESS)
Dec 27 11:02:27 DietPi-EmoncmsVM systemd[1]: feedwriter.service: Service hold-off time over, scheduling restart.
Dec 27 11:02:27 DietPi-EmoncmsVM systemd[1]: Stopped Emoncms feedwriter script.
Dec 27 11:02:27 DietPi-EmoncmsVM systemd[1]: Started Emoncms feedwriter script.
Dec 27 11:02:27 DietPi-EmoncmsVM feedwriter[25040]: Error: setting must be true: feed_settings['redisbuffer']['enabled']
The old system-runner was triggered from crontab (for the “pi” user on the EmonSD image), so editing the crontab to remove it is the simplest way to remove it before installing the systemd/redis based one. The emonsd update script used to reinstate the crontab entry though, so make sure that has also been updated first before you remove the crontab entry otherwise it will get put back next time you run the update script.
Once it is removed from crontab, kill the running process using sudo killall service-runner
I’m not familiar enough with the feedwriter change to provide details on “upgrading” it.
Thanks. I realise that, I just am not familiar with cron so I have no idea where to start to remove it and there are now no installation instructions I can back track as to how it was setup in the first place
Ah… The easiest way to do that is crontab -e which “edits your crontab”. First you need to work out what user it is running as because you need to be that user to edit its crontab… If it is ‘pi’ for example, make sure you are logged on as ‘pi’, then crontab -e will fire up the defined editor for crontab (nano by default on a pi), either delete the line containing service-runner or prefix it with a # to comment it out, then save the “file”.
Use ps -ef | grep service-runner to work out what user it is running as.
You can check it using crontab -l (list your crontab)