-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
67 lines (57 loc) · 1.75 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env runhaskell
{-# OPTIONS -Wall -fno-warn-unused-do-bind #-}
import Control.Monad
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import System.Process
import System.Directory
main :: IO ()
main = defaultMainWithHooks simpleUserHooks { runTests = tests }
tests :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO ()
tests args _ _ _ = do
case args of
["nginx",x] -> nginx x
["fastcgi",x] -> fastcgi x
a -> badarg a
nginx :: String -> IO ()
nginx "start" = npid not $ do
system "nginx -p`pwd`/httpd/ -cnginx.conf"
nginx "stop" = npid id $ do
system $ "kill `cat " ++ ngpath ++ "`"
nginx "restart" = do
nginx "stop"
nginx "clean"
nginx "start"
nginx "clean" = npid id $ do
system $ "rm " ++ ngpath ++ ""
nginx a = badarg a
fastcgi :: String -> IO ()
fastcgi "start" = fpid not $ do
system $ "spawn-fcgi dist/build/amelie.fcgi/amelie.fcgi -p 9001 -P " ++ fppath
fastcgi "stop" = fpid id $ do
system $ "kill `cat " ++ fppath ++ "`"
fastcgi "clean"
fastcgi "refresh" = do
system "cabal build && cabal test fastcgi restart"
return ()
fastcgi "restart" = do
system "cabal test fastcgi stop; cabal test fastcgi clean; cabal test fastcgi start"
return ()
fastcgi "clean" = fpid id $ do
system $ "rm " ++ fppath
fastcgi a = badarg a
npid :: (Bool -> Bool) -> IO a -> IO ()
npid = pid ngpath
fpid :: (Bool -> Bool) -> IO a -> IO ()
fpid = pid fppath
fppath :: FilePath
fppath = "httpd/fastcgi.pid"
ngpath :: FilePath
ngpath = "httpd/nginx.pid"
pid :: FilePath -> (Bool -> Bool) -> IO a -> IO ()
pid path p m = do
e <- doesFileExist path
when (p e) $ do m; return ()
badarg :: Show a => a -> IO ()
badarg a = error $ "invalid argument(s): " ++ show a