2024-09-04 01:20:12 +09:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io/fs"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
systemdCheckPath = "/run/systemd/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SdBooted implements https://www.freedesktop.org/software/systemd/man/sd_booted.html
|
2024-09-12 20:53:33 +09:00
|
|
|
func SdBooted() (bool, error) {
|
2024-09-04 01:20:12 +09:00
|
|
|
_, err := os.Stat(systemdCheckPath)
|
|
|
|
if err != nil {
|
2024-09-12 20:53:33 +09:00
|
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
|
|
err = nil
|
2024-09-04 01:20:12 +09:00
|
|
|
}
|
2024-09-12 20:53:33 +09:00
|
|
|
return false, err
|
2024-09-04 01:20:12 +09:00
|
|
|
}
|
2024-09-12 20:53:33 +09:00
|
|
|
|
|
|
|
return true, nil
|
2024-09-04 01:20:12 +09:00
|
|
|
}
|