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/manage.py 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 manage.py runserver .... &' /etc/rc.local

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 manage.py runserver .... &' /etc/rc.local
  • 1
    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 manage.py 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.