1

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?

UPDATE:-

Something like this -

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

chdir /tekooz
respawn

post-stop script
  sleep 30
end script

setuid deds

exec python testing.py
1

You can use setuid.

6.31 setuid

Added in Upstart v1.4

Syntax:

setuid <username> 

Changes to the user before running the job's process.

(and setgid if you want a group).


You can also add -u <username> to exec.

  • Thanks for suggestion. How would I use this in my example? Any thoughts? – arsenal Apr 7 '14 at 19:41
  • ehm... add it to your script where you change <username> to a username? (and of course before the exec ;) ) – Rinzwind Apr 7 '14 at 19:43
  • You talking about testing.conf file? I just updated the question with an example? Is that looks right to you? – arsenal Apr 7 '14 at 19:44
  • yes that will work. also see the addition from me. – Rinzwind Apr 7 '14 at 19:46
  • Sure. But I still need to start the script by running it like this only - sudo start testing Right? – arsenal Apr 7 '14 at 19:48

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.