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

Function requestSystemdRestart

cmd/dash.go:3090–3117  ·  view source on GitHub ↗

requestSystemdRestart attempts to restart the service via systemd

()

Source from the content-addressed store, hash-verified

3088
3089// requestSystemdRestart attempts to restart the service via systemd
3090func requestSystemdRestart() error {
3091 // Instead of trying to run systemctl (which requires sudo), we'll just exit gracefully
3092 // and let systemd restart us automatically (assuming Restart=always or Restart=on-failure)
3093 //
3094 // NOTE: Your systemd service file should have one of these restart policies:
3095 // Restart=always - Always restart the service when it exits
3096 // Restart=on-failure - Restart only on non-zero exit codes
3097 // Restart=on-success - Restart only on zero exit codes
3098 //
3099 // Example systemd service file:
3100 // [Service]
3101 // Type=simple
3102 // Restart=always
3103 // RestartSec=5
3104 // ExecStart=/usr/local/bin/cronitor dash
3105
3106 // Try to determine the service name for logging purposes
3107 serviceName := getSystemdServiceName()
3108 if serviceName != "" {
3109 log(fmt.Sprintf("Exiting to trigger systemd restart of service: %s", serviceName))
3110 } else {
3111 log("Exiting to trigger systemd restart")
3112 }
3113
3114 // Exit with success code to trigger systemd restart
3115 // Most systemd services are configured with Restart=always or Restart=on-failure
3116 return nil
3117}
3118
3119// getSystemdServiceName attempts to determine the systemd service name
3120func getSystemdServiceName() string {

Callers 1

performUpdateWithRestartFunction · 0.85

Calls 2

getSystemdServiceNameFunction · 0.85
logFunction · 0.85

Tested by

no test coverage detected