Create a custom systemd service.
Reminder: you can left-scroll and right-scroll the long code blocks
This article shows how to create custom service running under systemd on Linux. This way, you can use the same command you use to manage an Apache or Nginx services, but this time to manage you own services.
Create a cusom systemd service
-
Create a
hermit.service
file in the directory/etc/systemd/system/
. In the exemple above, other options for ̀Type
(under[Service]
) includeforking
, and other options forRestart
includealways
andon-abort
.1
2
3
4
5
6
7
8
9
10
11
12
13[Unit]
Description=My Custom Service
After=network.target
[Service]
Type=simple
User=hermit
WorkingDirectory=/home/hermit
ExecStart=/home/hermit/bin/hermit_deamon
Restart=on-failure
[Install]
WantedBy=multi-user.target -
Start the service:
1
systemctl start hermit.service
-
Let the service start at boot:
1
systemctl enable hermit.service
Basic service management
Enable or disable “start on boot”
1 | systemctl enable hermit.service |
Start or stop a service
1 | systemctl start hermit.service |
Reload or restart a service
1 | systemctl daemon-reload hermit.service |
Check the status of a services
This command will let you see if the service is running, show you its uptime and display its latest logs.
1 | systemctl status hermit.service |
Check the logs of the services
This command get the last 100 logs from the given service.
1 | journalctl -n 100 -u hermit.service |
Written on Mon Mar 4th 2019, 5:05 GMT+00:00.
Last updated on Mon Mar 4th 2019, 5:05 GMT+00:00.