Revision 9a0b8258
b/src/Ganeti/Daemon.hs | ||
---|---|---|
38 | 38 |
, oPort |
39 | 39 |
, oBindAddress |
40 | 40 |
, oSyslogUsage |
41 |
, oForceNode |
|
41 | 42 |
, parseArgs |
42 | 43 |
, parseAddress |
43 | 44 |
, cleanupSocket |
... | ... | |
99 | 100 |
, optNoUserChecks :: Bool -- ^ Ignore user checks |
100 | 101 |
, optBindAddress :: Maybe String -- ^ Override for the bind address |
101 | 102 |
, optSyslogUsage :: Maybe SyslogUsage -- ^ Override for Syslog usage |
103 |
, optForceNode :: Bool -- ^ Ignore node checks |
|
102 | 104 |
} |
103 | 105 |
|
104 | 106 |
-- | Default values for the command line options. |
... | ... | |
113 | 115 |
, optNoUserChecks = False |
114 | 116 |
, optBindAddress = Nothing |
115 | 117 |
, optSyslogUsage = Nothing |
118 |
, optForceNode = False |
|
116 | 119 |
} |
117 | 120 |
|
118 | 121 |
instance StandardOptions DaemonOptions where |
... | ... | |
185 | 188 |
"]"), |
186 | 189 |
OptComplChoices ["yes", "no", "only"]) |
187 | 190 |
|
191 |
oForceNode :: OptType |
|
192 |
oForceNode = |
|
193 |
(Option "" ["force-node"] |
|
194 |
(NoArg (\ opts -> Ok opts { optForceNode = True })) |
|
195 |
"Force the daemon to run on a different node than the master", |
|
196 |
OptComplNone) |
|
197 |
|
|
188 | 198 |
-- | Generic options. |
189 | 199 |
genericOpts :: [OptType] |
190 | 200 |
genericOpts = [ oShowHelp |
... | ... | |
328 | 338 |
|
329 | 339 |
-- | Ensures that the daemon runs on the right node (and exits |
330 | 340 |
-- gracefully if it doesnt) |
331 |
ensureNode :: GanetiDaemon -> IO () |
|
332 |
ensureNode daemon = do |
|
341 |
ensureNode :: GanetiDaemon -> DaemonOptions -> IO ()
|
|
342 |
ensureNode daemon opts = do
|
|
333 | 343 |
is_master <- isMaster |
334 |
when (daemonOnlyOnMaster daemon && not is_master) $ do |
|
344 |
when (daemonOnlyOnMaster daemon |
|
345 |
&& not is_master |
|
346 |
&& not (optForceNode opts)) $ do |
|
335 | 347 |
putStrLn "Not master, exiting." |
336 | 348 |
exitWith (ExitFailure C.exitNotmaster) |
337 | 349 |
|
... | ... | |
389 | 401 |
hPutStrLn stderr $ |
390 | 402 |
printf C.debugModeConfidentialityWarning (daemonName daemon) |
391 | 403 |
|
392 |
ensureNode daemon |
|
404 |
ensureNode daemon opts
|
|
393 | 405 |
|
394 | 406 |
exitUnless (null args) "This program doesn't take any arguments" |
395 | 407 |
|
Also available in: Unified diff