-
Notifications
You must be signed in to change notification settings - Fork 517
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
Added systemd based service-runner in python #1025
Added systemd based service-runner in python #1025
Conversation
Added a new python based service-runner and .service file to enable it to run as a service under systemd. This should replace the service-runner.sh bash script included in other repos that require service-runner.
I am with you on that. There have been some other discussions about that and I think it may be a good idea to take that forward. [edit] #794 has been created on this [\edit] https://community.openenergymonitor.org/t/move-data-settings-file-to-a-common-location/6464/5 As part of this PR, any documentation relating to service-runner should be updated, old files deleted and a method to migrate users to the new script created (not much then) 😄. |
|
Not completely familiar with Git, but my feeling is this needs a dev branch to properly test it (remove old stuff etc). |
|
Thanks @greeebs this looks great! I will try and test it this week |
|
Could someone tell me how to pull just the PR down (on top of a fresh master branch) and test it please? |
|
@borpin Paul |
|
@greeebs suddenly occurred to me. Which version of Python or is it compatible with both? |
|
@borpin, I only tested it with v2.7 I don't think I used anything that was incompatible with python3 though. |
|
Thanks @greeebs I've just tested on Raspbian Stretch and it works great 👍 However, I've just tested on two separate Jessie systems and get the error Has anyone else been able to test on Jessie? Maybe the systemd service file needs to be in a different location for Jessie? However, not working on Jessie is not a major issue since Jessie does not work on the new Pi3B+ therefore everyone will be moving to Stretch in the near future. Existing users can continue to use the old bash service runner in the emonPi repo which will continue to work fine. Once this is merged into Emoncms core master I will add note on the emonPi repo to indicate the existence of this new service runner. |
|
@glynhudson, I also had no success on jessie and after extensive reading of the man pages for systemd installed on my jessie systems, came to the conclusion that it was a systemd bug in the version that comes with jessie. It really should work the same way it does on stretch. The way around it on jessie is to link the service file into /etc/systemd/system instead of /lib/systemd/system. |
My reading of the docs, is that the /lib/ location is for packaged installs and /etc/ for local installs or locally modified service files. I think /etc/ is the better location. |
|
@borpin, I don't disgaree with that intention, but I urge you to test the difference between symlinking a file into I think the takeaway for me was that if you are going to put a file into |
|
Ah yes I see. It was raised as a bug but shut down as it is by design to delete the link. Not sure why it should delete the original file - perhaps that is a bug? I think a possible solution is to add the emoncms service files path to $SYSTEMD_UNIT_PATH (if it ends with an empty component (":"), the usual unit load path will be appended to the contents of the variable) as part of the emoncms install process. This might be the best option as it is then persistent and any future service files could be automatically found (though we will need to drop the Another option would be to not create a symlink first but rather use a full path for the enable which creates the links. The disadvantage is that any subsequent enable will also need the path. or However, I cannot see the point of the Final option, as you say, is to copy the service file to the I think the general confusion has occurred from a misunderstanding as to what systemctl actually does when you call |
|
According to the jessie manpage https://manpages.debian.org/jessie/systemd/systemd.unit.5.en.html Which leaves us with either copying the file into Do you know how that behaves if you do a subsequent Maybe we just have two sets of instructions, one for jessie and one for stretch :) Personally, I still think It's just a shame |
|
I've just been reading some more forum posts around the place on systemd and systemctl enable/disable... I'll try and play around a bit more with jessie and see if I can work out why it bugs out when the .service is in /lib/systemd/system... Other packages use that directory so it really should work - maybe there's something missing from the .service file which is no longer required in stretch. |
I think you need to use the full path command to enable again. How about a hybrid solution:
If we decide at a later time to move these types of files off the |
|
Have you tried using a hard symlink ( |
|
@pb66, pretty sure that only works if both source and destination are on the same mount point, which may not always be the case? |
I think that the user base that have emoncms core and the OS on separate mountpoints might be quite small and can be catered for with a footnote, those users with split filesystems will have a little experience of this and be able to cope. IMO it's better to have a simple solution for the masses than trying to accommodate all use cases, the next best alternative is to just set it up for "stretch" users and have special instructions for "jessie" users as it would be daft to be stuck with jessie considerations in the stretch code long after jessie has faded out. Having said that /lib/systemd/system is supposed to be for package managed files and isn't really the place for any emoncms unit files but do I understand your preference for a location where links are not deleted. Given there are fewer users that might fall foul of a multi-mountpoint FS than Jessie users, and the /etc path might be more appropriate to both jessie and stretch it might be the lesser evil, it's certainly the more KISS approach, if it works, this maybe irrelevant if it doesn't do the job in any case. I just thought I would throw another option your way, it's a sad thing that possibly the easiest option is to write an init script as that would most likely work perfectly across both jessie and stretch (and wheezy too) you can see why the uptake of systemd is slow and meets resistance, it's just too complex for it's own good some of the time. |
@greeebs Ah yes - sorry.
@pb66 I'd concur with this sentiment but add that if we can make it work for other future service units, that would be good. Have you looked at using |
This would be my preference. As I mentioned earlier I don't think many jessie users will make the effort to switch to this new service runner. It's now in place for Stretch going forward. We will not be releasing a Jessie image that includes this service runner. |
|
I'm happy for this branch to be merged into Master as soon as your ready. Thanks again for your help 👍 |
|
I have just installed this on a DietPi VM - stretch. I decided to copy the file to Seems to run fine. However, could you add in a comment in the readme that it runs as a user not as system so if not running on a Pi, the user name will need to be changed. Actually looking at the MQTT service file, it does not have a |
I think it would be bad practice to use "User=pi", If you do not want to use "User=root" (probably the default) then perhaps create a specific user for emoncms (and emonhub etc?). I always create a emoncms user for each instance and the original emonhub install guide adds a "emonhub" system user for emonhub. That has been carried forward to the emonpi variant and used in that service file too. https://github.com/openenergymonitor/emonhub/blob/emon-pi/service/emonhub.service#L10
https://github.com/emoncms/emoncms/pull/1025/files#diff-b89a17ccfc5ff5bfcc42d3509fd56a50R15 |
|
As pb66 indicated above, the readme already says this:
Remember that this was a replacement for the emonPi service-runner which ran from the pi user's crontab. I have no idea if it needs to run as pi, I just made it an exact replacement for what was already there :) |
My comment wasn't aimed at you, just my 2 cents worth on using "pi", it is a really bad position across most if not all the OEM projects that the user "pi" and more often the |
Added systemd based service-runner in python (#1025)
|
This has now been merged into master |
I didn't take it that way and I agree with your sentiment entirely... it was more an explanation of why this service unit file has user=pi when @borpin didn't find a user= entry in the MQTT service unit file. A missing user= entry simply implies user=root which may be correct in MQTTs case. |
Added a new python based service-runner and .service file to enable it to run as a service under systemd.
This should replace the service-runner bash script included in other repos that require service-runner.
Previously these changes were in a PR to https://github.com/openenergymonitor/emonpi but part of that discussion suggested moving this function to emoncms. For the previous discussions, see openenergymonitor/emonpi#67 and openenergymonitor/emonpi#66
For this PR, I have created a new
servicesdirectory under scripts with aservice-runnerdirectory underneath containing the actual .service and .py files.I left the documentation file for it in the
scripts/services/directory, but can move it down one level if people think that makes more sense.I have not yet tested it on Debian jessie, but strongly suggest a merge of this waits until that testing has been completed.
I'm also not sure that running a service with a script file that lives under /var/www is entirely appropriate, but can probably be convinced otherwise.
If this gets merged in, we'll need to make sure the other service-runner scripts in the openenergymonitor/emonpi and emoncms/backup (and possibly other places too?) get cleaned up.
@pb66, @glynhudson , @Paul-Reed, @borpin , I have incorporated most of the changes previously discussed but appreciate if you could have a quick look and provide feedback.