systemd services
Writing and driving a service unit: its three sections, ExecStart, Type, Restart, User, After, Requires, Wants, WantedBy, systemctl, unit states and journalctl -u.
- 32 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
systemd unit: what is it?
Show the answer
An object managed by systemd and described by a configuration file: service, timer, socket, mount point or target.
The suffix gives the type:
.service,.timer,.target. Package files live in/usr/lib/systemd/system, the administrator's in/etc/systemd/system, which takes precedence.This unit's server crashes with exit code 1. What does systemd do?
```ini
[Unit]
Description=Serveur app
After=network.target
[Service]
User=app
ExecStart=/opt/app/serveur
Restart=on-failure
[Install]
WantedBy=multi-user.target`- It restarts it, since a failed exit falls under Restart=on-failure
- It leaves it stopped: only Restart=always restarts after a failed exit
- It restarts it at the next boot only, because of WantedBy=
- It also stops network.target, which the service depends on according to After=
Show the answer
It restarts it, since a failed exit falls under Restart=on-failure
on-failurecovers an exit with a non-zero code or a signal.After=creates no dependency, andWantedBy=is only used byenable.A service unit file has three sections: … for the description and dependencies, … for the command launched, … for what enable does.
Show the answer
A service unit file has three sections: [Unit] for the description and dependencies, [Service] for the command launched, [Install] for what enable does.
ExecStart=,User=,Type=andRestart=go in the command's section;After=andRequires=in the first;WantedBy=in the last.Service type (Type=): what is it?
Show the answer
The directive that tells systemd how to know the service has started: simple (the process launched is the service), forking (the parent exits, the child stays), oneshot (the command ends, and that is all).
The default
simplesuits a program that stays in the foreground: systemd supervises it and sends its output to the journal.forkingis for old daemons that detach on their own.systemctl status app shows “Main process exited, code=exited, status=203/EXEC”. What is the likely cause, and the fix?
- The service runs out of memory: raise the limit with MemoryMax=
- The account named by User= does not exist: create it with useradd
- The ExecStart path is wrong or the file is not executable: check with ls -l, then chmod +x or fix the path
- The listening port is held by another process: pick another one
Show the answer
The ExecStart path is wrong or the file is not executable: check with ls -l, then chmod +x or fix the path
203/EXECmeans systemd could not run the command: missing path, missing execute permission or script interpreter not found. An unknown account gives217/USER.