title: Executing multiple Python scripts in a particular order using systemd
body: <p>I am running Raspbian GNU Linux (9) Stretch, on my Raspberry Pi 3.</p>
  
  <h2>Project Overview</h2>
  
  <ol>
  <li>Python script which makes use of 2 inputs to the Pi. Calculations are performed based on these inputs, and values are stored in a database.</li>
  <li>A separate Django website which reads values from this database and updates the content of the web page.</li>
  </ol>
  
  <p><strong>Django Server</strong> run using: <code>/home/pi/mysite/manage.py runserver 127.0.0.1:8000</code></p>
  
  <p><strong>Python Script</strong> located at: <code>/home/pi/Desktop/myscript.py</code></p>
  
  <p>On startup I would like to first make sure that my Django server is up and running and then start my python script. </p>
  
  <h2>What I have done so far</h2>
  
  <p>Initially I started by trying to get the python script to run on startup. To do this I am using a simple <code>systemd</code> service as follows.</p>
  
  <pre><code>[Unit]
  Description=My script
  
  [Service]
  ExecStart=/usr/bin/python3 /home/pi/Desktop/myscript.py
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>This runs without error and initiates the python script on startup.</p>
  
  <p>However, I cannot get my Django server up and running inside the same systemd service since only one <code>ExecStart</code> is allowed. I need both to be run in parallel, but the Django up to be started first.</p>
  
  <p>I think I am looking for something like <a href="https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Wants=" rel="nofollow noreferrer">Wants</a>.</p>
  
  <p>I came across the following <a href="https://stackoverflow.com/questions/48195340/systemd-with-multiple-execstart">question</a>, but I have not managed to implement a working solution. However most of the information is  relevant.</p>
  
  <blockquote>
    <p>if Type=simple in your unit file, you can only specify one <code>ExecStart</code>, but you can add as many <code>ExecStartPre</code>,<code>ExecStartPost</code>, but none of this is suited for long running commands, because they are executed serially and everything one start is killed before starting the next one. If <code>Type=oneshot</code> you can specify multiple <code>ExecStart</code>, they run serially not in parallel.</p>
  </blockquote>
  
  <p>I tried creating another unit as follows:</p>
  
  <pre><code>sudo systemctl edit --force mysite.service
  
  
  [Unit]
  Description=my site
  
  [Service]
  ExecStart=/usr/bin/python /home/pi/mysite/manage.py runserver 127.0.0.1:8000
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>This works on it's own.</p>
  
  <p>However <strong>I need both to be run in parallel, but the Django up to be started first.</strong></p>
  
  <p>That's why I edited <code>myscript.service</code>as follows:</p>
  
  <pre><code>[Unit]
  Description=My script
  
  [Service]
  ExecStart=/usr/bin/python3 /home/pi/Desktop/Scripts/oee_calc.py
  Wants=mysite.service
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>The python script is initiated, but the django server is not.</p>
  
  <p>Any suggestions on how this can be done?</p>