I've created small web server using werkzeug and I'm able to run it in usual python way with python my_server.py
. Pages load, everything works fine. Now I want to start it when my pc boots. What's the easiest way to do that? I've been struggling with upstart but it doesn't seem to "live in a background" cuz after I execute start my_server
I immediately receive kernel: [ 8799.793942] init: my_server main process (7274) terminated with status 1
my_server.py:
...
if __name__ == '__main__':
from werkzeug.serving import run_simple
app = create_app()
run_simple('0.0.0.0', 4000, app)
upstart configuration file my_server.conf:
description "My service"
author "Some Dude <[email protected]>"
start on runlevel [2345]
stop on runlevel [016]
exec /path/to/my_server.py
start on startup
Any Ideas how to make it work? Or any other better way to daemonize the script?
Update:
I believe the problem lies within my_server.py
. It doesn't seem to initiate the webserver (method run_simple()
) in the first place. What steps should be taken to make .py file be run by task handler such as upstart?
- Place shebang as first line
#!/usr/bin/env python
- Allow execution permissions
chmod 755
- Start the daemon with superuser rights (to be absolutely sure no permission restrictions prevents it from starting)
- Make sure all python libraries are there!
- Something else?
Solved:
The problem was with missing python dependencies. When starting the script through task manager (e.g. upstart
or start-stop-daemon
) no errors are thrown. Need to be absolutely sure that pythonpath contains everything you need.