Back to Explore
GuideVibeFix editorialUpdated Dec 2, 2026

systemctl From Zero: Is the Service Running Now, and Will It Start at Boot?

Your service died, or it did not come back after a reboot. systemctl is the remote control for systemd: start, stop, status, and boot persistence. This guide runs every command for real on systemd 255: read-only inspection, a transient scope, a real service written from scratch, started, enabled, stopped, and deleted — plus the measured finding that is-active returns 4, not 3, when a unit is gone entirely.

Real photograph of technicians working in a server room aisle with blue cabling (illustrative photo)

Your service has died, or it did not come back up after a reboot. What do you do? On a modern Linux system, the answer almost certainly involves systemctl. It is the remote control for systemd: starting, stopping, checking status, and setting services to start at boot all go through it. This guide runs every command for real on systemd 255: from read-only status checks, to writing a real service file, starting it, enabling it for boot, then stopping and deleting it — including two details found only by running it: is-active returns 4, not 3, when a unit has vanished entirely, and enable is, at its core, just a symbolic link. Learning systemctl means grasping two questions: is this service running right now, and will it start at the next boot? Every command revolves around those two questions.

First, three nouns that trip up many people. systemd is the "manager" of a Linux system, usually the first process to run after boot (PID 1), responsible for starting and managing everything on the system. A unit is one "thing" systemd manages: a service is a .service file, a scheduled task is a .timer, a listening port is a .socket, a mount point is a .mount, and there are also targets, paths, and slices. systemctl is the command-line tool you use to talk to systemd: you tell it what to do to which unit, and it executes the request and reports back. Remember the division of labor: systemd is the manager, units are the things being managed, and systemctl is the walkie-talkie in your hand. Every command that follows is the same sentence pattern: "systemctl + verb + unit name."

The most common operations are actually read-only: look at the state first, then act. systemctl is-system-running tells you the state of the whole system — normally running, or degraded if some unit has failed. systemctl list-units --type=service --state=running lists the services that are running, with columns for LOAD (whether the unit definition loaded), ACTIVE (active, inactive, or failed), SUB (the detailed state, such as running or exited), and a description. One honest note: the machine used for this guide is a thin container, and only one service is running on it — systemd-journald.service, the journal service. On your laptop or server, the list will be long, dozens or even hundreds of services. That itself illustrates a point: list-units shows what is currently loaded in memory, not what is installed; to see all installed unit files, use list-unit-files. Read-only commands have another advantage: most of them run without root, so checking status is safe.

To see the details of one unit, use status. It is written for humans, and every line is useful. Take journald as an example: the first line gives the name and description; the Loaded line says where the unit file lives, whether it loaded, and its boot state (static, explained later); the Active line says when it started and how long it has been running; below that are the main PID, tasks, memory, CPU, and control group, followed by the most recent log lines. One detail to note: status shows only the last 10 lines of logs by default, and lines are truncated to fit the terminal width — for full logs, use journalctl --unit=name (journalctl has its own guide elsewhere, so it is not covered in depth here). One small finding from testing: journald has a drop-in file, nice.conf, meaning its configuration comes from the main file plus a fragment — and systemctl cat shows the main file and all its fragments together, which is why you should use cat to inspect configuration rather than reading files directly.

If status is for humans, show is for machines. systemctl show systemd-journald.service -p ActiveState -p SubState -p LoadState -p MainPID prints only the properties you name, one per line as name=value, ready to be parsed by a script: ActiveState=active, SubState=running, LoadState=loaded, MainPID=17. The -p flag can be repeated, or you can request several properties at once. Two more useful ones: -p FragmentPath tells you the actual path of the unit file, and -p UnitFileState tells you the boot state (journald is static). When a script needs to judge a service's state, always use show or is-active — never parse the human-readable output of status. The status format can change between versions, while show's name=value output is a stable machine interface. The systemd manual explicitly recommends this practice.

Before writing a real service, here is a way that needs no file at all: systemd-run --scope. It creates a transient scope unit to run a command, and when the command ends, the scope disappears without leaving any file behind. In testing, we ran systemd-run --scope --unit=demo286-scope sleep 30 and checked immediately: is-active reported active with exit code 0; show reported ActiveState=active and SubState=running. After stopping it and checking again, is-active still printed inactive — but the exit code had become 4, not 3. That 4 is the first finding from live testing: is-active has three exit codes, not two. Zero means running, 3 means "the unit exists but is not running," and 4 means "no such unit at all." A stopped transient scope vanishes from systemd's memory entirely, so checking it afterwards means "it does not exist." The distinction matters in scripts: asking "is the service running?" and asking "does the service exist?" are two different questions, and exit codes 3 and 4 separate them cleanly.

