Turning Linux Scripts Into a Service (Daemon)

You can turn any script into a service or daemon via systemctl, w00t! How? See below ๐Ÿ˜‰ You can use this skeletal framework when creating future daemons! Step one = create a file in the following location /etc/systemd/system/name.service and then populate it with the following below.

NOTE1: The line ExecStart=/usr/bin/env perl /path/script.pl is intended for perl scripts, you will need to put in whatever applies to you here.

Service Template

Description=daemon name

ExecStart=/usr/bin/env perl /path/script.pl


Systemctl Commands

Here are some of systemctl useful commands:

# start service
sudo systemctl start SERVICE

# stop service
sudo systemctl stop SERVICE

# restart service
sudo systemctl restart SERVICE

# start service automatically on system startup
sudo systemctl enable SERVICE

# stop service from automatically starting
sudo systemctl disable SERVICE

# to get a status of all services via STDOUT and no less
sudo systemctl list-units --no-pager --type=service

# check the status of your service
sudo systemctl status SERVICE

NOTE2: To read more about the options in the config above go here.

NOTE3: To make sure your daemon resets properly fill in Restart and ResartSec. Read more here.

๐Ÿ‘ Get Blog Updates

๐Ÿ“ Latest Posts


Leave a Reply