When managing services on a Debian system, you may from time to time come across the following error:
Failed to stop unit: Unit foo.service not loaded.
This article explains what the error means and how to solve it.
What Does the Error Mean?
Whenever the Debian system tries to manage a service, such as stopping a service with the systemctl stop foo.service
command, it throws the error “Failed to stop unit: Unit foo.service not loaded” when the service hasn’t been previously installed or enabled.
How Do I Fix It?
The easiest way to solve this error is to first check the status of the service. To do this, use the command systemctl status foo.service
. In this case, you should see a message like the one below:
foo.service – Foo Service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
The meaning of the message is that the foo.service
service is not loaded, and therefore it is inactive and “dead”.
Enable and Start the Service
To make the service active, you must first enable it. To do that, use the command systemctl enable foo.service
. This will create the symbolic links required for managing the foo.service
service.
Once enabled, you can start the service with the command systemctl start foo.service
. This should output a message saying the service has been successfully started. Now you can check the status of the service using the command systemctl status foo.service
, and you should see an output like the one below:
foo.service – Foo Service
Loaded: loaded (/usr/lib/systemd/system/foo.service; enabled; vendor preset: enabled)
Active: active (running) since [date]
This means that the service has been loaded and is running normally.
Conclusion
This article has explained the error “Failed to stop unit: Unit foo.service not loaded” and how to solve it on a Debian system. To summarise, you should first check the status of a service to ensure it has been loaded, enabled, and started correctly. If a service has failed to start, you should enable it with the command systemctl enable foo.service
and then start it with the command systemctl start foo.service
. Once the service is started, you should always check its status with the command systemctl status foo.service
to make sure it is running normally.