Getting systemd working

Hello

Reading this thread How to run script at boot? [SOLVED] I want to do something similar to auto start my energy monitor (measureit) Having someissues though, wonder if anyone can help…
logs below…

thanks

root@osmc:/etc/systemd/system# systemctl status measureit.service -l

  • measureit.service - MeasureIT pvoutput uploader
    Loaded: loaded (/etc/systemd/system/measureit.service; enabled)
    Active: inactive (dead)

Jan 29 07:50:14 osmc systemd[1]: [/etc/systemd/system/measureit.service:2] Unknown section ‘unit’. Ignoring.
Jan 29 07:50:14 osmc systemd[1]: [/etc/systemd/system/measureit.service:12] Executable path is not absolute, ignoring: usr/bin/python /var/www/html/measureit/measureit_system_files/python/data-input.py
Jan 29 07:50:14 osmc systemd[1]: measureit.service lacks ExecStart setting. Refusing.
Jan 29 07:56:51 osmc systemd[1]: [/etc/systemd/system/measureit.service:3] Failed to add dependency on mediacenter, ignoring: Invalid argument
Jan 29 07:56:51 osmc systemd[1]: [/etc/systemd/system/measureit.service:9] Executable path is not absolute, ignoring: usr/bin/python /var/www/html/measureit/measureit_system_files/python/data-input.py
Jan 29 07:56:51 osmc systemd[1]: measureit.service lacks ExecStart setting. Refusing.
Jan 29 08:00:58 osmc systemd[1]: [/etc/systemd/system/measureit.service:3] Failed to add dependency on mediacenter, ignoring: Invalid argument
Jan 29 08:14:56 osmc systemd[1]: [/etc/systemd/system/measureit.service:3] Failed to add dependency on mediacenter, ignoring: Invalid argument
Jan 29 08:18:37 osmc systemd[1]: [/etc/systemd/system/measureit.service:3] Failed to add dependency on mediacenter, ignoring: Invalid argument
Jan 29 08:22:21 osmc systemd[1]: [/etc/systemd/system/measureit.service:3] Failed to add dependency on mediacenter, ignoring: Invalid argument
root@osmc:/etc/systemd/system# vi measureit.service
[Unit]
Description=MeasureIT pvoutput uploader
After=mediacenter

[Service]
User=osmc
Group=osmc
Type=simple
ExecStart=/usr/bin/python /var/www/html/measureit/measureit_system_files/python/
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20
KillMode=process
Restart=on-failure
RestartSec=60
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

Your unit file looks visually ok, except I would change that after line to After=mediacenter.service - it’s best to be explicit about the unit type you are referring to.

However your errors suggest that the file is not being read properly - my first guess would be that you have windows line endings - did you originally write the file in vi or did you do it on a Windows PC ?

thanks for the reply.
Yea I originally copied the sshd.service and edited in vi. I did chmodd 777 it to appear like the sshd service.
When checking in winscp… the file seems a fair bit bigger than the others (all be it a few bytes)

Just tried copying sshd again to a fresh file and ensured I didnt get any dodgy line breaks etc and got the same result…

Anyone? Getting fed up of having to kill/respawn measureit every single day in order for the solar to be measured!
Any suggestions appreciated muchly!
ta v much.

Do you get more info with “sudo”? sudo systemctl status measureit.service -l

And are you correctly specifying the file to run?
ExecStart=/usr/bin/python /var/www/html/measureit/measureit_system_files/python/

should it be:
ExecStart=/usr/bin/python /var/www/html/measureit/measureit_system_files/python/data-input.py

what if you try simplifying by removing the modifiers:

ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20
KillMode=process
Restart=on-failure
RestartSec=60
StartLimitInterval=60s

thanks for the reply Berto
Na I was already running it under sudo bash shell.

yea dont know why thats missed out from the original text… it is already ExecStart=/usr/bin/python /var/www/html/measureit/measureit_system_files/python/data-input.py

yes will try simplifying thats worth trying…

thanks.

Good luck. As already mentioned, the errors suggest a filepath problem. And you’re sure your .py is at the specified location?

If it helps, this thread gives details of a service I setup recently: Redirecting output from a systemd service (python script) to a log file?

Yay got it working… seems measureit was trying to write to /tmp/measureit.log so chmod 777 that and it started.
Now onto my next issue to get a cron job going to restart this 12:01 am every night as it seems theres a bug where my solar stops recording to pvoutput nightly… oh the joy!
thanks!

Glad you got it working!

Out of curiosity, could you post how your script was setup to get logging into a “.log” file? From the link I posted above, I was actually trying to do this but it did not work. I just use the journalctl now, but would be interested to know how it could be made to work to a log file.

Does your .py script specify the log file directly? In other words, you are not using simple print statements?

Didnt write the script myself… got it from here if you want a gander: measureit/measureit_system_files/python at master · lalelunet/measureit · GitHub

cheers

had some dramas getting this to start on boot…It wasnt waiting for mysql to start. Even though the service fails coz it cant connect to mysql, systemd thinks all is fine n dandy so probably something wrong with how it returns errors too…

Tried putting mysql in after=, wants= but still no good. Tried adding a timeout too… Only thing that finally got it going was by using type=idle as below which will wait for everything to startup first…

[Unit]
Description=measureIT
After=meadiacenter.service,mysql.service,apache2.service

[Service]
User=osmc
Group=osmc
Type=idle
WorkingDirectory=/var/www/html/measureit/measureit_system_files/python/
ExecStart=/usr/bin/python /var/www/html/measureit/measureit_system_files/python/data-input.py
TimeoutStopSec=20
Restart=on-failure
RestartSec=60
StartLimitInterval=60

[Install]
WantedBy=multi-user.target

Commas in your After= line are not valid, you should separate multiple entries with spaces.

This will probably cause your entire line to be ignored and hence cause your original problem.

1 Like