mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-23 14:06:18 +01:00
write health_file to /dev/shm instead of /tmp if available (#1455)
This commit is contained in:
@@ -9,11 +9,31 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// healthFile is the path to the health file
|
// healthFile is the path to the health file
|
||||||
var healthFile = filepath.Join(os.TempDir(), "beszel_health")
|
var healthFile = getHealthFilePath()
|
||||||
|
|
||||||
|
func getHealthFilePath() string {
|
||||||
|
filename := "beszel_health"
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
|
fullPath := filepath.Join("/dev/shm", filename)
|
||||||
|
if err := updateHealthFile(fullPath); err == nil {
|
||||||
|
return fullPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filepath.Join(os.TempDir(), filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateHealthFile(path string) error {
|
||||||
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
// Check checks if the agent is connected by checking the modification time of the health file
|
// Check checks if the agent is connected by checking the modification time of the health file
|
||||||
func Check() error {
|
func Check() error {
|
||||||
@@ -30,11 +50,7 @@ func Check() error {
|
|||||||
|
|
||||||
// Update updates the modification time of the health file
|
// Update updates the modification time of the health file
|
||||||
func Update() error {
|
func Update() error {
|
||||||
file, err := os.Create(healthFile)
|
return updateHealthFile(healthFile)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return file.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanUp removes the health file
|
// CleanUp removes the health file
|
||||||
|
|||||||
Reference in New Issue
Block a user