From 4eb3b8e11388d094f4920481ff90413c7e5aa940 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Sat, 26 Aug 2023 17:54:26 +0300 Subject: [PATCH] server: add env lookups for smp server paths (#817) * Add env lookups for smp server paths Allows running smp-server without touching system paths. Can be helpful for running multiple instances. * allow empty env var values * diff * fix --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- apps/smp-server/Main.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/smp-server/Main.hs b/apps/smp-server/Main.hs index 07dbc51d1..14738c154 100644 --- a/apps/smp-server/Main.hs +++ b/apps/smp-server/Main.hs @@ -1,13 +1,17 @@ +{-# LANGUAGE LambdaCase #-} + module Main where import Control.Logger.Simple +import Data.Maybe import Simplex.Messaging.Server.Main +import System.Environment -cfgPath :: FilePath -cfgPath = "/etc/opt/simplex" +defaultCfgPath :: FilePath +defaultCfgPath = "/etc/opt/simplex" -logPath :: FilePath -logPath = "/var/opt/simplex" +defaultLogPath :: FilePath +defaultLogPath = "/var/opt/simplex" logCfg :: LogConfig logCfg = LogConfig {lc_file = Nothing, lc_stderr = True} @@ -15,4 +19,9 @@ logCfg = LogConfig {lc_file = Nothing, lc_stderr = True} main :: IO () main = do setLogLevel LogDebug + cfgPath <- getEnvPath "SMP_SERVER_CFG_PATH" defaultCfgPath + logPath <- getEnvPath "SMP_SERVER_LOG_PATH" defaultLogPath withGlobalLogging logCfg $ smpServerCLI cfgPath logPath + +getEnvPath :: String -> FilePath -> IO FilePath +getEnvPath name def = maybe def (\case "" -> def; f -> f) <$> lookupEnv name