Yes, you can start a service even if is-disabled returns true. Being disabled means the service is not set to start automatically at boot, but it can still be started manually. Here’s how to handle this:
Example Command
You can check if the service is disabled and then start it:
SERVICE_NAME="example-service"
if systemctl is-enabled --quiet $SERVICE_NAME; then
echo "$SERVICE_NAME is enabled. No action needed."
else
echo "$SERVICE_NAME is disabled. Starting the service..."
systemctl start $SERVICE_NAME
fi
Key Points:
systemctl is-enabled:
- Returns
disabledif the service is not set to start automatically at boot.
systemctl start:
- Starts the service immediately regardless of its enabled/disabled status.
One-Liner Command
To directly check and start the service if it’s disabled:
! systemctl is-enabled --quiet example-service && systemctl start example-service
Explanation:
! systemctl is-enabled: Checks if the service is not enabled (disabled).&& systemctl start: Starts the service if the first condition is true.
Notes:
- A service being disabled does not mean it cannot be started. It simply means it won’t start automatically on system boot.
- After starting the service, if you want it to start automatically on future boots, you can enable it using:
systemctl enable example-service