Member-only story
[Technology][Linux][Systemd] — Automate Your Custom Applications Startup with Systemd on Linux
In this post, we will talk about how to configure your applications to run as a system service in Linux.
What is systemd
?
systemd
is a system and service manager for Linux, responsible for bootstrapping the user space and managing system processes. It uses unit files, usually located in /etc/systemd/system/
, to define how services behave. These unit files replace traditional init scripts and provide a more powerful and consistent way of managing services.
Let’s get started.
STEP 1. Make a backoffice.service file in /etc/systemd/system/ directory.
#/etc/systemd/system/backoffice.service[Unit]
Description= Back office service
After=mysqld.service
StartLimitIntervalSec=0[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/env node /path/to/server/app.js
[Install]
WantedBy=multi-user.target
Service Unit File Breakdown
This unit file is divided into three main sections: [Unit]
, [Service]
, and [Install]
. Each section serves a specific purpose in defining how the service should behave.