Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to use upstart so that the pydoc webserver for a package I'm developing always runs. If I run it from the command line:

pydoc -p 7464 /some_path/my_python_package

it works fine, and going to localhost:7464/my_python_package displays the documentation. However if I put it in an upstart script, e.g.

start on startup
start on runlevel [2,3,4,5]
stop on runlevel [0,1,6]

script
    pydoc -p 7464 /some_path/my_python_package
end script

then when I open up the browser at localhost:7464/my_python_package I get the following:

no Python documentation found for 'my_python_package' 

Note that localhost:7464 shows all of the standard python packages as normal, so it seems like upstart isn't parsing the path correctly.

I tried using putting export PYTHONPATH='/some_path' in and changing the execution line to pydoc -p 7464 $PYTHONPATH/my_python_package but this didn't work either.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

The syntax you've specified in that job is incorrect:

  • you have multiple 'start on' stanzas.
  • the last 'start on' stanza will be considered, but yours is invalid due to using commas between runlevels (your 'stop on' is invalid for the same reason).

You want something like this:

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

script
    pydoc -p 7464 /some_path/my_python_package
end script

Note that with version 0.9.7 and higher of Upstart (in other words Ubuntu Natty or newer - see https://wiki.ubuntu.com/NattyNarwhal/TechnicalOverviewUpstart), there is a new command called init-checkconf that will check your script for syntax errors. Usage is simple:

$ init-checkconf myjob.conf

Note that you must run init-checkconf as your user (not root).

Also, are you running this as a system job (job file lives in /etc/init/ ?) If so, do you really need the service to run as root? If not, see:

http://upstart.ubuntu.com/cookbook/#run-a-job-as-a-different-user

if this is a do you really need to run that service as the root user?

Finally, I would highly recommend taking a look at the rest of the Upstart Cookbook:

share|improve this answer
add comment

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.