Breaking News

Run A script as Service in Rpi

It is very essential to know how to run a python script as a service. Let us see how to do this from this tutorial.
Let us write a simple python program. (

from time import sleep

while True:
print “Hello World”
except KeyboardInterrupt, e:“Stopping…”)

Now we’re going to define the service to run this script:

cd /lib/systemd/system/
sudo nano hello.service

The service definition must be on the /lib/systemd/system folder. Our service is going to be called “hello.service”:

Description=Hello World

ExecStart=/usr/bin/python /home/pi/


Now that we have our service we need to activate it:

sudo chmod 644 /lib/systemd/system/hello.service
chmod +x /home/pi/
sudo systemctl daemon-reload
sudo systemctl enable hello.service
sudo systemctl start hello.service

For every change that we do on the /lib/systemd/system folder we need to execute a daemon-reload (third line of previous code). If we want to check the status of our service, you can execute:

sudo systemctl status hello.service

In general:

# Check status
sudo systemctl status hello.service

# Start service
sudo systemctl start hello.service

# Stop service
sudo systemctl stop hello.service

# Check service’s log
sudo journalctl -f -u hello.service

Leave a Reply

Your email address will not be published. Required fields are marked *