Skip to content

Commit

Permalink
Supervise cron process for better logging/signal handling/environment…
Browse files Browse the repository at this point in the history
… management.
  • Loading branch information
ndarilek committed Jun 20, 2024
1 parent 6b1cc60 commit d5c08ce
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {
}

svisor := supervisor.New("flybarman", 1*time.Minute)
svisor.AddProcess("cron", "/usr/sbin/cron -f", supervisor.WithRestart(0, 5*time.Second))
svisor.AddProcess("barman", fmt.Sprintf("tail -f %s", node.LogFile))
svisor.AddProcess("admin", "/usr/local/bin/start_admin_server",
supervisor.WithRestart(0, 5*time.Second),
Expand Down
13 changes: 1 addition & 12 deletions internal/flybarman/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ wal_retention_policy = main
}

if _, err := os.Stat(n.BarmanCronFile); os.IsNotExist(err) {
barmanCronFileContent := `* * * * * /usr/bin/barman cron
barmanCronFileContent := `* * * * * . $HOME/.profile; /usr/bin/barman cron >> /proc/1/fd/1 2>/proc/1/fd/2
`
if err := os.WriteFile(n.BarmanCronFile, []byte(barmanCronFileContent), 0644); err != nil {
return fmt.Errorf("failed write %s: %s", n.BarmanCronFile, err)
Expand All @@ -167,17 +167,6 @@ wal_retention_policy = main

log.Println("Crontab updated")

serviceCmd := exec.Command("/usr/sbin/service", "--version")
if err := serviceCmd.Run(); err != nil {
log.Println("service command not found, skipping initializing cron service")
} else {
serviceCronStartCommand := exec.Command("service", "cron", "start")
if _, err := serviceCronStartCommand.Output(); err != nil {
return fmt.Errorf("failed starting cron service: %s", err)
}
log.Println("Started cron service")
}

switchWalCommand := exec.Command("barman", "switch-wal", "--archive", "--force", "pg")
if _, err := switchWalCommand.Output(); err != nil {
log.Println(fmt.Errorf("failed switching WAL: %s", err))
Expand Down

0 comments on commit d5c08ce

Please sign in to comment.