Skip to content

Commit

Permalink
user friendly messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Apr 23, 2012
1 parent d01b8ff commit d59506a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions FileCGIApp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fileCgiApp cspec filespec cgispec revproxyspec um req = case mmp of
getBlock :: ByteString -> RouteDB -> Maybe [Route]
getBlock _ [] = Nothing
getBlock key (Block doms maps : ms)
| "*" `elem` doms = Just maps
| key `elem` doms = Just maps
| otherwise = getBlock key ms

Expand Down
17 changes: 13 additions & 4 deletions Mighty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ import System.IO
import System.Posix
import Types

errorFile :: FilePath
errorFile = "/tmp/mighty_error"

main :: IO ()
main = do
(opt,route) <- getOptRoute
if opt_debug_mode opt then
server opt route
else
else do
putStrLn $ "Detaching this terminal..." ++ errorFile
putStrLn $ "If any, errors can be found in \"" ++ errorFile ++ "\""
daemonize $ server opt route
where
getOptRoute = getArgs >>= eachCase
Expand All @@ -45,7 +50,7 @@ main = do
defaultOption
dir <- getCurrentDirectory
let dst = fromString . addTrailingPathSeparator $ dir
route = [Block ["localhost"] [RouteFile "/" dst]]
route = [Block ["*"] [RouteFile "/" dst]]
return (opt, route)
| n == 2 = do
opt <- parseOption $ args !! 0
Expand All @@ -63,7 +68,11 @@ main = do
server :: Option -> RouteDB -> IO ()
server opt route = handle handler $ do
s <- sOpen
unless debug writePidFile
if debug then do
putStrLn $ "Serving on port " ++ show port ++ "."
hFlush stdout
else
writePidFile
setGroupUser opt
logCheck logtype
if workers == 1 then do
Expand All @@ -86,7 +95,7 @@ server opt route = handle handler $ do
handler :: SomeException -> IO ()
handler e
| debug = hPrint stderr e
| otherwise = writeFile "/tmp/mighty_error" (show e)
| otherwise = writeFile errorFile (show e)
logspec = FileLogSpec {
log_file = opt_log_file opt
, log_file_size = fromIntegral $ opt_log_file_size opt
Expand Down

0 comments on commit d59506a

Please sign in to comment.