MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / isRunningUnderSystemd

Function isRunningUnderSystemd

cmd/dash.go:3063–3087  ·  view source on GitHub ↗

isRunningUnderSystemd checks if the current process is running under systemd

()

Source from the content-addressed store, hash-verified

3061
3062// isRunningUnderSystemd checks if the current process is running under systemd
3063func isRunningUnderSystemd() bool {
3064 // Check if NOTIFY_SOCKET environment variable is set (systemd sets this)
3065 if os.Getenv("NOTIFY_SOCKET") != "" {
3066 return true
3067 }
3068
3069 // Check if we're running as PID 1's direct child and systemd is PID 1
3070 ppid := os.Getppid()
3071 if ppid == 1 {
3072 // Check if PID 1 is systemd
3073 if cmdline, err := os.ReadFile("/proc/1/cmdline"); err == nil {
3074 return strings.Contains(string(cmdline), "systemd")
3075 }
3076 }
3077
3078 // Check if systemd journal is available
3079 if _, err := os.Stat("/run/systemd/journal"); err == nil {
3080 // Also check if we have systemd process manager
3081 if _, err := os.Stat("/run/systemd/system"); err == nil {
3082 return true
3083 }
3084 }
3085
3086 return false
3087}
3088
3089// requestSystemdRestart attempts to restart the service via systemd
3090func requestSystemdRestart() error {

Callers 1

performUpdateWithRestartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected