Chapter 2 · Lesson 7
Intermediate
1 min read
Services with systemd
Overview
systemd is a service manager that starts processes, tracks units and handles dependencies. A service unit is a configuration file describing how to start and stop a process. systemctl sends commands to systemd.
Detailed Notes
Inspect a service
bash
systemctl status nginx
systemctl is-active nginx
systemctl is-enabled nginx
statusshows state, process and recent logs.is-activeprints active/inactive.is-enabledshows whether it starts at boot.
Control:
bash
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl enable nginx
sudo systemctl disable nginx
restart stops and starts. reload asks a service to reread configuration without a complete restart when supported.
Unit files
ini
[Unit]
Description=Example API
After=network.target
[Service]
User=app
WorkingDirectory=/opt/app
ExecStart=/usr/bin/node server.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
ExecStartis the process that starts.Userruns it as a named account.Restart=on-failurerestarts after a failure.WantedBydefines boot target membership.
After editing a unit:
bash
sudo systemctl daemon-reload
sudo systemctl restart app
systemctl status app
daemon-reload tells systemd to reread unit files.
Common Interview Questions
Finished this lesson?
0 of 25 lessons done · 0% of the course

