2025-01-07 16:01:49 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-01-08 19:29:05 +01:00
|
|
|
"os"
|
2025-01-10 16:57:23 +01:00
|
|
|
"fmt"
|
2025-01-09 17:58:51 +01:00
|
|
|
"os/exec"
|
2025-01-07 16:01:49 +01:00
|
|
|
|
|
|
|
"git.keyzox.me/42_adjoly/inception/internal/env"
|
|
|
|
)
|
|
|
|
|
2025-01-09 17:58:51 +01:00
|
|
|
func checkMariaDB(user, password, host, port string) bool {
|
|
|
|
// Create the command to run mariadb client
|
|
|
|
cmd := exec.Command("mariadb", "-u"+user, "-p"+password, "-h"+host, "-P"+port, "-e", "SELECT 1;")
|
|
|
|
|
|
|
|
// Run the command
|
|
|
|
err := cmd.Run()
|
2025-01-07 16:01:49 +01:00
|
|
|
if err != nil {
|
2025-01-09 17:58:51 +01:00
|
|
|
fmt.Printf("Health check failed: %v\n", err)
|
2025-01-09 17:29:36 +01:00
|
|
|
return false
|
2025-01-07 16:01:49 +01:00
|
|
|
}
|
2025-02-07 18:00:30 +01:00
|
|
|
fmt.Println("Maria DB is healthy")
|
2025-01-07 16:01:49 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2025-01-09 17:58:51 +01:00
|
|
|
func main() {
|
|
|
|
// Configuration
|
2025-01-10 16:57:23 +01:00
|
|
|
user := env.EscapeEnv(env.FileEnv("MYSQL_USER", "mariadb"))
|
|
|
|
password := env.EscapeEnv(env.FileEnv("MYSQL_PASSWORD", "default"))
|
2025-01-09 17:58:51 +01:00
|
|
|
host := "127.0.0.1"
|
|
|
|
port := "3306"
|
|
|
|
|
2025-01-09 18:05:41 +01:00
|
|
|
if checkMariaDB(user, password, host, port) {
|
|
|
|
os.Exit(0) // Success
|
2025-01-07 16:01:49 +01:00
|
|
|
}
|
2025-01-09 17:29:36 +01:00
|
|
|
|
2025-01-09 17:58:51 +01:00
|
|
|
fmt.Println("MariaDB health check failed")
|
|
|
|
os.Exit(1) // Failure
|
2025-01-07 16:01:49 +01:00
|
|
|
}
|