Skip to content
Snippets Groups Projects
Commit b714ff89 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add command line option for controlling syslog use


… and enable it in hconfd.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent a6e2a138
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,7 @@ module Ganeti.Daemon ...@@ -34,6 +34,7 @@ module Ganeti.Daemon
, oDebug , oDebug
, oPort , oPort
, oBindAddress , oBindAddress
, oSyslogUsage
, parseArgs , parseArgs
, parseAddress , parseAddress
, writePidFile , writePidFile
...@@ -75,6 +76,7 @@ data DaemonOptions = DaemonOptions ...@@ -75,6 +76,7 @@ data DaemonOptions = DaemonOptions
, optDebug :: Bool -- ^ Enable debug messages , optDebug :: Bool -- ^ Enable debug messages
, optNoUserChecks :: Bool -- ^ Ignore user checks , optNoUserChecks :: Bool -- ^ Ignore user checks
, optBindAddress :: Maybe String -- ^ Override for the bind address , optBindAddress :: Maybe String -- ^ Override for the bind address
, optSyslogUsage :: Maybe SyslogUsage -- ^ Override for Syslog usage
} }
-- | Default values for the command line options. -- | Default values for the command line options.
...@@ -87,6 +89,7 @@ defaultOptions = DaemonOptions ...@@ -87,6 +89,7 @@ defaultOptions = DaemonOptions
, optDebug = False , optDebug = False
, optNoUserChecks = False , optNoUserChecks = False
, optBindAddress = Nothing , optBindAddress = Nothing
, optSyslogUsage = Nothing
} }
-- | Abrreviation for the option type. -- | Abrreviation for the option type.
...@@ -142,6 +145,15 @@ oBindAddress = Option "b" ["bind"] ...@@ -142,6 +145,15 @@ oBindAddress = Option "b" ["bind"]
"ADDR") "ADDR")
"Bind address (default depends on cluster configuration)" "Bind address (default depends on cluster configuration)"
oSyslogUsage :: OptType
oSyslogUsage = Option "" ["syslog"]
(reqWithConversion syslogUsageFromRaw
(\su opts -> Ok opts { optSyslogUsage = Just su })
"SYSLOG")
("Enable logging to syslog (except debug \
\messages); one of 'no', 'yes' or 'only' [" ++ C.syslogUsage ++
"]")
-- | Usage info. -- | Usage info.
usageHelp :: String -> [OptType] -> String usageHelp :: String -> [OptType] -> String
usageHelp progname = usageHelp progname =
...@@ -291,16 +303,21 @@ genericMain daemon options main = do ...@@ -291,16 +303,21 @@ genericMain daemon options main = do
exitWith $ ExitFailure C.exitFailure exitWith $ ExitFailure C.exitFailure
Ok ents -> verifyDaemonUser daemon ents Ok ents -> verifyDaemonUser daemon ents
syslog <- case optSyslogUsage opts of
Nothing -> exitIfBad $
annotateResult "Invalid cluster syslog setting" $
syslogUsageFromRaw C.syslogUsage
Just v -> return v
let processFn = if optDaemonize opts then daemonize else id let processFn = if optDaemonize opts then daemonize else id
processFn $ innerMain daemon opts (main opts) processFn $ innerMain daemon opts syslog (main opts)
-- | Inner daemon function. -- | Inner daemon function.
-- --
-- This is executed after daemonization. -- This is executed after daemonization.
innerMain :: GanetiDaemon -> DaemonOptions -> IO () -> IO () innerMain :: GanetiDaemon -> DaemonOptions -> SyslogUsage -> IO () -> IO ()
innerMain daemon opts main = do innerMain daemon opts syslog main = do
setupLogging (daemonLogFile daemon) (daemonName daemon) (optDebug opts) setupLogging (daemonLogFile daemon) (daemonName daemon) (optDebug opts)
(not (optDaemonize opts)) False SyslogNo (not (optDaemonize opts)) False syslog
pid_fd <- writePidFile (daemonPidFile daemon) pid_fd <- writePidFile (daemonPidFile daemon)
case pid_fd of case pid_fd of
Bad msg -> do Bad msg -> do
......
...@@ -40,6 +40,7 @@ options = ...@@ -40,6 +40,7 @@ options =
, oDebug , oDebug
, oPort C.defaultConfdPort , oPort C.defaultConfdPort
, oBindAddress , oBindAddress
, oSyslogUsage
] ]
-- | Main function. -- | Main function.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment