2020-09-20 16:46:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
2020-10-18 15:22:24 +00:00
|
|
|
"time"
|
2020-09-20 16:46:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func preStartHooks() {
|
|
|
|
for _, cmd := range appConfig.Hooks.PreStart {
|
|
|
|
log.Println("Executing pre-start hook:", cmd)
|
|
|
|
executeCommand(cmd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:22:24 +00:00
|
|
|
func startHourlyHooks() {
|
|
|
|
for _, cmd := range appConfig.Hooks.Hourly {
|
|
|
|
go func(cmd string) {
|
|
|
|
run := func() {
|
|
|
|
log.Println("Executing hourly hook:", cmd)
|
|
|
|
executeCommand(cmd)
|
|
|
|
}
|
|
|
|
// Execute once
|
|
|
|
run()
|
|
|
|
// Start ticker and execute regularly
|
|
|
|
ticker := time.NewTicker(1 * time.Hour)
|
|
|
|
for range ticker.C {
|
|
|
|
run()
|
|
|
|
}
|
|
|
|
}(cmd)
|
2020-09-20 16:46:25 +00:00
|
|
|
}
|
2020-10-18 15:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func executeCommand(cmd string) {
|
|
|
|
out, err := exec.Command(appConfig.Hooks.Shell, "-c", cmd).CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Failed to execute command:", err.Error())
|
2020-09-20 16:46:25 +00:00
|
|
|
}
|
2020-10-18 15:22:24 +00:00
|
|
|
log.Println("Output:")
|
|
|
|
log.Print(string(out))
|
2020-09-20 16:46:25 +00:00
|
|
|
}
|