Linux remove systemd service

How to remove systemd services

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?

7 Answers 7

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] # 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.

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_Linux/…

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] .

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.

This is the only correct answer. The other ones with more upvotes and the check mark are workarounds.

This was exactly what I needed. The service apparently was removed, but the failed state was still kicking around.

It sounds like this just resets the state for a service that should no longer exist. You should very likely delete the service files themselves, not simply change the state of a service you no longer want.

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 rm command. [chkconfig] can simplify the process!(click here to read about chkconfig)

To re-iterate the list of commands:

  1. systemctl stop [servicename]
  2. chkconfig [servicename] off OR for newer systems systemctl disable [servicename]
  3. systemctl daemon-reload
  4. systemctl reset-failed
Читайте также:  Astra linux запрет cd rom

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.

chkconfig was the original command to enable/disable SysVinit services. In systems using systemd , it may be present as a backward compatibility command; but the native systemctl command is just as simple: systemctl disable [servicename]

Okay, but the reason for me using this command is, you then don’t have to explicitly run the rm command

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 

Set service to your desired service that should be deleted. E.g. service=gunicorn.service

+1 for a single operation. This could easily be set in a script with the service string as argument, simplifying the process.

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

  1. unit still present on one of the systemd directory
  2. unit does not exit but a file link is still present on one of the systemd directory
  3. the service is used in other unit(s)*

(*) 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)

Sources: Linuxhacks.org
Disclosure: I am the owner of Linuxhacks.org

Источник

How to Remove Service in Linux

Sometimes you may want to remove the Systemd service or at least make it unavailable for use. There is no sense to remove the unit file, cause after the next system update this file may be recovered.

The simplest way to remove a service in Linux — remove the package which provides this service. First, find the path to the unit file. You can use the systemctl status command:

Читайте также:  Очистка манджаро линукс через терминал

sudo systemctl status nginx

Then, you can use the dpkg command to find a package which owns the file if you use Ubuntu. For example:

dpkg -S /lib/systemd/system/nginx.service

After this, you can remove the package:

If you don’t want to delete the package or it is impossible, cause the service is provided by one of the system packages, you can mask the service. Systemd wouldn’t start masked packages on the system startup even if they are added to the system autostart. And, of course, you can’t start them manually. Use the mask command to make the package unavailable. For example:

sudo systemctl mask nginx

After this, you can check the status of the service and ensure that it has been masked:

sudo systemctl status nginx

Also, you will get an error when trying to start the service:

sudo systemctl start nginx

Use the unmask command to disable masking and make the service available for using:

sudo systemctl unmask nginx

Now, you have learned how to remove service in Linux. As you can see it is pretty straightforward. Read about services in detail in this article.

Found a mistake in the text? Let me know about that. Highlight the text with the mistake and press Ctrl+Enter.

Источник

How to remove a systemd’s service?

To disable a systemd’s service the following command can be used:

systemctl stop service-name; systemctl disable service-name; 

Removing a service from systemd:

Systemd uses unit (file to define services) to remove a service the unit file 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/Reload 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

  1. Unit still present on one of the systemd directory
  2. Unit does not exit but a file link is still present on one of the systemd directory
  3. The service is used in other unit(s)*

(*) 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)

Читайте также:  Linux image entry point

Posted on 2019-05-29 by intika, viewed times and updated on August 22, 2020.

Источник

How to Enable or Disable Services in Ubuntu Systemd

Often, there is a need to enable or disable services temporarily or permanently on our Ubuntu system. Sometimes, we may require certain services to start up automatically on boot up e.g ssh or web servers and sometimes we may need to disable services we no longer require and are hogging the CPU and RAM.

In this guide, we take a look at how we can enable and disable services on Ubuntu. To do this, we must first understand that there are 3 main init systems for Ubuntu

Each init system has a different way of starting and stopping services. We’ll take a look at each one of these.

How to enable and disable services in Systemd init

To start a service in systemd run the command as shown:

systemctl start service-name

For example, to start apache web service, run

To verify that the service is running, run

Output ● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Thu 2018-03-15 17:09:05 UTC; 35s ago Docs: man:systemd-sysv-generator(8) CGroup: /system.slice/apache2.service ├─2499 /usr/sbin/apache2 -k start ├─2502 /usr/sbin/apache2 -k start └─2503 /usr/sbin/apache2 -k start Mar 15 17:09:04 ip-172-31-41-251 systemd[1]: Starting LSB: Apache2 web server. Mar 15 17:09:04 ip-172-31-41-251 apache2[2475]: * Starting Apache httpd web ser Mar 15 17:09:05 ip-172-31-41-251 apache2[2475]: * Mar 15 17:09:05 ip-172-31-41-251 systemd[1]: Started LSB: Apache2 web server.

To stop the service running service

To confirm that the service is not running, run

Output ● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: inactive (dead) since Thu 2018-03-15 17:19:47 UTC; 12s ago Docs: man:systemd-sysv-generator(8) Process: 2822 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS Process: 2687 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCE Mar 15 17:10:11 ip-172-31-41-251 systemd[1]: Starting LSB: Apache2 web server. Mar 15 17:10:11 ip-172-31-41-251 apache2[2687]: * Starting Apache httpd web ser Mar 15 17:10:12 ip-172-31-41-251 apache2[2687]: * Mar 15 17:10:12 ip-172-31-41-251 systemd[1]: Started LSB: Apache2 web server. Mar 15 17:19:46 ip-172-31-41-251 systemd[1]: Stopping LSB: Apache2 web server. Mar 15 17:19:46 ip-172-31-41-251 apache2[2822]: * Stopping Apache httpd web ser Mar 15 17:19:47 ip-172-31-41-251 apache2[2822]: * Mar 15 17:19:47 ip-172-31-41-251 systemd[1]: Stopped LSB: Apache2 web server.

To enable apache2 service on boot up run

To disable apache2 service on boot up run

Источник

Оцените статью
Adblock
detector