How to stop a service using systemctl

Stopping a service with systemctl takes a daemon fully offline for maintenance, troubleshooting, or a controlled cutover instead of leaving it reachable while changes are still in progress. That matters when a process must stop accepting connections, stop writing data, or release a port before the next action can happen safely.

On a systemd host, systemctl stop unit.service asks the manager to run the unit's stop path and move its runtime state from active to inactive. That runtime state is separate from the unit-file state, so stopping a service does not enable or disable it for future boots. Current upstream behavior also treats a manual stop as an intentional shutdown, so a service that uses Restart=always does not immediately restart just because the command was issued.

Examples below use queue-worker.service as a stand-in unit name to keep the flow readable. Replace it with the real unit on the host, add sudo for system services, use systemctl --user stop for per-user units, and remember that some units can reject manual stops through RefuseManualStop=yes or return later if an active socket, timer, path, or dependent unit can trigger them again.

Steps to stop a service using systemctl:

  1. Open a terminal on the host that runs systemd with an account that can use sudo.

    Use systemctl --user stop unit.service instead when the target is a per-user service managed by the user instance of systemd.

  2. Check the current runtime state before stopping the unit.
    $ systemctl status --no-pager --full queue-worker.service
    ● queue-worker.service - Queue Worker Service
         Loaded: loaded (/etc/systemd/system/queue-worker.service; disabled; preset: enabled)
         Active: active (running) since Mon 2026-04-13 13:08:08 UTC; 22ms ago
       Main PID: 258 (sleep)
          Tasks: 1 (limit: 14335)
         Memory: 656.0K (peak: 1.0M)
            CPU: 13ms
    ##### snipped #####

    Replace queue-worker.service with the actual unit name, such as nginx.service, ssh.service, docker.service, or postgresql.service. The status view confirms that the service is running now and shows the loaded unit path before anything is changed.

  3. Confirm that the unit accepts manual stop requests when the service is policy-managed or generated by another tool.
    $ systemctl show -p CanStop -p RefuseManualStop queue-worker.service
    CanStop=yes
    RefuseManualStop=no

    CanStop=yes means the manager has a usable stop path for the unit. If RefuseManualStop=yes, current upstream systemctl behavior rejects a manual stop request even though the unit might still stop during dependency handling or system shutdown.

  4. Stop the service.
    $ sudo systemctl stop queue-worker.service

    Stopping a remote-access, proxy, database, or queue service can disconnect active clients immediately. Keep console or other out-of-band access available before stopping anything that could cut off the current session.

    Unless --no-block is used, systemctl waits for the queued stop job to finish before returning. A service stopped this way stays down even when the unit file uses Restart=always, because the manager treats the command as an intentional stop instead of a crash.

  5. Verify that the service is now inactive and that its boot-time state did not change.
    $ systemctl show -p ActiveState -p SubState -p UnitFileState queue-worker.service
    ActiveState=inactive
    SubState=dead
    UnitFileState=disabled

    stop changes the runtime state only. A unit can be inactive now while remaining enabled, disabled, or static for later boots.

  6. Read the recent unit journal when the stop takes too long, fails, or the service returns unexpectedly.
    $ sudo journalctl -u queue-worker.service -n 6 --no-pager
    Apr 13 13:05:36 server systemd[1]: Started queue-worker.service - Queue Worker Service.
    Apr 13 13:05:36 server bash[124]: queue-worker started
    Apr 13 13:06:01 server systemd[1]: Stopping queue-worker.service - Queue Worker Service...
    Apr 13 13:06:01 server bash[163]: queue-worker stopping
    Apr 13 13:06:01 server systemd[1]: queue-worker.service: Deactivated successfully.
    Apr 13 13:06:01 server systemd[1]: Stopped queue-worker.service - Queue Worker Service.

    journalctl -u shows whether the unit ran its stop commands cleanly, timed out, or had to be terminated forcefully. If the service comes back later, check for active socket, timer, path, or dependent units that can trigger it again.

  7. Stop an already inactive service safely in idempotent automation when the goal is simply to enforce a stopped state.
    $ sudo systemctl stop queue-worker.service
    
    $ systemctl is-active queue-worker.service
    inactive

    The current stop operation still exits successfully when the service is already inactive, which makes it safe in shell scripts and configuration management runs that should not fail on a no-op stop.