requestSystemdRestart attempts to restart the service via systemd
()
| 3088 | |
| 3089 | // requestSystemdRestart attempts to restart the service via systemd |
| 3090 | func 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 |
| 3120 | func getSystemdServiceName() string { |
no test coverage detected