# Services with systemd

> Run, supervise, schedule and log long-running services on modern Linux using systemd units and journald. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/devops/systemd-services
Last updated: 2026-11-28

Run, supervise, schedule and log long-running services on modern Linux using systemd units and journald.

Intermediate · about 6 hours · difficulty 2/5

Learn first: [Processes, Signals and Resources](https://www.internhack.in/roadmaps/tracks/devops/processes-signals), [Users, Groups and Permissions](https://www.internhack.in/roadmaps/tracks/devops/users-permissions)

**systemd** is the init system on almost every mainstream distribution. It starts services at boot, restarts them when they crash, orders dependencies, schedules jobs and collects logs. If you deploy anything to a VM, you will write unit files.

### Working with units

- `systemctl start|stop|restart|reload|status <unit>`, `enable` to start at boot, `daemon-reload` after editing files.
- Unit files live in `/etc/systemd/system/`. A service unit has `[Unit]` (description, `After=`, `Wants=`), `[Service]` (`ExecStart`, `User`, `Restart=on-failure`, `Environment`/`EnvironmentFile`) and `[Install]` (`WantedBy=multi-user.target`).
- Override vendor units safely with `systemctl edit` (drop-in files) instead of editing the originals.

### Logs and timers

- `journalctl -u myapp -f`, `--since "10 min ago"`, `-p err` to filter by priority.
- **Timers** replace cron for scheduled jobs, with logging and missed-run handling built in.

### Hardening

Directives like `NoNewPrivileges=true`, `ProtectSystem=strict`, `PrivateTmp=true` and resource limits (`MemoryMax`, `CPUQuota`) sandbox a service cheaply.

### Pitfalls

Forgetting `daemon-reload`, services that fork into the background when systemd expects `Type=simple`, and restart loops that hide a crash (check `systemctl status` and the journal).

**Good enough to move on:** you can turn any app into a hardened systemd service that restarts on failure, and schedule a job with a timer.

## Key concepts

- **systemctl basics**
- **Writing service unit files**
- **Restart policies and dependencies**
- **journalctl**
- **systemd timers vs cron**
- **Drop-in overrides**
- **Sandboxing directives**

## Mini project

Deploy a small web app as a systemd service running under its own user with Restart=on-failure and an EnvironmentFile, then add a timer that hits its health endpoint every 5 minutes and logs failures.

## Check yourself

You edited a unit file and restarted the service but nothing changed. What step did you miss?

## Free resources

- [systemd project](https://systemd.io/) (systemd.io)
- [systemd man pages](https://www.freedesktop.org/software/systemd/man/latest/) (freedesktop.org)

Previous: [Users, Groups and Permissions](https://www.internhack.in/roadmaps/tracks/devops/users-permissions) · Next: [Performance and Troubleshooting](https://www.internhack.in/roadmaps/tracks/devops/linux-performance)

## More in Living on Linux

- [Linux Command Line and Packages](https://www.internhack.in/roadmaps/tracks/devops/linux-basics)
- [Processes, Signals and Resources](https://www.internhack.in/roadmaps/tracks/devops/processes-signals)
- [Filesystems, Disks and Storage](https://www.internhack.in/roadmaps/tracks/devops/filesystems-storage)
- [Users, Groups and Permissions](https://www.internhack.in/roadmaps/tracks/devops/users-permissions)
- [Services with systemd](https://www.internhack.in/roadmaps/tracks/devops/systemd-services)
- [Performance and Troubleshooting](https://www.internhack.in/roadmaps/tracks/devops/linux-performance)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
