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?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
My recipe for service obliteration (be careful with the
systemctl stop [servicename] systemctl disable [servicename] rm /etc/systemd/system/[servicename] rm /etc/systemd/system/[servicename] # and symlinks that might be related rm /usr/lib/systemd/system/[servicename] rm /usr/lib/systemd/system/[servicename] # and 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.
/etc/systemd/system/. For reference see: access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/… Mar 8, 2017 at 0:18
systemctl cat [servicename].
systemctl reset-failedin the end?
You are probably looking for
$ sudo systemctl reset-failed $
From the systemd man page:
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.
Sounds like you uninstalled it, but didn't remove the systemd hook:
# systemctl disable [servicename]
Adding on to @mark-lakata's answer and keeping in mind the attentiveness required for the
[chkconfig] can simplify the process!(click here to read about chkconfig)
To re-iterate the list of commands:
systemctl stop [servicename]
chkconfig [servicename] offOR for newer systems
systemctl disable [servicename]
Note: The 1st command is optional depending on whether you want keep the service running in the present session or not (as for this question the command should be used).
The 2nd command takes care of both disabling and removing (following the symlinks) the service.
chkconfigwas the original command to enable/disable SysVinit services. In systems using
systemd, it may be present as a backward compatibility command; but the native
systemctlcommand is just as simple:
systemctl disable [servicename]
systemctl disableis not removing the unit files for me
A simple Oneliner could be:
service=YOUR_SERVICE_NAME; systemctl stop $service && systemctl disable $service && rm /etc/systemd/system/$service && systemctl daemon-reload && systemctl reset-failed
service to your desired service that should be deleted. E.g.
Removing a service from systemd :
Systemd uses unit (file to define services) to remove a service the unit have to be removed... here is a list of unit locations :
/etc/systemd/system/ (and sub directories) /usr/local/etc/systemd/system/ (and sub directories) ~/.config/systemd/user/ (and sub directories) /usr/lib/systemd/ (and sub directories) /usr/local/lib/systemd/ (and sub directories) /etc/init.d/ (Converted old service system)
Refresh systemd :
systemctl daemon-reload systemctl reset-failed
Ghost services (not-found) :
Systemd can list ghost (not-found) services even if the unit is deleted for many reasons
(*) if a service is mentioned in other unit but does not exist systemd will still list that service with the state not-found even if there is not unit file... you can search what unit is using that service with a text search and edit those units (not recommended if you plan to install that service later)
Disclosure: I am the owner of Linuxhacks.org
the best and official way to remove a service and its override files is:
systemctl revert servicename
this will delete anything created with:
which will revert the given unit to its vendor configuration