LinuxCommandLibrary

systemctl-disable

Disable a systemd unit from starting automatically

TLDR

Stop a service from running on boot

$ systemctl disable [unit]
copy

Stop a service from running on boot and stop its current execution
$ systemctl disable [unit] --now
copy

SYNOPSIS

`systemctl disable [OPTIONS...] UNIT...`

PARAMETERS

--now
    Immediately stops the specified units in addition to disabling them. This option combines the effects of `disable` and `stop`.

--runtime
    Makes the change only for the current runtime, meaning it will not persist across a reboot. The symbolic links are created in `/run/systemd/system/` instead of `/etc/systemd/system/`.

--force
    Overrides specific checks. For `disable`, this can be used to remove links even if the unit is not explicitly recognized as being 'enabled' in the traditional sense, though its primary use is more common with `enable`.

--quiet
    Suppresses output messages during the operation, making the command execute silently.

--user
    Operates on the user systemd instance instead of the system-wide manager. This is used for managing user-specific services.

UNIT...
    One or more names of systemd units to be disabled (e.g., `apache2.service`, `network.target`).

DESCRIPTION

The `systemctl disable` command is used to prevent one or more systemd units, typically services, from starting automatically when the system boots. When a unit is disabled, systemd removes the symbolic links that connect the unit file (e.g., `my-service.service`) from the appropriate target's `.wants` or `.requires` directory (e.g., `/etc/systemd/system/multi-user.target.wants/`).

This action makes the change persistent across reboots. It's important to note that `systemctl disable` does not stop a service if it is currently running; it only affects its state for future boots. To stop a running service, you would use `systemctl stop`. To prevent a service from being started manually or automatically, the `systemctl mask` command is used, which creates a symbolic link to `/dev/null` for the unit file, making it impossible to start.

CAVEATS

Disabling a service only prevents it from auto-starting at boot. It does not stop a service that is currently running. You must use `systemctl stop UNIT` to halt a running service.

Also, `systemctl disable` is different from `systemctl mask`. While `disable` prevents auto-start, `mask` completely prevents a unit from being started, even manually, by linking its unit file to `/dev/null`.

STATIC UNITS

Some unit types, particularly `target` units or specific `mount` units, are considered 'static'. This means they do not have a traditional enable/disable mechanism because they are typically pulled in by other units or are fundamental to the system's operation. Attempting to `disable` a static unit may result in a message indicating it's static and cannot be disabled in the usual way.

DEPENDENCY MANAGEMENT

When you disable a unit, systemd removes its symlinks from `.wants` or `.requires` directories. This action primarily affects how that specific unit is brought up. However, if other units explicitly depend on the disabled unit using `Requires=` or `Wants=` directives in their own unit files, those units might still attempt to start it, or their startup behavior might be affected if the dependency is no longer met automatically. Always consider the dependency chain when disabling critical services.

HISTORY

The `systemctl` command is the primary control interface for systemd, the init system and service manager that has largely replaced older systems like SysVinit and Upstart in many Linux distributions. `systemd` was first introduced in Fedora in 2010 and adopted by many major distributions thereafter. The `disable` command, along with `enable`, `start`, and `stop`, is a fundamental part of `systemd`'s design for managing the lifecycle of services and other system units, providing a more structured and efficient way to handle system startup and runtime processes.

SEE ALSO

systemctl enable(1), systemctl start(1), systemctl stop(1), systemctl mask(1), systemctl status(1), systemctl is-enabled(1)

Copied to clipboard