Development: Feedwriter systemd service

(Trystan Lea) #1

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:

sudo service feedwriter stop
sudo update-rc.d feedwriter disable
sudo rm /etc/init.d/feedwriter

Installation of systemd feedwriter service:

sudo ln -s /var/www/emoncms/scripts/services/feedwriter/feedwriter.service /lib/systemd/system
sudo systemctl enable feedwriter.service
sudo systemctl start feedwriter.service

To check the status of feedwriter:

sudo systemctl status feedwriter.service

Edited: for consistency with service-runner installation path.

(Brian Orpin) #2

Whilst I think this is a great idea, can we add in some consistency with other emoncms related services please.

@Greebo created a folder for service files in the scripts folder. with the intention of adding all services here eventually.

There was also a decision to use the /lib/systemd/system folder for the service file and link to it from there.

sudo ln -s /var/www/emoncms/scripts/services/service-runner/service-runner.service /lib/systemd/system

A daemon-reload command is not necessary at this point (as the daemon is not enabled). the enable command does everything necessary.

Have the general installation instructions been updated?

(Trystan Lea) #3

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.

(Trystan Lea) #4

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:

(Paul Reed) #5

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.


(Trystan Lea) #6

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.

(Paul Reed) #7

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.


(Brian Orpin) #8

I have not got it installed as I understand it was predominately to reduce SD card wear.

The only thing of note I can think of is the location of the core. Was emonpi core at /var/www/html/emoncms?

(Trystan Lea) #9

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?

At the moment installation of feedwriter is documented as part of the low-write installation guide here:
If we replace the steps there with:

sudo ln -s /var/www/emoncms/scripts/services/feedwriter/feedwriter.service /lib/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable feedwriter.service
sudo service feedwriter start

and then include the above steps for removal of the old service in the applicable release note, would that be sufficient?

(Brian Orpin) #10

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.

(Trystan Lea) #11

Great thanks @borpin, I’ve amended the above as you recommend. We will update the documentation when this is properly released.

(Greebo) #12

sudo isn’t strictly required to get the status of a service…

Can’t help myself applying the principle of least privilege :slight_smile:

(Brian Orpin) #13


Running DietPi, I tend to do everything as root, so I am never sure when you do and when you don’t!