Posts

Showing posts from July, 2018

Create a Background Service Using systemd In Linux

First of all, we are going to write a small python script which print "Hello World" every 60 seconds. This is going to be our service script (hello_world.py): 1 2 3 4 5 6 7 8 9 10 #!/usr/bin/python   from time import sleep   try :      while True :          print "Hello World"          sleep ( 60 ) except KeyboardInterrupt , e :      logging . info ( "Stopping..." ) You can execute it by  python hello_world.py . If you get boring reading so many hello worlds, press Ctrl+C (or Cmd+C on OSX) to stop it. Save this file as hello_world.py in your home folder ( home/pi/ ). Now we're going to define the service to run this script: 1 2 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": 1 2 3 4 5 6 7 8 9 10 11