title: Start a python script at startup automatically?
body: <p>I followed multiple tutorials available on stackoverflow about starting a python script at startup but none of them works.</p>
  
  <p>I need to activate a virtualenv then start a flask server</p>
  
  <ol>
  <li>I tried
  init.d method</li>
  </ol>
  
  <p>I made an <code>start.sh</code> in <code>/etc/init.d/</code></p>
  
  <pre><code>#!/bin/sh
  ### BEGIN INIT INFO
  # Provides:          skeleton
  # Required-Start:    $remote_fs $syslog
  # Required-Stop:     $remote_fs $syslog
  # Should-Start:      $portmap
  # Should-Stop:       $portmap
  # X-Start-Before:    nis
  # X-Stop-After:      nis
  # Default-Start:     2 3 4 5
  # Default-Stop:      0 1 6
  # X-Interactive:     true
  # Short-Description: Example initscript
  # Description:       This file should be used to construct scripts to be
  #                    placed in /etc/init.d.
  ### END INIT INFO
  
  cd /home/ion/
  source /home/ion/py35/bin/activate
  cd /home/ion/Desktop/flask/
  nohup python main.py &amp;
  echo "Done"
  </code></pre>
  
  <p>Its permissions are chmod at +x</p>
  
  <pre><code>ion@aurora:/etc/init.d$ ll start.sh
  -rwxr-xr-x 1 root root 625 Jun 25 19:10 start.sh*
  </code></pre>
  
  <p>Went to <code>/etc/rc.local</code></p>
  
  <pre><code>#!/bin/sh -e
  #
  # rc.local
  #
  # This script is executed at the end of each multiuser runlevel.
  # Make sure that the script will "exit 0" on success or any other
  # value on error.
  #
  # In order to enable or disable this script just change the execution
  # bits.
  #
  # By default this script does nothing.
  /etc/init.d/start.sh
  
  
  exit 0
  </code></pre>
  
  <p>Didn't work</p>
  
  <ol start="2">
  <li><p>cronjob method</p>
  
  <p>sudo crontab -e</p></li>
  </ol>
  
  <p>and appended </p>
  
  <pre><code>@reboot sh '/etc/init.d/start.sh'
  </code></pre>
  
  <p>Didn't worked either , where am I wrong?</p>
  
  <p>Manual triggered logs</p>
  
  <pre><code>(py35) ion@aurora:~/Desktop/flask$ python main.py 
  WARNING:tensorflow:From /home/ion/Desktop/flask/encoder.py:57: calling l2_normalize (from tensorflow.python.ops.nn_impl) with dim is deprecated and will be removed in a future version.
  Instructions for updating:
  dim is deprecated, use axis instead
  2018-06-25 19:34:05.511943: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
   * Serving Flask app "main" (lazy loading)
   * Environment: production
     WARNING: Do not use the development server in a production environment.
     Use a production WSGI server instead.
   * Debug mode: on
   * Running on http://localhost:5505/ (Press CTRL+C to quit)
   * Restarting with stat
  </code></pre>