feat: add notify scripts for state transitions
Some checks failed
Release / Build darwin-amd64 (push) Has been cancelled
Release / Build linux-amd64 (push) Has been cancelled
Release / Build darwin-arm64 (push) Has been cancelled
Release / Build linux-arm64 (push) Has been cancelled
Release / Create Release (push) Has been cancelled

- Add notify_master/notify_backup/notify_fault support
- Support both file path and inline shell script
- Async execution with 60s timeout
- Inject GO_ALIVED_INSTANCE and GO_ALIVED_EVENT env vars
- Bump version to 1.3.0

🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
loveuer
2026-03-05 06:02:01 -08:00
parent 22e13c9c0d
commit 3fc3c860bc
3 changed files with 112 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ import (
)
// Version can be set at build time via ldflags
var Version = "1.2.1"
var Version = "1.3.0"
var rootCmd = &cobra.Command{
Use: "go-alived",

View File

@@ -58,6 +58,7 @@ func runService(cmd *cobra.Command, args []string) {
os.Exit(1)
}
setupNotifyScripts(vrrpMgr, cfg, log)
setupHealthTracking(vrrpMgr, healthMgr, log)
healthMgr.StartAll()
@@ -100,6 +101,27 @@ func cleanup(log *logger.Logger, vrrpMgr *vrrp.Manager, healthMgr *health.Manage
vrrpMgr.StopAll()
}
func setupNotifyScripts(vrrpMgr *vrrp.Manager, cfg *config.Config, log *logger.Logger) {
for _, vrrpCfg := range cfg.VRRP {
if vrrpCfg.NotifyMaster == "" && vrrpCfg.NotifyBackup == "" && vrrpCfg.NotifyFault == "" {
continue
}
inst, ok := vrrpMgr.GetInstance(vrrpCfg.Name)
if !ok {
continue
}
vrrp.SetupNotify(inst, &vrrp.NotifyConfig{
Name: vrrpCfg.Name,
NotifyMaster: vrrpCfg.NotifyMaster,
NotifyBackup: vrrpCfg.NotifyBackup,
NotifyFault: vrrpCfg.NotifyFault,
Log: log,
})
}
}
func setupHealthTracking(vrrpMgr *vrrp.Manager, healthMgr *health.Manager, log *logger.Logger) {
instances := vrrpMgr.GetAllInstances()