Step 6 of 7 · lab · 30 min
Write a systemd unit for a service
A daemon is started by hand in a terminal. Turn it into a systemd service that survives a reboot and a crash.
Situation
A developer left a daemon on the server, /usr/local/bin/myapp: it runs in the foreground and
listens on port 9000. So far it is started by hand in a terminal, so once the administrator
logs out or the server reboots, the daemon is not running. A user myapp that cannot log in has
already been created for the daemon.
Task
Turn the daemon into a systemd service myapp with the file /etc/systemd/system/myapp.service:
- The service is running, and its process listens on port
9000. - The service's process runs as the user
myapp. - The service starts at system boot and starts again by itself after a crash.
The daemon itself does not need changing.
The tools you need are already installed. There is no internet on this machine.
Lab · on your own
No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.
Goals
0 of 6-
The unit file /etc/systemd/system/myapp.service exists — not done yet
-
The myapp service is active — not done yet
-
Port 9000 is served by the myapp service's process — not done yet
-
The service's process runs as the user myapp — not done yet
-
The myapp service is enabled at boot — not done yet
-
myapp starts again after a crash — not done yet
The machine is starting
Hints
0 of 3Lab goals
0 of 6-
The unit file /etc/systemd/system/myapp.service exists — not done yet
-
The myapp service is active — not done yet
-
Port 9000 is served by the myapp service's process — not done yet
-
The service's process runs as the user myapp — not done yet
-
The myapp service is enabled at boot — not done yet
-
myapp starts again after a crash — not done yet
Goals are checked on the machine after every command.