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?

Community
  • 1
  • 1
bugs99
  • 31
  • 1
  • 4
  • 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. – Teemu Ikonen Jun 08 '12 at 12:01
  • @TeemuIkonen: It's not being run by cron. It's being run with init. ... there is nothing in init's path... – Jan Hudec Jun 08 '12 at 12:02
  • @Teemu Ikonen - tried with exec /usr/bin/python filename, but still the same – bugs99 Jun 08 '12 at 12:10
  • See debugging help here http://upstart.ubuntu.com/cookbook/#exec section 20.5. Personally I've dumped linux init mess and switched to supervisord – Teemu Ikonen Jun 08 '12 at 13:06
  • Can you post your Python script contents ? – Amr Jun 08 '12 at 13:41
  • just add chdir /home/bilbo/scripts above exec statement and change exec statement to - exec python webserver.py – bugs99 Jun 12 '12 at 06:45

1 Answers1

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.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • redirecting error output file gives nothing. tried the following - sudo start script 2> error.txt – bugs99 Jun 08 '12 at 12:14
  • ok, i added /usr/bin/python instead of python in :- exec python filename but still same problem – bugs99 Jun 08 '12 at 12:41