Now, a real service file. Our demo service is called demo286-hello.service. It is short, but every section matters. The file has three sections. The [Unit] section holds metadata: Description is a human-readable description, and After=network.target means "start me after the network is up." The [Service] section is the core: Type=oneshot means "this service runs once and exits," RemainAfterExit=yes means "count as active even after exiting," ExecStart is the command to run on start (writing hello-systemctl into /tmp/demo286-hello.txt), and ExecStop is the command on stop (deleting that file). The [Install] section governs boot: WantedBy=multi-user.target means "bring me up when the system enters multi-user mode." The choice of Type matters: oneshot fits jobs that run once and finish, such as initialization or writing a file, while a long-running service like a web server uses Type=simple, the default. RemainAfterExit is also worth remembering: without it, a oneshot service becomes inactive after it finishes; with it, the service stays active, and status shows active (exited).

After writing the file, the first step is not start — it is daemon-reload. When systemd boots, it reads all unit files into memory; after that, it does not notice when you change, add, or delete a file until you tell it to re-read. Forgetting this step is the most common mistake: the file is correct, but start runs the old version, or the new file cannot be found at all. In testing, we ran daemon-reload before start, as the guide instructs. One reassurance: daemon-reload itself does not restart any service; it only makes systemd re-read its configuration, and services that are already running are not interrupted. A related command, daemon-reexec, makes systemd re-execute itself; you will rarely need it, and knowing its name is enough.

Starting and stopping is where state changes become most visible. Before start, is-active reported inactive with exit code 3. After systemctl start demo286-hello.service, is-active reported active with exit code 0; the file /tmp/demo286-hello.txt contained exactly what ExecStart wrote, hello-systemctl; and status showed Active: active (exited), along with the ExecStart process ID and exit status 0/SUCCESS. After stopping it with systemctl stop, ExecStop deleted the file, and is-active returned to inactive with exit code 3. This sequence makes the word "state" concrete: active and inactive are not abstract labels but verifiable facts — whether a process exists, whether a file exists, and what the exit code is. One more detail: for a oneshot service, status shows the Main PID as an already-exited process (code=exited). Do not let the name "Main PID" fool you — the process is gone, and what remains is the record of its exit.

enable and disable govern something else entirely: the next boot. is-enabled checks the boot state. In testing, the demo service started as disabled with exit code 1; after systemctl enable, it became enabled with exit code 0. What did enable actually do? The output says it plainly: Created symlink /etc/systemd/system/multi-user.target.wants/demo286-hello.service → /etc/systemd/system/demo286-hello.service. It created a symbolic link. At boot, when systemd enters multi-user mode, it sees the link in the multi-user.target.wants directory and starts the service. disable deletes that link, and the output reads Removed "...". So enable and start are fully independent actions: enable governs only the next boot, not the present moment; start governs only the present moment, not the next boot. To do both at once — start now and start at boot — either run the two commands separately, or use systemctl enable --now. This distinction is the single most confused point for beginners, and it is worth one sentence to remember: start governs now, enable governs the future.

The is-enabled exit codes form a table that mirrors is-active: 0 means enabled (or static), 1 means disabled, and 4 means no such unit (printing not-found). The word static needs its own explanation: journald's is-enabled output is static with exit code 0. Static means "this unit does not need enabling, because another unit pulls it in" — journald is triggered by a socket, so it needs no boot link, and its boot state is neither enabled nor disabled but static. A few related states exist: masked (blocked, stronger than disabled — even a manual start is refused), linked, and alias, among others; in daily use, enabled, disabled, and static cover almost everything. Masking is worth knowing about: systemctl mask name blocks a service completely, and unmask reverses it. Use it when you want a service never to run, but be careful — masking a critical system service can leave a machine unbootable.

