When I do systemctl stop service
on a stopped or failed service, it returns 0 and no output. I need to know whether it was running before I call this.
Calling systemctl status
before stopping is not an option: it increases running time and introduces race conditions. Both reasons are important in my case.
stop
stops a service andstatus
would tell you "whether it was running". Are you looking for a "stop only if it's already running" command? Or do you want "stop" to return different exit codes if the service was running and was successfully stopped? (In which case this may turn into a feature request of systemd)stop
to tell me what it has really done. A special exit code would be the best solution. Although a message in the output is acceptable too.