Systemctl has an is-active subcommand which is useful in scripts that need to check the status of a service
From the systemctl docs:
Check whether any of the specified units are active (i.e. running). Returns an exit code 0 if at least one is active, or non-zero otherwise. Unless --quiet is specified, this will also print the current unit state to standard output.
On Wed, 15 Feb 2023 18:41:53 +0000 "~aren" outgoing@sr.ht wrote:
Systemctl has an is-active subcommand which is useful in scripts that need to check the status of a service
I think this would be really helpful, thanks for the suggestion!
From the systemctl docs:
Check whether any of the specified units are active (i.e. running). Returns an exit code 0 if at least one is active, or non-zero otherwise. Unless --quiet is specified, this will also print the current unit state to standard output.
If I understand that correctly, it should do something like this?
$ superctl is-active foo stopped $ echo $? 1 $ superctl start foo $ superctl is-active --quiet foo $ echo $? 0
Correct
I'm not sure if it makes any difference but it looks like systemd prints "inactive" instead of stopped, and returns 3. There's an exit status table in the man page that describes it, if it is useful to match those.