extra-hosts

This commit is contained in:
Michael Snoyman 2012-10-12 12:17:00 +02:00
parent e0fa8d7bac
commit a16f532880
2 changed files with 9 additions and 0 deletions

View File

@ -31,6 +31,8 @@ import System.IO (hClose)
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
import Data.Conduit (($$), yield, runResourceT) import Data.Conduit (($$), yield, runResourceT)
import Data.Conduit.Binary (sinkFile) import Data.Conduit.Binary (sinkFile)
import Data.Set (Set)
import qualified Data.Set as Set
data Config = Config data Config = Config
{ configExec :: F.FilePath { configExec :: F.FilePath
@ -38,6 +40,7 @@ data Config = Config
, configHost :: String , configHost :: String
, configPostgres :: Bool , configPostgres :: Bool
, configSsl :: Bool , configSsl :: Bool
, configExtraHosts :: Set String
} }
instance FromJSON Config where instance FromJSON Config where
@ -47,6 +50,7 @@ instance FromJSON Config where
<*> o .: "host" <*> o .: "host"
<*> o .:? "postgres" .!= False <*> o .:? "postgres" .!= False
<*> o .:? "ssl" .!= False <*> o .:? "ssl" .!= False
<*> o .:? "extra-hosts" .!= Set.empty
parseJSON _ = fail "Wanted an object" parseJSON _ = fail "Wanted an object"
data Command = Reload | Terminate data Command = Reload | Terminate
@ -151,6 +155,7 @@ start tf portman postgres logger appname bundle removeFromList = do
if b if b
then do then do
addEntry portman (configHost config) port addEntry portman (configHost config) port
mapM_ (flip (addEntry portman) port) $ Set.toList $ configExtraHosts config
loop chan dir process port config loop chan dir process port config
else do else do
removeFromList removeFromList
@ -163,6 +168,7 @@ start tf portman postgres logger appname bundle removeFromList = do
Terminate -> do Terminate -> do
removeFromList removeFromList
removeEntry portman $ configHost configOld removeEntry portman $ configHost configOld
mapM_ (removeEntry portman) $ Set.toList $ configExtraHosts configOld
log $ TerminatingApp appname log $ TerminatingApp appname
terminateOld terminateOld
detach logger detach logger
@ -182,6 +188,7 @@ start tf portman postgres logger appname bundle removeFromList = do
if b if b
then do then do
addEntry portman (configHost config) port addEntry portman (configHost config) port
mapM_ (flip (addEntry portman) port) $ Set.toList $ configExtraHosts config
when (configHost config /= configHost configOld) $ when (configHost config /= configHost configOld) $
removeEntry portman $ configHost configOld removeEntry portman $ configHost configOld
log $ FinishedReloading appname log $ FinishedReloading appname

View File

@ -2,3 +2,5 @@ exec: ../hello
args: args:
- Hello World 1 - Hello World 1
host: tealc-mint host: tealc-mint
extra-hosts:
- pong