Tags: #linux
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
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.
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:
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 superawesome.service
# Stop the service
systemctl stop superawesome.service
# Start the service
systemctl start superawesome.service
# Check service status (if it crashed or failed to start, you'll see the reason here)
systemctl status superawesome.service