The systemd unit failed to load because the systemd daemon itself encountered an unrecoverable state while parsing the unit file.
Common Causes and Fixes:
-
Syntax Errors in the Unit File:
- Diagnosis: Run
systemd-analyze verify /etc/systemd/system/your-unit-name.service. This command parses unit files for syntax errors without trying to activate them. - Fix: Examine the output of
systemd-analyze verify. It will point to the exact line and character causing the problem. Common errors include missing[Unit],[Service], or[Install]sections, incorrect key-value pairs (e.g.,ExecStart=/usr/bin/my-appinstead ofExecStart=/usr/bin/my-app), or misplaced dependencies. Correct the syntax according tosystemdunit file specifications. For example, ifExecStartis missing, add it:
This works because[Service] ExecStart=/usr/local/bin/my-daemon Restart=on-failuresystemdrequires specific sections and key-value pairs to understand how to manage a service. - Example Error:
your-unit-name.service:10: unknown directive 'ExecStartt' - Fix: Change
ExecStartt=toExecStart=in/etc/systemd/system/your-unit-name.service.
- Diagnosis: Run
-
File Permissions:
- Diagnosis: Check the permissions of the unit file using
ls -l /etc/systemd/system/your-unit-name.service. - Fix: Unit files must be readable by the root user. Typically, they should have permissions of
644(owner read/write, group read, others read). Usechmod 644 /etc/systemd/system/your-unit-name.serviceto correct them. This ensures thesystemddaemon can access and read the configuration.
- Diagnosis: Check the permissions of the unit file using
-
Incorrect File Ownership:
- Diagnosis: Check the ownership of the unit file using
ls -l /etc/systemd/system/your-unit-name.service. - Fix: Unit files should typically be owned by
root:root. Usechown root:root /etc/systemd/system/your-unit-name.serviceto correct ownership. This ensuressystemd, running as root, has the necessary privileges to manage the file.
- Diagnosis: Check the ownership of the unit file using
-
Missing or Malformed Dependencies:
- Diagnosis: If your unit file has
Requires=,Wants=,Before=, orAfter=directives, usesystemctl list-dependencies your-unit-name.serviceto see if the listed dependencies exist and are valid units. Also,systemd-analyze verify /etc/systemd/system/your-unit-name.servicewill often flag invalid dependency names. - Fix: Ensure all units specified in dependency directives actually exist and are valid
systemdunits. If a dependency likenetwork-online.targetis expected but not enabled or present, you might need to install the relevant package (e.g.,systemd-networkdornetwork-manager) and enable its corresponding service. For example, if you haveWants=my-other-service.serviceandmy-other-service.servicedoesn’t exist, create it or remove theWants=line. This works becausesystemdcannot load a unit that depends on a non-existent or invalid unit.
- Diagnosis: If your unit file has
-
Unit File Name Conventions:
- Diagnosis: Verify that the unit file name follows the standard
systemdnaming conventions (e.g.,my-service.service,my-device.device,my-mount.mount). The error might be subtle, like a typo or an invalid character. - Fix: Rename the file to adhere to
systemdconventions. For instance, if you named itmy service.service, rename it tomy-service.serviceusingmv /etc/systemd/system/my service.service /etc/systemd/system/my-service.service.systemdexpects specific suffixes to identify the type of unit being managed.
- Diagnosis: Verify that the unit file name follows the standard
-
Corrupted Unit File:
- Diagnosis: The file might appear syntactically correct but contain invisible characters or be corrupted at the byte level. Use
cat -vET /etc/systemd/system/your-unit-name.serviceto reveal non-printable characters. - Fix: Recreate the unit file from scratch, carefully re-typing all content. Ensure no stray control characters or encoding issues are introduced. Copying and pasting from a known good source or text editor can sometimes introduce hidden characters. This resolves the issue by providing
systemdwith a clean, byte-for-byte correct configuration.
- Diagnosis: The file might appear syntactically correct but contain invisible characters or be corrupted at the byte level. Use
-
Systemd Daemon State:
- Diagnosis: In rare cases, the
systemddaemon itself might be in a bad state. Checksystemctl status systemd. - Fix: A full system reboot is often the most reliable way to reset the
systemddaemon.sudo reboot. This forcessystemdto re-initialize its internal state and re-scan all unit files.
- Diagnosis: In rare cases, the
After fixing any of these issues, you’ll need to run sudo systemctl daemon-reload to make systemd re-read its configuration, and then sudo systemctl start your-unit-name.service to attempt to start your service.
The next error you’ll likely encounter is a systemctl start failure if the service itself has runtime errors or if its dependencies are not met at runtime, even if the unit file loaded correctly.