Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
respawn

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?

share|improve this question
    
You can try the method in the Upstart docs here: upstart.ubuntu.com/cookbook/#run-a-job-as-a-different-user –  fooot Apr 17 at 17:04

1 Answer 1

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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