I am running my Python script using upstart feature of Ubuntu so that if for whatever reason my Python script dies or gets killed, it can be restarted automatically and everything is working fine -

So I decided to use UPSTART feature of Ubuntu to restart the Python script automatically.

After creating the testing.conf file like this in /etc/init/testing.conf -

start on runlevel [2345]
stop on runlevel [016]

chdir /tekooz

post-stop script
  sleep 30
end script

exec python testing.py

I ran below sudo command to start it and I can see that process running using ps ax and my python script is also running fine. And when I check the pid of the above process, I always see it is running as root. I don't want to run that as root. Instead I want to run that as deds account

deds@bx13:/$ sudo start testing
testing start/running, process 3635
deds@bx13:/$ ps aux | grep testing
root      3635  2.4  0.1 364136 15660 ?        Ssl  12:24   0:00 python testing.py

Is there some other place where I need to put the testing.conf file and then run it with some other command?

I don't want to start my python script by doing sudo as sudo start testing and also I don't want to start as root, I just want to start as deds account. Is there any other way of doing this?


You have two options. If your upstart version (use the initctl --version command) is at least 1.4, then add the following lines to your testing.conf file:

setuid deds
setgid deds

otherwise, change your exec line to:

exec sudo -u deds python testing.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.