Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bin/barman_cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Identify the process id of the cron supervisor process
cron_pid=$(pgrep -f '/usr/sbin/cron')
if [ -z "$cron_pid" ]; then
# Send the error message to main process's stderr
echo "Failed to resolve cron process id" >> /proc/1/fd/2
exit 1
fi

barman_output=$(barman cron 2>&1)
barman_exit_code=$?

# Log the result of barman cron
if [ $barman_exit_code -ne 0 ]; then
echo "Barman cron failed with exit code $barman_exit_code: $barman_output" >> /proc/$cron_pid/fd/2
exit 1
fi
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
22 changes: 4 additions & 18 deletions internal/flybarman/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,12 @@ wal_retention_policy = main
return fmt.Errorf("failed to write file %s: %s", n.RootPasswordConfigPath, err)
}

if _, err := os.Stat(n.BarmanCronFile); os.IsNotExist(err) {
barmanCronFileContent := `* * * * * /usr/bin/barman cron
barmanCronFileContent := `* * * * * /usr/local/bin/barman_cron
`
if err := os.WriteFile(n.BarmanCronFile, []byte(barmanCronFileContent), 0644); err != nil {
return fmt.Errorf("failed write %s: %s", n.BarmanCronFile, err)
}

log.Println(n.BarmanCronFile + " created successfully.")
if err := os.WriteFile(n.BarmanCronFile, []byte(barmanCronFileContent), 0644); err != nil {
return fmt.Errorf("failed write %s: %s", n.BarmanCronFile, err)
}
log.Println(n.BarmanCronFile + " created successfully.")

if _, err := os.Stat(n.LogFile); os.IsNotExist(err) {
file, err := os.Create(n.LogFile)
Expand All @@ -167,17 +164,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