failed
- happens when a unit has entered a failed state and can be reset with the systemctl reset-failed
command
not-found
- happens when you've removed a unit but systemd still has a reference to it, like when a unit gets enabled and a symlink gets placed in /etc/systemd/system
, this can be fixed by removing references to the unit in /etc/system/systemd/*.wants/
then running systemctl daemon-reload
For example, assume the following bash script:
#!/bin/bash
# script.sh
while true
do
sleep 1
done
And 3 systemd units: example-foo.service
, example-bar.service
, and example-baz.service
$ sudo systemctl cat example-{foo,bar,baz}.service
# /etc/systemd/system/example-foo.service
[Service]
ExecStart=/home/vagrant/script.sh
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/example-bar.service
[Service]
ExecStart=/home/vagrant/script.sh
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/example-baz.service
[Service]
ExecStart=/home/vagrant/script.sh
[Install]
WantedBy=multi-user.target
Now, let's start and enable the units. Observe how symlinks get created.
$ sudo systemctl start example-{foo,bar,baz}.service
$ sudo systemctl enable example-{foo,bar,baz}.service
Created symlink from /etc/systemd/system/multi-user.target.wants/example-foo.service to /etc/systemd/system/example-foo.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/example-bar.service to /etc/systemd/system/example-bar.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/example-baz.service to /etc/systemd/system/example-baz.service.
Confirm there are actually 6 files for our 3 units.
$ find /etc/systemd/system -name 'example*.service'
/etc/systemd/system/multi-user.target.wants/example-bar.service
/etc/systemd/system/multi-user.target.wants/example-foo.service
/etc/systemd/system/multi-user.target.wants/example-baz.service
/etc/systemd/system/example-bar.service
/etc/systemd/system/example-foo.service
/etc/systemd/system/example-baz.service
Now, check the state of all 3 units, they're running.
$ systemctl list-units example*
UNIT LOAD ACTIVE SUB DESCRIPTION
example-bar.service loaded active running example-bar.service
example-baz.service loaded active running example-baz.service
example-foo.service loaded active running example-foo.service
Now, simulate a failure by sending a SIGKILL to example-foo.service
. Observe how the unit is in a failed state.
$ sudo systemctl kill -s KILL example-foo.service
$ systemctl list-units example*
UNIT LOAD ACTIVE SUB DESCRIPTION
example-bar.service loaded active running example-bar.service
example-baz.service loaded active running example-baz.service
● example-foo.service loaded failed failed example-foo.service
To reset a unit in a failed state use the systemctl rese-failed
command. Observe how the unit is now in an inactive state.
$ sudo systemctl reset-failed
$ systemctl list-units example*
UNIT LOAD ACTIVE SUB DESCRIPTION
example-bar.service loaded active running example-bar.service
example-baz.service loaded active running example-baz.service
...
$ systemctl list-units --all example*
UNIT LOAD ACTIVE SUB DESCRIPTION
example-bar.service loaded active running example-bar.service
example-baz.service loaded active running example-baz.service
example-foo.service loaded inactive dead example-foo.service
Okay, now let's remove the example-bar.service unit. Observe how the unit is in a not-found state; however, the example-bar.service broken symlink is still in /etc/system/system/multi-user.target.wants
$ sudo rm /etc/systemd/system/example-bar.service
$ sudo systemctl daemon-reload
$ sudo systemctl stop example-bar.service
Failed to stop example-bar.service: Unit example-bar.service not loaded.
$ systemctl list-units --all example*
UNIT LOAD ACTIVE SUB DESCRIPTION
● example-bar.service not-found inactive dead example-bar.service
example-baz.service loaded active running example-baz.service
example-foo.service loaded inactive dead example-foo.service
$ find /etc/systemd/system -name 'example*.service'
/etc/systemd/system/multi-user.target.wants/example-bar.service
/etc/systemd/system/multi-user.target.wants/example-foo.service
/etc/systemd/system/multi-user.target.wants/example-baz.service
/etc/systemd/system/example-foo.service
/etc/systemd/system/example-baz.service
Remove the broken symlink and confirm the example-bar.service unit is gone.
$ sudo rm /etc/systemd/system/multi-user.target.wants/example-bar.service
$ sudo systemctl daemon-reload
$ systemctl list-units --all example*
UNIT LOAD ACTIVE SUB DESCRIPTION
example-baz.service loaded active running example-baz.service
example-foo.service loaded inactive dead example-foo.service