Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am facing the following problem. I want to run a python script as a service on Ubuntu 11.10 system (already mentioned in the following link: Python service using Upstart on Ubuntu) I followed the steps mentioned in the above mentioned link, but i got the following error message in syslog:

init: script main process (21826) terminated with status 1
Jun 8 16:59:55 bilbo kernel: [263012.984531] init: script main process ended, respawning
Jun 8 16:59:55 bilbo kernel: [263013.044099] init: script main process (21827) terminated with status 1

The above two lines are getting repeated all the time.

On saying sudo start script, I get the following:

$ sudo start script
script start/running, process 21826

Following is the content of my script.conf placed in /etc/init:

description "Used to start python script as a service"
author "bilbo"
start on runlevel [2]
stop on runlevel [06]
exec python /home/bilbo/scripts/

Please tell me what I am doing wrong? Do I have to change my python code as well?

share|improve this question
up vote 1 down vote accepted is exiting with a non-zero value. By default Upstart considers this an error and so is attempting to restart the service.

As to why is exiting - my guess would be that it is assuming a particular environment. When Upstart spawns a process, it clears the environment, just like cron and at, and then sets a very small number of variables, namely:

To see the entire job environment, add a call to set as shown here:

If your python service needs other variables, you can set them using "env" (the Upstart stanza, not the shell command). See:

share|improve this answer
Thanks jamesodhunt for the input. Your guess was right. In order to run the script, it needed to be run from its current directory only and not from absolute path. So just added chdir directory_path to the conf file and that was it. :D – bugs99 Jun 12 '12 at 6:40

Your Answer


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.