package main
import (
"fmt"
"os/exec"
"time"
)
// the function is like Supervisor()
// check clickhouse service alive status
// if it is not alive, wake up it
// if it is alive, do nothing;
// this coding need deploy on clickhouse server
func main() {
for {
// Check if the ClickHouse process is alive
cmd := exec.Command("pgrep", "clickhouse")
if err := cmd.Run(); err != nil {
// If the ClickHouse process is not alive, start it
startCmd := exec.Command("clickhouse", "start")
if err := startCmd.Run(); err != nil {
panic(err)
}
fmt.Println("ClickHouse process started")
} else {
fmt.Println("ClickHouse process is already running")
}
// Wait for 1 minute before testing again
time.Sleep(1 * time.Minute)
}
}
golang实现clickhouse守护进程
最新推荐文章于 2023-10-20 12:19:03 发布