Systemd services aren't executed by a shell, and although man systemd.service
notes the syntax for the various Exec___
directives is "inspired by shell syntax", it also notes:
redirection using "<", "<<", ">", and ">>", pipes using "|",
running programs in the background using "&", and other elements of shell syntax are not supported.
So you can see there is a problem there. I don't know if that will necessarily mean the service wasn't run, but it will mean it won't log to where you want it to log (see the StandardOutput
and StandardError
options in man systemd.exec
for that).
Of course, this implies it can still be run manually:
If a type sudo systemctl restart gateway.service ,the program runs normally
So likely the spurious redirection is just being ignored, and not the main problem.
This just seems wrong:
[Unit]
After= multi-user.target
[Install]
WantedBy = multi-user.target
If you have reason to believe this should work, fair enough. If it is just something you decided upon, I would use something other than multi-user.target
in After
, e.g., local-fs.target
or networking.target
(check to make sure those are in use with systemctl status ____
first).
By the way, you do not mention doing this:
sudo systemctl enable [my.service]
Which you must do if you want it run at boot. You can also check after boot to see what happened:
systemctl status [my.service]
There should be some clue there. Also, every time you change the service file you will need to use sudo systemctl daemon-reload
.
Finally, you may want to change the type of the service to either simple
or oneshot
, depending on whether this is a persistent, long-running program (simple
) or something that just configures something quickly then exits (oneshot
).
sudo systemctl enable gateway.service
?sudo journalctl -xe -u gateway.service
directly after boot before you've started the application manually?man systemd.service
, specifically the paragraph which begins "This syntax is...", includes the phrase "Specifically, redirection using..." and ends "...are not supported.".ExecStart=/home/pi/WebSite/env/bin/python gateway.py
and update the systemd files withsudo systemctl daemon-reload