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 have a server which exists to run one little Django application. If the server reboots, I want Django to start again:

nohup /opt/myapp/ runserver ...

I'm having trouble finding a simple way to make this run. There are tutorials explaining how to write full-fledged services, runlevels, init.d etc. But there must be a simpler way? A place where I can hack this one extra line onto?

EDIT Mark's answer is perfect, the one-liner works out as:

sudo sed --in-place '/^exit 0/i\cd /opt/appdir\npython runserver .... &' /etc/rc.local
share|improve this question
up vote 5 down vote accepted

You could add it to /etc/rc.local before the line that says exit 0. This way it will run at boot every time.

To add the command using one line:

sudo sed --in-place '/^exit 0/i\cd /opt/appdir\npython runserver .... &' /etc/rc.local
share|improve this answer
Perfect. For anyone who wants to do this programmatically, here's the one-liner I came up with: sudo sed --in-place '/^exit 0/i\cd /opt/appdir\nnohup python runserver ... &' /etc/rc.local – Steve Bennett Feb 6 '13 at 0:26
At shutdown the service will be "killed". Be carefull not doing that for services that needs a "clean" shutdown. – Emmanuel Jul 5 '13 at 16:07

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.