Creating a startup service for python script to run as root in Arch Linux
<p>I have a python script that I want to run on start up as root. I believe that I need to add it as a service file but I don't know if it has root permission. This is how i have my service file. The python file wont run unless in root.</p>

<pre><code>[Unit]
Description= Description here

[Service]
Type=simple
ExecStart=/usr/bin/python /home/script.py
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=script.service
</code></pre>

<p>Any help will be appreciated.</p>

<p>Got it to work. After I removed the root check from my python script everything worked fine, i also removed the <code>Type=simple</code> part from the service file. After those two things it worked fine.</p>

<p>the root check part i removed was.</p>

<pre><code>from os import getenv
user = getenv("SUDO_USER")
if user is None:
    print ("This program needs to run as root")
    exit(0)
</code></pre>

<p>and the service file now looks like this</p>

<pre><code>[Unit]
Description= Description here

[Service]
ExecStart=/usr/bin/python /home/script.py
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=script.service
</code></pre>

<p>I still don't understand why I needed to take out the root check, program ran fine when I used <code>sudo python script.py</code>. For some reason when the script was ran with systemctl it would fail the root check.</p>

python linux root startup