systemd Basics: Manage Services and Read Logs with systemctl and journalctl

Linux 8 min readUpdated Nov 17, 2026
1 view0 comments
Close-up of the back of a server rack in black and white, with ports and drive bays
Photo: rawpixel (CC0, public domain). source

On almost every modern Linux server (RHEL, Rocky Linux, AlmaLinux, Fedora, Ubuntu, Debian) systemd is the program that starts everything at boot and keeps services running. Two commands do most of the daily work: systemctl to control services, and journalctl to read their logs. This guide shows you both, how to write your own service and timer, and how to track down a service that will not start. The examples were run on AlmaLinux 9 with systemd 252.

What systemd manages: units

systemd works with units. The ones you meet most:

Unit type What it is Example
.service A program that runs in the background sshd.service, httpd.service
.timer Starts another unit on a schedule (a modern cron) dnf-makecache.timer
.socket Starts a service when something connects sshd.socket on some systems
.target A group of units, like a run level multi-user.target

When you leave off the suffix, systemctl assumes .service, so systemctl status httpd and systemctl status httpd.service are the same.

The everyday systemctl commands

I want to Command (run as root or with sudo)
See the state of a service systemctl status httpd
Start / stop it now systemctl start httpd / systemctl stop httpd
Restart it (stop, then start) systemctl restart httpd
Reload its configuration without dropping connections systemctl reload httpd
Start it at every boot systemctl enable httpd
Enable and start in one step systemctl enable --now httpd
Stop it starting at boot systemctl disable httpd
Is it running? Is it enabled? systemctl is-active httpd and systemctl is-enabled httpd
Block it completely systemctl mask httpd (undo with unmask)

Two of these are easy to mix up. start/stop acts on the service now. enable/disable controls whether it starts at boot. To get both, use enable --now.

The two is- commands are made for scripts, because they print one word and return an exit code you can test:

$ systemctl is-active httpd
active
$ systemctl is-enabled httpd
enabled

Read systemctl status

$ systemctl status httpd --no-pager -n 0
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/httpd.service.d
             └─php-fpm.conf
     Active: active (running) since Sun 2026-10-25 22:10:47 UTC; 3 weeks 1 day ago
       Docs: man:httpd.service(8)
  • The dot at the start is green when the service runs and red when it has failed.
  • Loaded shows the unit file’s location, and whether it is enabled at boot.
  • Drop-In lists extra configuration files that change the service without editing the original. More on this below.
  • Active is the state (active (running), inactive (dead), failed) and how long it has been in it.

To see every service that has failed, and what is running:

systemctl list-units --type=service --state=failed
systemctl list-units --type=service --state=running
systemctl list-timers

Read the logs with journalctl

systemd collects the output of every service into one searchable journal. You rarely need to know where log files are.

I want to see Command
Logs of one service journalctl -u sshd
The last 50 lines journalctl -u sshd -n 50
New lines live (like tail -f) journalctl -u sshd -f
Only today, or a time range journalctl --since today or --since "2026-11-17 08:00" --until "2026-11-17 09:00"
Only errors and worse journalctl -p err
Since the last boot / the previous boot journalctl -b / journalctl -b -1
The end of the log, without a pager journalctl -u sshd -e --no-pager
How much disk it uses journalctl --disk-usage

Options combine. journalctl -u httpd -p err --since yesterday shows only the web server’s errors since yesterday. A line with timestamps in a precise ISO format (useful for pasting into a ticket) looks like this when you add -o short-iso:

$ journalctl -u sshd -n 2 --no-pager -o short-iso
2026-11-17T09:00:24+0000 server sshd-session[PID]: Accepted publickey for root from 203.0.113.5 port 38931 ssh2: ED25519 SHA256:...
2026-11-17T09:00:24+0000 server sshd-session[PID]: pam_unix(sshd:session): session opened for user root(uid=0) by root(uid=0)

Some distributions only keep the journal in memory, which means it is lost at reboot. To keep it on disk, create the folder /var/log/journal and restart systemd-journald, or set Storage=persistent in /etc/systemd/journald.conf. To limit its size, use journalctl --vacuum-size=200M.

Write your own service

To keep your own program running (a script, a Node.js app, a Python worker), you write a small unit file. Save this as /etc/systemd/system/myapp.service:

