Cannot disable systemd service

8.8k views Asked by At

I've been using the dbus API from systemd and I've been enabling services with the EnableUnitFiles() function as detailed here http://www.freedesktop.org/wiki/Software/systemd/dbus/

However, when I try to disable the same service with the command

systemctl disable "service_name"

and follow-up with a check to see if the service is disabled with

systemctl status "service_name"

it still reveals the service to be enabled. I am currently running Centos7.

Any insight would be appreciated as to why I cannot disable the service. Thanks!

2

There are 2 answers

2
Raman On BEST ANSWER

Try the systemd mask command rather than disable:

systemctl mask <service_name>

The disable command still allows the service to be started, for example, in response to another service requesting it as a dependency (even if optional), or manually. However mask disables the service completely.

Also, I don't believe either mask or disable actually stop a running service: they just configure the startup of that service in the future. Therefore, you should also do systemctl stop <service_name>.

0
THESorcerer On
chmod -x <service exec>

or rename it

I just disabled the OpenVPN server like that. systemctl disable or systemctl mask didn't work. After a reboot, the service was still there (Ubuntu Server 22.04).

I know it is HIGHLY NOT an elegant solution, but it is the only one that works for sure.