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 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
share|improve this question
add comment

1 Answer

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