When a service fails, troubleshooting follows a fixed routine. First, check whether anything has failed: systemctl --failed lists every unit in the failed state — on the test machine, that was "0 loaded units listed," meaning none. Then look at the specific unit: systemctl status name shows the Active line and recent logs; or read the logs directly with journalctl --unit=name. There is one more counterintuitive exit code: systemctl is-failed with no arguments returns 0 when there is a failed unit, and 1 when there is none. The logic is inverted relative to is-active — is-failed asks "is anything broken?", and 0 means yes, 1 means no. In testing, is-failed returned 1, meaning nothing on the system had failed. Two more routine actions: systemctl restart name, which is stop followed by start; and systemctl reload name, which tells a service to re-read its own configuration without restarting — though reload only works if the service itself supports it, and not all services do.

A unit is not only a service. Knowing the other kinds helps you understand the whole system. A timer is a scheduler, similar in purpose to crontab: when the time comes, it triggers a service. Many scheduled tasks on modern systems have already moved from cron to systemd timers — with the advantages that you can see when a timer last ran, when it will run next (systemctl list-timers), and what it logged. A socket is a listening endpoint: it watches a port or a file and starts the matching service only when a request arrives, giving you start-on-demand. A mount unit corresponds to a filesystem mount point. A target is a collection of units — multi-user.target is "everything that should be up in multi-user command-line mode," and graphical.target is "everything for graphical mode." A path unit is a trigger: it starts a service when a file appears or changes. A slice is a resource group that limits how much CPU and memory a set of processes may use. In daily use, services and timers are the two kinds you will touch most; targets are the key to understanding "how far boot goes"; the rest you only need to recognize by name when you meet them.

Targets deserve their own explanation, because they answer the question of how far boot actually goes. Booting a Linux system is not a single switch but a chain of targets: basic.target, then multi-user.target, then graphical.target, each layer building on the one below. Servers usually stop at multi-user.target (multi-user command-line mode), while desktops continue to graphical.target. systemctl get-default shows which target the system boots to by default, and set-default changes it. WantedBy=multi-user.target means "bring me up when the system reaches multi-user mode." This mechanism evolved from the old runlevels: runlevel 3 roughly corresponded to multi-user.target, and runlevel 5 to graphical.target. Once you understand targets, you understand why enabling a service requires a WantedBy line — you are saying at which stage of boot it should be brought up. Most services hang under multi-user.target; only desktop-related services hang under graphical.target.

Logs are the other half of systemctl. When a service runs, its output is collected by journald and stored in a binary journal, which you query with journalctl. Three queries cover most needs: journalctl --unit=name shows all logs for one service; journalctl --unit=name -f follows them live, like tail -f; journalctl --unit=name --since "1 hour ago" shows the last hour. The log lines at the bottom of status output are simply the first ten lines of journalctl --unit=name. In troubleshooting, status and journalctl work together: status tells you the current state and when the service last started, and journalctl tells you what it actually printed while starting. One thing many people do not know: journald stores logs in /run/log/journal (in memory, lost on reboot) or /var/log/journal (on disk, persistent), depending on the system configuration — before looking for logs from a previous boot, confirm that persistent storage is enabled. journalctl has its own guide elsewhere; this is only the entry point.

Dependencies between units come in three pairs of words, and confusing them causes real problems. After and Before govern order only: After=network.target means "start me after the network is up," but it does not care whether the network actually came up — if the network fails, the service still starts (and may then fail on its own). Requires is a hard dependency: Requires=network.target means "do not start me without the network," and if the network stops, the service stops too. Wants is a soft dependency: Wants=network.target means "start with the network if it is there, but start anyway if it is not." Most services use the combination of After and Wants: wait for the network in ordering terms, but do not require it. The demo service only declared After=network.target, with no Wants or Requires — because it only writes a file, and whether the network is up makes no difference to it. When writing your own services, match the words to the need: Requires for hard dependencies, Wants for soft ones, After for ordering only. Getting this wrong produces two failure modes: starting too early and failing, or waiting on something that should not block you.

Restart policy is the small section of configuration most worth thinking about in production. Restart= takes several values: no (the default — if it dies, leave it), on-failure (restart only on abnormal exit, not on a clean one), on-success, and always (restart whatever happened). For a long-running service, on-failure is the usual choice: a crash gets the service pulled back up, while a deliberate manual stop stays stopped. RestartSec= sets how long to wait before restarting — five seconds avoids a tight loop of starting and crashing. There is also a pair of settings that guard against restart storms: StartLimitBurst= and StartLimitIntervalSec=, meaning "within this long, restart at most this many times, then stop trying." In newer systemd versions these settings have been renamed, so check the manual on your own machine when writing them. A oneshot demo service needs no Restart setting, because it runs once and finishes; but for a web service, an API service, or a resident agent, Restart=on-failure is nearly always worth writing. Remember: automatic restart is a safety net, not a bug fix — if a service keeps dying, read the logs first, then decide on the restart policy.

