Although the problem exposed here seems very similar, none of the solutions provided work. Context :
- Raspberry Pi Zero W, Raspbian Lite (2020-08-20)
- I want to register a python3 script as a service, to run in background
I wanted to make it go with systemd, which worked with following configuration :
application.service lies in
[Unit] Description=application After=multi-user.target [Service] User=custom_user Type=idle TimeoutSec=0 PIDFile=/run/application.pid ExecStart=/usr/bin/python3 -u /path/to/application.py >> /path/to/log.log 2>&1 KillMode=control-group Environment="PYTHONUNBUFFERED=1" Restart=always RestartSec=3s [Install] WantedBy=multi-user.target
This service correctly loads at startup, on expected segments (related to
WantedBy sections). But it won't log anything in log file I provided. You notice
Environment entry to force
PYTHONUNBUFFERED and same thing with the
-u argument passed on Python executable call. This has no effect at all.
If I launch exactly the same exec line on a CLI, the script runs AND logs. Through the service definition, no log at all.
- If i check
journalctloutput, I find my log lines
log2ramare set up on the log file/directory
I ended up with adding my command line in
/etc/rc.local followed by an ampersand. This is not a go according to me as I would like to register this service in the best way possible regarding the system it's running on.
Thanks for your replies and enlightments.