Continuing from here: Force rc.local to wait for network, I have been working on implementing my own systemd service to run a custom python script. Everything seems to be working, except that I cannot seem to get the script stdout to redirect to a log file.
I recognize this has nothing to do with OSMC, just wondering if someone knows the answer offhand… what changes would I make to get stdout to log into a file somewhere?
Here are the contents of the new ttcbutler.service
file I have defined in /etc/systemd/system
:
[Unit]
Description=ttcbutler Daemon
After=network-online.target
Wants=network-online.target
[Service]
User=osmc
Group=osmc
WorkingDirectory=/home/pi
Type=simple
ExecStart=/usr/bin/python -u /home/pi/ttc_sms_butler.py 1> /tmp/ttc_sms.log 2>&1 &
[Install]
WantedBy=multi-user.target
The service is running correctly, as confirmed by sudo systemctl status ttcbutler.service -l
, except that I do not get anything populated into ‘/tmp/ttc_sms.log’
This tutorial indicates I should just be able to use:
ExecStart=/usr/bin/python /home/pi/myscript.py > /home/pi/myscript.log 2>&1
As shown in the version of the .service file I posted above, I also tried with the -u
switch that I used to have in rc.local
, but no luck.
Finally, I tried enclosing the whole ExecStart line in quotes (’ and "), based on this post. Again, no joy:
ExecStart=/usr/bin/python "/home/pi/ttc_sms_butler.py > /tmp/ttc_sms.log 2>&1"
Is there anything else I should try?