A short history helps place systemctl in a larger picture. Older Linux systems used SysV init: services were scripts in /etc/init.d/, boot was managed with chkconfig or update-rc.d, and status was checked with service name status. systemd replaced that world with unit files, but many distributions kept the service command as a compatibility shim — running service nginx status on a new system very likely just forwards to systemctl behind the scenes. A few commands are easily confused with systemctl: systemd-analyze measures boot time (systemd-analyze blame shows which service slowed boot down), hostnamectl manages the host name, timedatectl manages time, and loginctl manages login sessions. Each is a small tool in the systemd ecosystem with its own job. systemctl handles the state and switching of units, journalctl handles logs, and the division is clean. Knowing which tool does what keeps you from checking logs with systemctl or starting services with journalctl. Every tool has its own job; identify it before using it.

A few common pitfalls are worth naming in advance, because avoiding them saves hours. The first: changing a unit file and forgetting daemon-reload, covered above. The second: assuming that enabling a service starts it immediately — it does not; enable only affects the next boot, and starting it now still requires start, or enable --now for both at once. The third: assuming that starting a service means it will be there after the next boot — it does not; start only affects the present, and boot persistence still requires enable. The fourth: the difference between --user and system services. By default, systemctl manages system services under PID 1's systemd; systemctl --user manages your own per-user systemd instance. On the test machine, the --user bus cannot connect ("Failed to connect to bus: No medium found"), because the container runs no systemd for regular users — on your laptop, --user works, and it is the right place for your own small services, such as a local development server, without needing root. The fifth: never edit the stock unit files under /usr/lib/systemd/system/ directly, because upgrades will overwrite them. To change one, use systemctl edit name, which creates a drop-in fragment under /etc/systemd/system/ that survives upgrades.

The most common real-world use is writing a service for your own project, so here is a template you can adapt directly. Suppose you have a vibe-coded project, a long-running web service started with /usr/bin/node /home/lee/myapp/server.js, working in /home/lee/myapp, which you want to restart automatically when it crashes and to start at boot. The service file would look like this: in [Unit], a Description with the project name and After=network.target; in [Service], Type=simple (the default, for long-running services), WorkingDirectory=/home/lee/myapp, ExecStart=/usr/bin/node /home/lee/myapp/server.js, Restart=on-failure, and RestartSec=5; in [Install], WantedBy=multi-user.target. Write it to /etc/systemd/system/myapp.service, run daemon-reload, then start, confirm with is-active, enable for boot, and check logs with systemctl status and journalctl --unit=myapp. Two details matter: ExecStart must use absolute paths — never write just node, because systemd's environment and PATH differ from your shell's, and node may not be on its PATH. And User= can specify which user runs the service; for your own projects, run as a non-root user rather than root.

Finally, a cheat sheet collecting every command in this guide. Check the system state: systemctl is-system-running. List running services: systemctl list-units --type=service --state=running. List installed units: systemctl list-unit-files. Inspect one unit: systemctl status name (for humans), systemctl show name -p property (for machines), systemctl cat name (the full unit file). Start, stop, restart: systemctl start/stop/restart name. Boot persistence: systemctl enable/disable name, with enable --now doing both at once. Check state by exit code: is-active (0 running, 3 not running, 4 no such unit), is-enabled (0 enabled or static, 1 disabled, 4 no such unit), is-failed (0 something failed, 1 nothing failed). After changing files: systemctl daemon-reload. Show failures: systemctl --failed. Run one command transiently: systemd-run --scope command. The full measured transcript is in demo286_systemctl.sh — run it once and you can reproduce the whole experiment. Note that the timestamps and process IDs in status output change on every run; that is normal, and only those lines differ between runs.

Two more service-file settings deserve attention, because they cause a large share of "it works in my shell but not in systemd" problems. The first is the environment. A service started by systemd does not inherit your shell's environment: no aliases, no shell functions, a minimal PATH, and none of the variables from your .bashrc. If your program needs a variable, declare it explicitly with Environment=NAME=value, or load a whole file of them with EnvironmentFile=/path/to/env — which is also the right way to keep secrets out of the unit file itself. WorkingDirectory= sets the directory the process starts in, so relative paths inside the program resolve the way you expect. User= and Group= choose which account runs the process; a service that only needs to serve web traffic has no business running as root. The debugging rule follows directly: if a service fails only under systemd but works when you run the command yourself, the difference is almost always the environment — the working directory, the PATH, a missing variable, or the user. Compare the two environments before changing the program.

