Linux & Servers guides, explanations and reader checklists on whilenetworking.com

Diagnosing Systemd Boot Failures: How to Analyze Service Units and Journal Logs

When a Linux server fails to boot, or when a specific service refuses to start after an update, the root cause is almost invariably hidden within systemd …

When a Linux server fails to boot, or when a specific service refuses to start after an update, the root cause is almost invariably hidden within systemd unit files or its journal logs. For IT students and junior engineers, relying on generic restart commands often leads to circular errors where services fail because dependencies are missing or permissions are incorrect. To move from reactive troubleshooting to proactive stability, one must learn to read the boot sequence like a story, identifying exactly which character (service) tripped at which scene (boot phase). This guide provides a concrete methodology for analyzing systemd failures using real-world commands and journal inspection techniques.

Understanding the Boot Sequence and Unit States

Before diving into logs, it is essential to understand how systemd manages services. A service unit can be in several states: running, failed, activating, or dead. When a system boots, systemd attempts to start units defined in /etc/systemd/system/ and /lib/systemd/system/. If a unit depends on another that fails, the dependent unit will also fail unless configured otherwise.

To begin any diagnosis, you must check the overall boot status immediately after the kernel loads but before graphical login prompts appear. Run the following command to see if the system entered multi-user mode or failed early:

systemctl get-default.target
systemctl list-units --state=failed

Illustrative Output:

  UNIT           LOAD   ACTIVE SUB    DESCRIPTION
  ssh.service    loaded failed dead  OpenSSH server daemon
  nginx.service  loaded failed dead  A high performance web server

If units show as failed, clicking on them reveals the specific error message. Note that “loaded” means the configuration file exists, but “failed” indicates the start attempt did not succeed. Common causes at this stage include missing binaries (e.g., a binary was deleted or moved), incorrect file permissions, or network dependencies that timed out.

Inspecting Journal Logs for Specific Errors

The journalctl command is the primary tool for forensic analysis in systemd. By default, it shows recent logs from all services, but filtering by unit name is crucial for isolation. When a service fails, systemd usually prints an error to the journal explaining why the start command returned a non-zero exit code.

To view logs for a specific failed service, use:

journalctl -u <service-name> -n 50 --no-pager

Replace <service-name> with the actual unit name, such as nginx.service. The -n 50 flag limits output to the last 50 lines, preventing information overload. The --no-pager option ensures the output scrolls in a terminal-friendly format rather than requiring page navigation.

Expected Result Analysis:
Look for keywords like ExitCode=, Failed with result:, or specific error codes like permission denied. For example, if a web server fails due to a missing SSL certificate, the log might read: SSL_CTX_use_certificate_file failed: No such file or directory. If the error mentions Permission denied, it often points to SELinux contexts or standard Unix file permissions (e.g., a script trying to write to /var/log owned by root while running as a non-root user).

Analyzing Service Unit Files and Dependencies

Sometimes the issue is not in the runtime logs but in the unit definition itself. Open the service file using systemctl cat <service-name> or by editing directly in /etc/systemd/system/. Pay close attention to the [Unit] section, specifically the After= and Requires= directives. These define dependencies. If a service is configured to start before its database dependency is ready, it will fail immediately upon startup.

Consider a scenario where a custom application service fails because it expects a network interface to be up. If the network unit (network.target or NetworkManager) is not listed in the After= directive, the app might crash trying to bind to an IP address on a down interface.

Common Configuration Mistake:
A frequent error seen in student labs and production environments is missing Wants= or Requires= directives when services should be coupled. For instance, if you have a service that manages backups but forgets to require the network, it might try to connect to a remote server during boot before the network stack initializes, resulting in a connection timeout.

To verify dependencies, use:

systemctl show <service-name> -p Dependencies

This command lists all required and wanted units. If a dependency is missing or incorrectly ordered, you must edit the unit file to add the correct After= directive, ensuring the dependent service starts first.

Practical Lab Scenario: Troubleshooting a Failed Web Server

To solidify these concepts, consider a realistic workplace scenario: A junior engineer reports that the company’s internal web portal is inaccessible after a system reboot. The server runs Ubuntu 24.04 with nginx and PHP-FPM.

Step-by-Step Diagnosis:
1. Check Boot Status: Run systemctl status nginx. You see Active: failed (Result: exit-code).
2. View Logs: Execute journalctl -u nginx -n 30. The log shows: bind() to 0.0.0.0:80 failed (98: Address already in use).
3. Hypothesize: Another process is occupying port 80, or a previous instance of nginx crashed and left the socket in a TIME_WAIT state.
4. Investigate Process List: Run ss -tlnp | grep :80. You find a process named nginx-worker listening on port 80 but not responding to commands.
5. Inspect Permissions: Check if the nginx config file has correct permissions: ls -l /etc/nginx/sites-available/default. If the directory is owned by www-data but the file is root-owned, nginx cannot read it during startup.
6. Fix and Restart: Correct ownership with chown www-data:www-data /etc/nginx/sites-available/default, then reload the daemon: systemctl daemon-reload && systemctl restart nginx.

This scenario highlights how logs guide you from a generic “service failed” status to a specific configuration or permission issue.

Verification Steps and Common Errors

After applying fixes, verification is critical before declaring the problem solved. Always reload the systemd manager configuration after editing unit files:

systemctl daemon-reload

Then attempt to start the service again:

systemctl start <service-name>
systemctl status <service-name>

Common Errors and Fixes:
* Error: Unit nginx.service could not be found.
* Fix: Ensure the unit file exists in /etc/systemd/system/ or /lib/systemd/system/. If using a package, verify the package was installed correctly.
* Error: Failed to start <service>: No such file or directory.
* Fix: Check that executable paths (like /usr/bin/php) exist and are not symlinks to deleted files.
* Error: Job for nginx.service failed because the control process exited with error code.
* Fix: This usually means the main configuration file has a syntax error. Run nginx -t to test config validity before restarting.

Student Practice Task and Industry Application

For students, a valuable exercise is to intentionally break a service in a virtual machine (e.g., VirtualBox or Docker) and then diagnose it without external help. Create a custom unit file that starts a dummy script which exits with code 1. Attempt to start it, observe the failure, read the journal, modify the script to exit successfully, and restart.

In industry applications, monitoring tools like Prometheus or Nagios often integrate with systemd by scraping status files (/sys/fs/cgroup/systemd/system.slice/<service>.slice/status). Understanding how to interpret systemd logs allows engineers to write better alerting rules that detect not just service down states, but specific error patterns found in the journal.

Conclusion
Diagnosing systemd boot failures requires a methodical approach: check unit states, inspect journal logs for exit codes, verify unit file dependencies and permissions, and apply targeted fixes. By mastering these skills, IT professionals can minimize downtime and ensure robust server deployments. Remember that terms, availability, eligibility, laws, and prices depend on insurer, policy, and jurisdiction; similarly, system behavior depends on OS version, kernel modules, and specific configuration nuances. Always verify changes in a test environment before applying them to production systems.

Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.