How to Create a new service with systemd

create a new service with systemd

This tutorial (create a new service with systemd) describes the steps to follow to turn a program into a systemd service that can be started automatically during system startup. For our example, we will create a service to start the daemon Deluge start ( deluged ), but it can be applied to any program.


  • Have the administrative rights
  • Knowing how to use the terminal

How to create a new service with systemd

Creating a program encapsulating script

Deluged does not support stopping or stimulus parameters, we need to create a script that will do that. We can store the script in / usr / local / bin

sudo cat> /usr/local/bin/

Then paste the following code:

#! / bin / bash 
# /usr/local/bin/ 
function d_start ( ) 
	echo  "Deluge: starting service" 
	deluged --pidfile = / tmp /
	 sleep  5 
	echo  "PID is $ (cat /tmp/ " 
function d_stop ( ) 
	echo  "Deluge: stopping Service (PID = $ (cat /tmp/ )" 
	kill $ ( cat  / tmp / ) 
	rm  / tmp /
function d_status ( ) 
	ps  -ef  |  grep deluged |  grep  -v  grep 
	echo  "PID indicate indication file $ (cat /tmp/ 2> / dev / null) " 
# Some Things That run always 
touch  / var / lock / deluge
# Management instructions of the service 
box  "$ 1"  in 
	start )
	Stop )
	Reload )
		sleep  1
	Status )
	* ) 
	Echo  "Usage: $ 0 {start | stop | reload | status}" 
	exit  1 
exit  0

Create the service file

In Systemd, services are defined in files tickets · located in / etc / systemd / system / .

Create a service package for our program:

sudo cat> /etc/systemd/system/deluge.service

Then paste the following code:

Description = Deluge daemon
After = auditd.service

Type = forking
ExecStart = / usr / local / bin / start
ExecStop = / usr / local / bin / stop
ExecReload = / usr / local / bin / reload

WantedBy =

Service Installation

We must now reload the list of services:

sudo systemctl daemon reload

Then activate the launch of the service at boot:

sudo systemctl enable deluge

Key services management commands

For reference, the following commands to manage the service:

In our example, <service> == deluge

systemctl sudo 
order Description
start Start Service
stop Stop Service
status Service Status
is-enabled Whether the service is activated at boot
enable Active start the service
disable Disables the startup service


Please note, services are launched by root , so if you have already configured the program with another user, it will:

  • either copy the configuration to root ,
  • or point the service to the proper configuration (for deluged there is an option -config )

So, it remains only to test that everything is working by running the service:

sudo systemctl start deluge

If everything can restart the machine to check that the service starts automatically:

sudo reboot

You May Also Like

About the Author: admin

Leave a Reply

Your email address will not be published.