Linux Labs

Packages, services, and logs / Stage 8 of 13

Your own service unit and applying changes

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 7 · lab · 30 minmedium

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:

  1. The service is running, and its process listens on port 9000.
  2. The service's process runs as the user myapp.
  3. 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
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab 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
node1 Ubuntu 24.04

Lab 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
Loading…