[Unit]
Description=My small app
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
DynamicUser=yes
WorkingDirectory=/tmp
ExecStart=/usr/bin/sleep 3600
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
  • [Unit] describes the service and its order. After=network-online.target starts it after the network is up.
  • [Service] says how to run it. ExecStart must use the full path to the program. Restart=on-failure restarts it if it crashes, and RestartSec=5 waits five seconds between attempts.
  • DynamicUser=yes runs the program under a temporary, unprivileged user that systemd creates. If you prefer a fixed account, create a dedicated user and set User= to that name. Avoid User=nobody: systemd-analyze warns that it is not safe.
  • [Install] says which target should start the service when you enable it.

Check the file before you use it. systemd-analyze verify reads a unit and reports problems without installing it:

$ systemd-analyze verify /etc/systemd/system/myapp.service
$                                   # no output means no problems

$ systemd-analyze verify bad.service      # same file with a wrong ExecStart
bad.service: Command /usr/bin/doesnotexist is not executable: No such file or directory

Then tell systemd about the new file and start it:

systemctl daemon-reload
systemctl enable --now myapp
systemctl status myapp

You must run systemctl daemon-reload every time you create or edit a unit file. Forgetting it is the most common reason a change “does not work”.

Change a service without editing the original

Do not edit files under /usr/lib/systemd/system, because package updates replace them. Add an override instead:

systemctl edit httpd

This opens an empty file in your editor, saved as a drop-in at /etc/systemd/system/httpd.service.d/override.conf. Put only what you want to change in it, for example:

[Service]
Restart=always
RestartSec=10

Save, and systemd reloads by itself. To see the final result of the original plus all overrides, run systemctl cat httpd.

Timers: the modern replacement for cron

A timer unit starts a service on a schedule. You need two files with the same name: job.service (what to run) and job.timer (when):

[Unit]
Description=Run job every day at 03:30

[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true

[Install]
WantedBy=timers.target

Enable the timer, not the service: systemctl enable --now job.timer. Persistent=true makes a missed run happen at the next boot, for example when the server was off at 03:30.

Schedule expressions are easier to get right when you test them. systemd-analyze calendar shows when an expression will next fire:

$ systemd-analyze calendar "*-*-* 03:30:00"
Normalized form: *-*-* 03:30:00
    Next elapse: Wed 2026-11-18 03:30:00 UTC

$ systemd-analyze calendar "Mon *-*-* 09:00"
Normalized form: Mon *-*-* 09:00:00
    Next elapse: Mon 2026-11-23 09:00:00 UTC

$ systemd-analyze calendar hourly
Normalized form: *-*-* *:00:00

Compared with cron, timers log to the journal (journalctl -u job.service), can catch up after downtime, and show up in systemctl list-timers. Cron is still fine for simple jobs, as in our Bash scripting guide.

Troubleshoot a service that will not start

  1. Look at the state. systemctl status myapp shows whether it is failed and often prints the last log lines and the exit status.
  2. Read the full log. journalctl -u myapp -e --no-pager jumps to the end. The error is usually just above where it stopped.
  3. Check the unit file. systemd-analyze verify catches wrong paths and typos. Make sure ExecStart uses an absolute path, and that you ran daemon-reload after editing.
  4. Run the command yourself as the same user, to see the program’s own error message.
  5. Check SELinux on RHEL-based systems. A program may be blocked from a file or port even when permissions look fine. sudo ausearch -m avc -ts recent lists recent denials.
  6. Clear a failed state after you fix the cause: systemctl reset-failed myapp, then start it again. A service that restarts too fast hits a start limit and stays failed until you reset it.

Why did my server boot slowly?

systemd can tell you where boot time went:

$ systemd-analyze time
Startup finished in 879ms (kernel) + 1.619s (initrd) + 24.975s (userspace) = 27.473s
multi-user.target reached after 24.483s in userspace.

$ systemd-analyze blame | head

blame lists units from slowest to fastest. A unit that waits for the network (such as NetworkManager-wait-online) or a cloud-provider setup service often tops the list on virtual servers. A long time there is usually normal. Only act on a service you do not need.

Quick reference

systemctl status|start|stop|restart|reload NAME
systemctl enable --now NAME      # start now and at every boot
systemctl daemon-reload          # after creating or editing a unit
systemctl list-units --state=failed
systemctl list-timers
journalctl -u NAME -e            # logs of a service, jump to the end
journalctl -u NAME -f            # follow live
journalctl -p err --since today  # today's errors
systemd-analyze verify FILE      # check a unit file
systemd-analyze calendar "EXPR"  # test a timer schedule

Next, secure the way you reach the server with SSH key login, or find out what is filling the disk when a service fails because there is no space left.

Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

More tutorials like this

Leave a Comment

Your email address will not be published. Required fields are marked *

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top