mirror of
https://github.com/taigrr/systemctl.git
synced 2026-03-09 00:14:38 -07:00
add IsSystemd checker
This commit is contained in:
10
helpers.go
10
helpers.go
@@ -3,6 +3,7 @@ package systemctl
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -112,6 +113,15 @@ func GetMaskedUnits(ctx context.Context, opts Options) ([]string, error) {
|
|||||||
return units, nil
|
return units, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if systemd is the current init system
|
||||||
|
func IsSystemd() (bool, error) {
|
||||||
|
b, err := os.ReadFile("/proc/1/comm")
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(b)) == "systemd", nil
|
||||||
|
}
|
||||||
|
|
||||||
// check if a service is masked
|
// check if a service is masked
|
||||||
func IsMasked(ctx context.Context, unit string, opts Options) (bool, error) {
|
func IsMasked(ctx context.Context, unit string, opts Options) (bool, error) {
|
||||||
units, err := GetMaskedUnits(ctx, opts)
|
units, err := GetMaskedUnits(ctx, opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user