smp server: validate stats_save_interval

This commit is contained in:
sh committed 2026-10-26 07:30:22 +00:00
1 parent 31a3f0eba7
commit 3780c4af29
2 files changed
+15 -1

No files matched your search

+4 -1
View File
@@ -440,6 +440,9 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath =
transports = iniTransports ini
sharedHTTP = any (\(_, _, addHTTP) -> addHTTP) transports
iniStoreType = either error id $! readStoreType ini
iniStatsSaveInterval = case readIniDefault defStatsSaveInterval "STORE_LOG" "stats_save_interval" ini of
n | n < 1 -> error $ "invalid INI setting stats_save_interval: " <> show n
n -> n
iniStoreCfg :: SupportedStore qs ms => SQSType qs -> SMSType ms -> ServerStoreCfg (MsgStoreType qs ms)
iniStoreCfg SQSMemory SMSMemory = SSCMemory $ enableStoreLog' ini $> StorePaths {storeLogFile = storeLogFilePath, storeMsgsFile = restoreMessagesFile storeMsgsFilePath}
#if defined(dbServerPostgres)
@@ -495,7 +498,7 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath =
logStatsStartTime = 0, -- seconds from 00:00 UTC
serverStatsLogFile = combine logPath "smp-server-stats.daily.log",
serverStatsBackupFile = logStats $> combine logPath "smp-server-stats.log",
statsSaveInterval = readIniDefault defStatsSaveInterval "STORE_LOG" "stats_save_interval" ini,
statsSaveInterval = iniStatsSaveInterval,
prometheusInterval = eitherToMaybe (lookupValue "STORE_LOG" "prometheus_interval" ini) >>= readMaybe . T.unpack,
prometheusMetricsFile = combine logPath "smp-server-metrics.txt",
pendingENDInterval = 15000000, -- 15 seconds
+11
View File
@@ -86,6 +86,7 @@ cliTests = do
it "with store log, no password" $ smpServerTest True False
it "static files" smpServerTestStatic
it "cloud scripts disable embedded web without certificates" smpCloudScriptsDisableWeb
it "should not start with invalid stats_save_interval" smpServerInvalidStatsSaveInterval
#if defined(dbServerPostgres)
around_ (postgressBracket ntfTestServerDBConnectInfo) $ before_ (createNtfSchema ntfTestServerDBConnectInfo ntfTestServerDBOpts) $
describe "Ntf server CLI" $ do
@@ -204,6 +205,16 @@ smpServerTestStatic = do
let X.CertificateChain cc = tlsPeerCert tls
in map (X.signedObject . X.getSigned) cc
smpServerInvalidStatsSaveInterval :: HasTestEnv => IO ()
smpServerInvalidStatsSaveInterval = do
let iniFile = cfgPath <> "/smp-server.ini"
capture_ (withArgs ["init", "-y", "--no-password"] $ smpServerCLI cfgPath logPath)
>>= (`shouldSatisfy` (("Server initialized, please provide additional server information in " <> iniFile) `isPrefixOf`))
Right ini <- readIniFile iniFile
writeIniFile iniFile ini {iniSections = HM.adjust (("stats_save_interval", "0") :) "STORE_LOG" (iniSections ini)}
capture_ (withArgs ["start"] $ 5000000 `timeout` smpServerCLI cfgPath logPath)
`shouldThrow` errorCall "invalid INI setting stats_save_interval: 0"
smpCloudScriptsDisableWeb :: HasCallStack => IO ()
smpCloudScriptsDisableWeb = do
linode <- readFile "scripts/smp-server-linode.sh"