Creating a daemon in System D
So, you created your awesome server-side application and you are ready to start using. However, you want it to start automatically with your server and restart if it crashes. Also, you're happy to have a system that uses System D
So, how do we do that?
(Spoiler alert: It's super easy)
Let's say your service name is Super Awesome Server
Step 1 - Create a user/group for your service
Create a user and group, optionally, or select an existing one.
Let's say, I am going to use the user and group aweserver, short for awesome server.
Step 2 - Create a file service configuration
File name: /etc/systemd/system/superawesome.service
And add this as a content of your file:
[Unit]
Description=Super Awesome Server
[Service]
ExecStart=/opt/myawesomeserver/bin/run_server
User=aweserver
Group=aweserver
Restart=always
[Install]
WantedBy=multi-user.target
Note:
- User and Group keys containing the desired user and group
- Restart = always to restart in case the application crashes
Step 3 - Starting the service
As you created a new service, reload the daemon with:
systemctl daemon-reload
You're done!
Some other interesting commands
# Restart the service
systemctl restart avahi-daemon.service
# Stop the service
systemctl stop avahi-daemon.service
# Start the service
systemctl start avahi-daemon.service
# Check service status (if it crashed or failed to start, you'll see the reason here)
systemctl status avahi-daemon.service
Top comments (0)