How to Create a Systemd Service File

How to Create a Systemd Service File

This tutorial goes through creating a systemd service file. Simple and to the point. It assumes you have a linux service installed, for which your system can’t find systemd <service_name>.service file for. 

Checking Service Install Directory

First off we need to find which directory our service is installed in for most Linux distros it should be under: /usr/local/bin/.

							
							
					which <service_name> # replace <service_name> with your actual service name				
			

Creating Systemd Service File

Next we will create a systemd service file for our service

							
							
					sudo nano /etc/systemd/system/<service_name>.service # replace <service_name> with your actual service name				
			

and we will enter the following into the file:

							
							
					[Unit]
Description= # Your description here
After=network.target

[Service]
ExecStart=/usr/local/bin/<service_name> # # replace <service_name> with your actual service name
Restart=always
User=nobody
Group=nogroup

[Install]
WantedBy=multi-user.target
				
			

Press CTL+O then ENTER to save the file, CTL+X to exit the nano editor.

Next we will reload the systemd daemon.

							
							
					sudo systemctl daemon-reload
				
			

That’s it! You can start and manage your service now just as you would normally.

							
							
					sudo systemctl start <service_name> # replace <service_name> with your actual service name				
			

Walter is a tech entrepreneur and in his free time loves fitness, art, writing, and exploring Montana's outdoors.