2

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 script as linux service/daemon)

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/webserver.py
respawn

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

6
  • Is python process in the cron environment path? Try with absolute path /usr/local/bin/python or where ever the python you're using is. Commented Jun 8, 2012 at 12:01
  • @TeemuIkonen: It's not being run by cron. It's being run with init. ... there is nothing in init's path... Commented Jun 8, 2012 at 12:02
  • @Teemu Ikonen - tried with exec /usr/bin/python filename, but still the same Commented Jun 8, 2012 at 12:10
  • See debugging help here upstart.ubuntu.com/cookbook/#exec section 20.5. Personally I've dumped linux init mess and switched to supervisord Commented Jun 8, 2012 at 13:06
  • Can you post your Python script contents ? Commented Jun 8, 2012 at 13:41

1 Answer 1

0

The init script seems fine, but the script itself fails to run for some reason. You need to add some logging or at least redirect it's standard and error output to a log file to see what it might be.

Edit: Teemu Ikonen noticed in comment that you are running python without full path and that it might not be in $PATH in given context. I would extend it: It definitely isn't in your $PATH. You have to use full path to the executable in init scripts, always.

Sign up to request clarification or add additional context in comments.

2 Comments

redirecting error output file gives nothing. tried the following - sudo start script 2> error.txt
ok, i added /usr/bin/python instead of python in :- exec python filename but still same problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.