If I install a new service then decide I don’t want that application anymore and delete it, the service is still listed in the output from systemctl as error.

Where is this coming from and how can I remove them thoroughly?

share|improve this question
    
Please take into account that this site depends on its users for usability and credibility. The second answer is WAY BETTER than the first, and should be the accepted answer. – OmarOthman Mar 3 '17 at 7:37
up vote 98 down vote accepted

My recipe for service obliteration (be careful with the rm statements!)

systemctl stop [servicename]
systemctl disable [servicename]
rm /etc/systemd/system/[servicename]
rm /etc/systemd/system/[servicename] symlinks that might be related
systemctl daemon-reload
systemctl reset-failed

It is possible that the systemd service 'wraps' the old style scripts in /etc/init.d, so you may want to clean that up too, but that is not where systemd services live.

share|improve this answer
1  
Be aware that there are multiple locations where Systemd unit files are stored, notably /usr/lib/systemd/system and also /etc/systemd/system/. For reference see: access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Lin‌​ux/… – Mark Edington Mar 8 '17 at 0:18
1  
I had also to remove /etc/init.d/[servicename] before running systemctl reset-failed – Andrea Romagnoli Jun 7 '17 at 15:21
    
Right, I forgot to disable before removing the unit files. BTW, to find all unit files to remove, I inspect the output of systemctl cat [servicename]. – Amir Sep 17 '17 at 14:55
    
It may be a "wrapped" old style script in /etc/init.d/ but if you dont remove it you will find it still showing up under services left over from your removal. I can tell you that was the case for me. You could simply add that to your answer to make it more complete but hopefully the next person that needs it will look at the comments. – Marlon Nov 29 '17 at 1:30
    
@Marlon - If your /etc/init.d service is still running after removing the wrapper service, then it is configured outside the narrow scope of this question (which is simply about systemd). If you have sym links from /etc/r c* pointing to /etc/init.d, then you are not running systemd. – Mark Lakata Nov 30 '17 at 2:53

Sounds like you uninstalled it, but didn't remove the systemd hook:

# systemctl disable [servicename]

share|improve this answer

You are probably looking for reset-failed:

$ sudo systemctl reset-failed
$

From the systemd man page:

reset-failed [PATTERN...]

Reset the "failed" state of the specified units, or if no unit name is passed, reset the state of all units. When a unit fails in some way (i.e. process exiting with non-zero error code, terminating abnormally or timing out), it will automatically enter the "failed" state and its exit code and status is recorded for introspection by the administrator until the service is restarted or reset with this command.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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