From a82f845b84f68085fa64622fce321f510cf22acb Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Tue, 20 Jun 2023 23:49:23 -0400 Subject: [PATCH] add IsRunning helper --- helpers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/helpers.go b/helpers.go index 10a6c16..bb7aec9 100644 --- a/helpers.go +++ b/helpers.go @@ -97,3 +97,10 @@ func IsMasked(ctx context.Context, unit string, opts Options) (bool, error) { } return false, nil } + +// check if a service is running +// https://unix.stackexchange.com/a/396633 +func IsRunning(ctx context.Context, unit string, opts Options) (bool, error) { + status, err := Show(ctx, unit, properties.SubState, opts) + return status == "running", err +}