How to remove service linux

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 service from ubuntu

Process — How do I kill processes in Ubuntu?, To kill a process you will use the kill command, which sends a SIGNAL to the process. The signal indicates what the process should do. For example, sending a -1 to the process will ask it to reload the configuration file; sending a -2 is equivalent to pressing the Control+C on that process; -9 will cause the kernel to abandon …

Disable services on startup in ubuntu [duplicate]

I installed these applications on my Ubuntu:

These applications run every time the computer turns on.

How can I prevent these applications from running on start up?
So, these applications only run if I do «service nginx start».

If you are not using systemd (Ubuntu 14.10 and earlier) use:

The following command will give you a list of all services on your machine:

You should be able to find the names of the services you want to disable in there.

For more details, see enabling-and-disabling-services and for the very long answer see this post (as already mentioned by @muru).

Читайте также:  Проверить какие порты слушаются linux

For more details, see this post on Digital Ocean and the man page for systemctl.

Another method is by installing rcconf apt-get install rcconf . From rcconf you can enable/disable any service that is installed on your ubuntu/debian server.

apt-get install sysv-rc-conf 

Then simply to list services

To disable any services i.e nginx

For more information see man sysv-rc-conf

How to Disable a Service in Ubuntu?, The “apache2” service will remain active even upon restarting the system. Conclusion: There are two different init systems Ubuntu used, the “upstart” and the “systemd”.Both have different methods to manage the running services. The “systemd” is a widely adopted init system as “upstart” has been deprecated.This …

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?

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.

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.

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

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.

How to close ports / disable services?, This should tell you which program is running. From then on, you have several possibilities. First, you can just uninstall the corresponding program, in this case the mailserver that’s running. Second, if you want to keep the program, you could try just stopping the service, like so: sudo stop exim4.

Читайте также:  Чем открыть pcap linux

How to start and stop a service? [duplicate]

Possible Duplicate:
What’s the recommended way to enable / disable services?

Are there any other command to start stop restart service in ubuntu other than the below following.

You can use the following commands:

service stop service start service restart 

Note service —status-all doesn’t stop or start anything, it just returns a status (and there’s some known bugs in it).

If you have upstart then you can use these:

It depends largely on the service. The new and preferred way to stop start and restart services is through /etc/init.d . So, for example, to stop or start the Apache Webserver, you can run

The same is true of many other services, but probably not all. You can use the utility sysv-rc-conf to see which services you have that use an init.d script and manage them that way as well. Run it with sudo sysv-rc-conf .

If you’re looking for a GUI application, try Boot up Manager. Install with

and run from the UI or from a terminal with

Usage and documentation can be found here.

13.04 — how to remove a service that not be enabled, So — to stop a service running after a reboot, the best thing to do is manipulate the rc*.d scripts. And the best way to do that is to use the update-rc.d command. e.g. to disable ntp at boot, run: update-rc.d ntp disable. As to what services to disable — be careful that you understand what a service does and its purpose before disabling …

Источник

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.

Читайте также:  Передать файлы между linux

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

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

Источник

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