module HAppS.Server.Helpers
( smartserver
) where
import HAppS.Server
import HAppS.State
import System.Environment
import Control.Concurrent
import System.Time
import HAppS.Server.CookieFixer
-- run the happs server on some port
-- include cookie fix, various other enhancements that make things simpler
smartserver :: (Methods st, Component st, ToMessage a) =>
Conf -> String -> [ServerPartT IO a] -> Proxy st -> IO ()
smartserver conf progName c stateProxy = withProgName progName $ do
putStrLn . ( "starting happs server" ++ ) =<< time
control <- startSystemState stateProxy -- start the HAppS state system
putStrLn . ( "happs state started" ++ ) =<< time
tid <- forkIO $ simpleHTTP conf ( map cookieFixer c)
putStrLn . ( ( "simpleHttp started on port " ++ (show . port $ conf) ++ "\n" ++
"shut down with ctrl-c" ) ++) =<< time
waitForTermination
killThread tid
putStrLn . ( "creating checkpoint: " ++ ) =<< time
createCheckpoint control
putStrLn . ( "shutting down system: " ++ ) =<< time
shutdownSystem control
putStrLn . ( "exiting: " ++ ) =<< time
where time = return . ("\ntime: " ++ ) . show =<< getClockTime