title: Running a Python script via systemd
body: <p>I am pretty new to writing <code>systemd</code> service scripts. I was following this <a href="http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/" rel="nofollow noreferrer">useful page</a> to write my own. It is failing as below.</p>
  
  <p>The <code>prodKPI.service</code> contents in <code>/etc/systemd/system/</code> in a <code>Centos 7</code> machine are as</p>
  
  <pre><code>[Unit]
  Description=prodKPI: Aggregation logic to compute device availability
  
  [Service]
  Type=simple
  PermissionsStartOnly=true
  User=deployuser
  ExecStart = /usr/bin/python /tmp/app1/folder1/file1.py; /usr/bin/python /tmp/folder2/file2.py
  Restart=always
  
  [Install]
  WantedBy=default.target
  </code></pre>
  
  <p>The steps I followed after creating the file are</p>
  
  <pre><code>systemctl daemon-reload
  systemctl enable prodKPI.service
  </code></pre>
  
  <p>did a <code>reboot</code> and </p>
  
  <pre><code># systemctl status prodKPI.service
  ● prodKPI.service - prodKPI: Aggregation logic to compute device availability
     Loaded: loaded (/etc/systemd/system/prodKPI.service; enabled; vendor preset: disabled)
     Active: failed (Result: start-limit) since Fri 2017-07-21 19:20:41 UTC; 15min ago
    Process: 1190 ExecStart=/usr/bin/python /tmp/app1/folder1/file1.py; /usr/bin/python /tmp/folder2/file2.py (code=exited, status=2)
   Main PID: 1190 (code=exited, status=2)
  
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service: main process exited, code=exited, status=2/INVALIDARGUMENT
  Jul 21 19:20:41 device-1 systemd[1]: Unit prodKPI.service entered failed state.
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service failed.
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service holdoff time over, scheduling restart.
  Jul 21 19:20:41 device-1 systemd[1]: start request repeated too quickly for prodKPI.service
  Jul 21 19:20:41 device-1 systemd[1]: Failed to start prodKPI.service: Aggregation logic to compute device availability.
  Jul 21 19:20:41 device-1 systemd[1]: Unit prodKPI.service entered failed state.
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service failed.
  </code></pre>
  
  <p>which did not help much, from </p>
  
  <pre><code>journalctl -xe
  
  -- Unit prodKPI.service has finished starting up.
  -- 
  -- The start-up result is done.
  Jul 21 19:20:41 device-1 systemd[1]: Starting prodKPI.service: Aggregation logic to compute device availability...
  -- Subject: Unit prodKPI.service has begun start-up
  -- Defined-By: systemd
  -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  -- 
  -- Unit prodKPI.service has begun starting up.
  Jul 21 19:20:41 device-1 python[1190]: /usr/bin/python: can't open file '/tmp/app1/folder1/file1.py;': [Errno 2] No such file or directory
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service: main process exited, code=exited, status=2/INVALIDARGUMENT
  Jul 21 19:20:41 device-1 systemd[1]: Unit prodKPI.service entered failed state.
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service failed.
  Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service holdoff time over, scheduling restart.
  Jul 21 19:20:41 device-1: start request repeated too quickly for prodKPI.service
  Jul 21 19:20:41 device-1: Failed to start prodKPI.service: Aggregation logic to compute device availability.
  </code></pre>
  
  <p>The error line below indicates some kind of permission issues? Should the service unit be run with a different user (or) access levels? I changed the both the python files to be executable also</p>
  
  <pre><code>Jul 21 19:20:41 device-1 python[1190]: /usr/bin/python: can't open file '/tmp/app1/folder1/file1.py;': [Errno 2] No such file or directory
  </code></pre>