Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In addition to gg.kaspersky method, you could also turn your script into a "service", so that you can start or stop it using:</p> <pre><code>$ sudo service myserver start * Starting system myserver.py Daemon [ OK ] $ sudo service myserver status * /path/to/myserver.py is running $ sudo service myserver stop * Stopping system myserver.py Daemon [ OK ] </code></pre> <p>and define it as a startup service using:</p> <pre><code>$ sudo update-rc.d myserver defaults </code></pre> <p>To do this, you must create this file and save it in /etc/init.d/.</p> <pre><code>#!/bin/sh -e DAEMON="/path/to/myserver.py" DAEMONUSER="myuser" DAEMON_NAME="myserver.py" PATH="/sbin:/bin:/usr/sbin:/usr/bin" test -x $DAEMON || exit 0 . /lib/lsb/init-functions d_start () { log_daemon_msg "Starting system $DAEMON_NAME Daemon" start-stop-daemon --background --name $DAEMON_NAME --start --user $DAEMONUSER --exec $DAEMON log_end_msg $? } d_stop () { log_daemon_msg "Stopping system $DAEMON_NAME Daemon" start-stop-daemon --name $DAEMON_NAME --stop --retry 5 --name $DAEMON_NAME log_end_msg $? } case "$1" in start|stop) d_${1} ;; restart|reload|force-reload) d_stop d_start ;; force-stop) d_stop killall -q $DAEMON_NAME || true sleep 2 killall -q -9 $DAEMON_NAME || true ;; status) status_of_proc "$DAEMON_NAME" "$DAEMON" "system-wide $DAEMON_NAME" &amp;&amp; exit 0 || exit $? ;; *) echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|force-stop|restart|reload|force-reload|status}" exit 1 ;; esac exit 0 </code></pre> <p>In this example, I assume you have a shebang like #!/usr/bin/python at the head of your python file, so that you can execute it directly.</p> <p>Last but not least, do not forget to give execution rights to your python server and to the service script :</p> <pre><code>$ sudo chmod 755 /etc/init.d/myserver $ sudo chmod 755 /path/to/mserver.py </code></pre> <p>Here's the <a href="http://doc.ubuntu-fr.org/tutoriel/comment_transformer_un_programme_en_service" rel="nofollow noreferrer">page</a> where I learned this originally (french).</p> <p>Cheers.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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