I want to run a python script at boot as a particular user.
The script is a server (listens on a socket, serves requests, etc) and should be run in the background, with any output preferably piped to a log file.
My current approach is to add an entry at the end of rc.local like this:
su -l usr -c 'script.py arg1 arg2 &> logfile.log &'
The problem: In the script i have several print statements in the script. They never show up in the log file. I've tried
su -l usr -c 'script.py arg1 arg2 &> logfile.log &'
su -l usr -c 'script.py arg arg &> logfile.log &' &> secondLogfile.log &
su -l usr -c 'script.py arg arg &> logfile.log &'
su usr -c 'script.py arg arg &> logfile.log &'
I have the feeling i'm missing something basic. Maybe i'm going about it in totally the wrong way.
System is Fedora 15, script is Python3 and runs fine from the command line as the user. User has write permissions to the folder i want the output redirected to. (I ruled it out by making the folder 777).
I tried having the python script run as a Systemd service, but i was having issues with my script being able to grab a socket to listen on. (throwing an OS error about socket in use if i enabled the systemd service at boot, whereas if i ran systemctl start script.service after boot things worked fine).
How can i launch a python script as a user at boot that grabs a socket?