I have a web-server that is based on flask+tornado combination. It works inside of a virtual environment (set up with python virtualenv).

I want the server to launch automatically on start up, from a regular user. What i have done to achieve this:

1) i have written a startup script with following contents:

cd /home/ubuntu/myserver
# enter virtualenv
source venv/bin/activate
# launch
python app.py > serverlog.log 2&>1 &

2) i have set up a crontab with crontab -e as:

@reboot /home/ubuntu/start_service.sh

When i execute startup script from the command line, everything is correctly launched. But after reboot in serverlog.log i see a stacktrace that tells of failure to bind to port 5000. what can i do to fix it?


Crontab is not smart enough to keep your server up. When it goes down, it has to wait till crontab runs again; your clients will get a 404 error from your faulty server.

I advise you to use something like Supervisor. You can install it using easy_install like

   easy_install supervisor

You will need to deal with Supervisord and Supervisorctl. The first is a demon process manager that will run and make sure the PID from your

python app.py > serverlog.log 2&>1 &

keep running no matter what. You will be able to do such thing by creating a so called program on the supervisord.conf like

command=python app.py > serverlog.log 2&>1 &

Supervisorctl is how you control [ start | stop | restart ] the program you have just created on the supervisord configuration file. This might help you.

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.