Timers deserve a practical example, because they are the systemd replacement for cron. A timer is a second unit file that triggers a service on a schedule. Suppose you want a backup service to run every day: the service file, backup.service, contains the backup command as a oneshot; the timer file, backup.timer, contains [Timer] with OnCalendar=daily and Persistent=true — Persistent means "if the machine was off when the time came, run it at the next boot instead of skipping it." Enable the timer, not the service, and systemctl list-timers shows when it will fire next and when it last fired. Compared with crontab, the advantages are visibility and logging: every run is recorded in the journal, failures show up in systemctl --failed, and you can see the schedule without parsing a five-field line. The crontab guide from an earlier cycle covers the classic tool; timers are the modern alternative, and for anything that needs logging and failure reporting, they are usually the better choice.

Finally, a troubleshooting walkthrough for the most common failure: you start a service and it immediately fails. First, read the status: systemctl status name shows whether it failed, when, and the exit code. Second, read the logs: journalctl --unit=name --since "10 minutes ago" shows what the program printed before dying — most failures explain themselves in the last few lines. Third, check the usual suspects in order: does the ExecStart path exist, and is it executable? Does WorkingDirectory exist? Is the User= account allowed to read the files it needs? Does the program need an environment variable that systemd does not provide? Fourth, check whether the Type matches the program's behavior: a classic trap is a daemon that forks into the background while the unit says Type=simple — systemd watches the parent process, sees it exit, and marks the service failed, even though the daemon is running fine. The fix is Type=forking with a PIDFile= pointing at the file where the daemon writes its process ID. Work through the list in order, and most failed starts resolve in minutes. When they do not, the logs are still the answer — just older ones.

Where to go next: the manual pages are genuinely readable for this tool. Start with man systemctl for the full command list, then man systemd.service for every setting a service file can take, and man systemd.unit for the settings shared by all unit types. If boot feels slow, systemd-analyze blame will name the slowest units. And when you need the logs behind a status line, the journalctl guide from an earlier cycle picks up exactly where this one leaves off. The pattern to remember is small — two questions, a handful of verbs, and exit codes that tell the truth — but it covers nearly everything a service will ever need from you.

Two questions about a service: running now? starts at boot?

Views 0Comments 0

Comments (0)

ME
0/1000
Loading comments...

Sources

Browse projectsPublish your project

Related articles

Real photograph of a fingertip with a glowing fingerprint pattern overlaid (illustrative photo)
Guide
sha256sum From Zero: Give Every File a Fingerprint, Then Verify It Before You Trust It

Downloaded an installer or a model weights file — how do you know it arrived intact? sha256sum computes a 64-hex fingerprint for any file: change one byte and the fingerprint changes completely. This guide runs every command for real on GNU coreutils 9.4: fingerprints, manifests, bulk checks, deliberate tampering, a missing file, quiet mode — plus the measured finding that --ignore-missing skips missing files, not mismatched ones.

Developer WorkflowTool TipsLearning & Career
Real photograph of a data-center aisle with network cables (illustrative photo)
Guide
timeout From Zero: Give Any Command a Time Limit — and Stop It When the Time Is Up

A command starts running and goes silent — is it working, or has it died? timeout puts an upper bound on waiting: you don't need to know why it's stuck, only how long you'll wait at most. This guide runs every timeout command for real on GNU coreutils 9.4: the 124/125/126/127/137 exit-code table, -s signal choice, -k kill-after (3.002s measured), --preserve-status, -v, and the process-group rule — by default the whole group dies together.

Developer WorkflowTool TipsDebugging
Real photograph of a monitor showing a multi-pane terminal with system logs in a dark room (illustrative photo)
Guide
watch From Zero: Run a Command Every Few Seconds and Watch the Screen for Changes

Waiting for a build, a log, a status flip — much of the time you don't need a script, just one command that re-runs every few seconds and pins the result to the screen. This guide runs every watch command for real on procps-ng 4.0.4: the default interval, the header, -d highlighting, -g stop-on-change, -q stop-on-unchanged, -e freeze-on-error — plus the measured finding that -e's exit code is always 8, whatever the manual promises.

Developer WorkflowTool TipsLearning & Career