DEV Community

Thiago Massari Guedes
Thiago Massari Guedes

Posted on • Edited on

2

Creating a service (daemon) in Linux using System D

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more