diff --git a/.env.example b/.env.example index 17141464..223eef68 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # ------------------------------ # Log path -LOG_PATH=/tmp +LOG_PATH=/tmp/astra # Graph designer server port GRAPH_DESIGNER_SERVER_PORT=49483 # Server port diff --git a/server/main.go b/server/main.go index 442e6506..d590b89d 100644 --- a/server/main.go +++ b/server/main.go @@ -20,6 +20,15 @@ func main() { slog.Warn("load .env file failed", "err", err) } + // Check if the directory exists + logPath := os.Getenv("LOG_PATH") + if _, err := os.Stat(logPath); os.IsNotExist(err) { + if err := os.MkdirAll(logPath, os.ModePerm); err != nil { + slog.Error("create log directory failed", "err", err) + os.Exit(1) + } + } + // Check environment agoraAppId := os.Getenv("AGORA_APP_ID") if len(agoraAppId) != 32 { @@ -49,7 +58,7 @@ func main() { httpServerConfig := &internal.HttpServerConfig{ AppId: agoraAppId, AppCertificate: os.Getenv("AGORA_APP_CERTIFICATE"), - LogPath: os.Getenv("LOG_PATH"), + LogPath: logPath, Port: os.Getenv("SERVER_PORT"), WorkersMax: workersMax, WorkerQuitTimeoutSeconds: workerQuitTimeoutSeconds,