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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay