39

I'm having trouble figuring out how to remove systemd units that no longer have files. They still seem to linger in the system somehow.

The old broken units I am trying to remove:

core@ip-172-16-32-83 ~ $ systemctl list-units --all firehose-router*
  UNIT                       LOAD      ACTIVE SUB    DESCRIPTION
<E2><97><8F> firehose-router@02.service not-found failed failed firehose-router@02.service
<E2><97><8F> firehose-router@03.service not-found failed failed firehose-router@03.service

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

The files do not exist, yet a reload still has these units lingering:

core@ip-172-16-32-83 ~ $ systemctl list-unit-files firehose-router@02.service
core@ip-172-16-32-83 ~ $ sudo systemctl daemon-reload
core@ip-172-16-32-83 ~ $ systemctl list-units --all firehose-router*
  UNIT                       LOAD      ACTIVE SUB    DESCRIPTION
<E2><97><8F> firehose-router@02.service not-found failed failed firehose-router@02.service
<E2><97><8F> firehose-router@03.service not-found failed failed firehose-router@03.service

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

There are no files related to them that I can find:

core@ip-172-16-32-83 ~ $ sudo find /var/run/systemd -name "*firehose-router*"
core@ip-172-16-32-83 ~ $ find /etc/systemd/ -name "*firehose-router*"
core@ip-172-16-32-83 ~ $ find /usr/lib/systemd/ -name "*firehose-router*"
core@ip-172-16-32-83 ~ $

So how do I get rid of these?

  • You don't mention it, but I guess it fails if you try to systemctl disable them, right? – dawud Jun 19 '14 at 18:27
  • 2
    It just exist with 0. There is nothing to disable (it is already missing / disabled). – Andy Shinn Jun 19 '14 at 18:31
  • I tried all the solutions suggested here (and below so far) and rebooted and nothing worked. The units I'm trying to remove were once installed or attempted to install, and then later apt purged. So apparently apt purge does not remove the configuration that is given to systemd. It's still not clear to me if these "not-found" units cause any problems. – Elliptical view Sep 30 '16 at 5:05
  • I suspect I might be able to delete files in /var/lib/systemd/deb-systemd-helper-enabled/ but am not sure if I want to mess with this. I appear to have two known dead ends there: mariadb.service.dsh-also and mysql.service.dsh-also – Elliptical view Sep 30 '16 at 5:20
  • @Elipticalview Make a backup of these files, just in case, and afterwards remove these? – gf_ Feb 24 '17 at 10:09
71

The command you're after is systemctl reset-failed

  • 3
    Thank you! I don't know why that was not more obvious to me... – Andy Shinn Jun 19 '14 at 18:40
  • 5
    This worked for finally cleaning up a "real" service, but I have an alias service that refuses to go away. I tried disable, daemon-reloadand reset-failed but the alias service comes up as not-found inactive dead always. I also searched the disk for anything that matches the service name with no results. – Mark Lakata Jul 1 '15 at 18:16
  • 3
    I just ran into this and systemctl stop <service> worked for me. – mpontillo Aug 8 '16 at 21:58
  • The same applies for timers - they need to be stopped first before reset-failed can clean them up. – rustyx Feb 25 '18 at 19:31
0

It seems that systemd maintains links but does not know what to do with them when you delete the unit file.

You could try to remove them manually in /etc/systemd/system/suspend.target.wants/ and such but of course systemctl reset-failed from a previous answer sounds like a better option.

$ cd /etc/systemd/system
$ sudo mv lock.service /tmp 
$ sudo systemctl disable lock.service
Failed to disable unit: No such file or directory
$ sudo mv /tmp/lock.service .
$ sudo systemctl disable lock.service
Removed /etc/systemd/system/suspend.target.wants/lock.service.
0

When systemd analyzes unit definition files, it takes note of any other related units called out in the file - whether those other units exist or not.

$ systemctl --state=not-found --all
> ( ...prints list of 'not-found' units )

$ grep -r "<missing-unit>" /usr/lib/systemd/system
> ( returns files with references to <missing-unit> )

When a unit shows up as "not-found", it's not necessarily an error - all we know is, a local unit definition claims to have some relationship with it. This relationship might not be one we care about. For example, it could be "Before:" some other unit, but we don't use that other unit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.