Note that there are some explanatory texts on larger screens.

plurals
  1. PORun python script as daemon at boot time (Ubuntu)
    primarykey
    data
    text
    <p>I've created small web server using werkzeug and I'm able to run it in usual python way with <code>python my_server.py</code>. 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 <code>start my_server</code> I immediately receive <code>kernel: [ 8799.793942] init: my_server main process (7274) terminated with status 1</code></p> <p>my_server.py:</p> <pre><code>... if __name__ == '__main__': from werkzeug.serving import run_simple app = create_app() run_simple('0.0.0.0', 4000, app) </code></pre> <p>upstart configuration file my_server.conf:</p> <pre><code>description "My service" author "Some Dude &lt;blah@foo.com&gt;" start on runlevel [2345] stop on runlevel [016] exec /path/to/my_server.py start on startup </code></pre> <p>Any Ideas how to make it work? Or any other better way to daemonize the script?</p> <p><strong>Update:</strong> I believe the problem lies within <code>my_server.py</code>. It doesn't seem to initiate the webserver (method <code>run_simple()</code>) in the first place. What steps should be taken to make .py file be run by task handler such as upstart?</p> <ul> <li>Place shebang as first line <code>#!/usr/bin/env python</code></li> <li>Allow execution permissions <code>chmod 755</code></li> <li>Start the daemon with superuser rights (to be absolutely sure no permission restrictions prevents it from starting)</li> <li>Make sure all python libraries are there!</li> <li><em>Something else?</em></li> </ul> <p><strong>Solved:</strong> The problem was with missing python dependencies. When starting the script through task manager (e.g. <code>upstart</code> or <code>start-stop-daemon</code>) no errors are thrown. Need to be absolutely sure that pythonpath contains everything you need.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload