packages feed

kibro-0.0: executable/Stop.hs

module Stop where

import Directory
import System.Process
import Control.Applicative

import Utils

stop :: [String] -> IO ()
stop _ = inKibro $ \dir name -> do stopFastCGI dir name
                                   stopLighty dir name

-- TODO: abstract this

stopLighty dir name = do
  exists <- doesFileExist pid
  if exists
     then do doing "Stopping lighttpd"
             id <- readFile pid
             -- TODO: make this compatible with windows
             runCommand $ "kill " ++ id
             return ()
     else return ()
      where pid = dir ./. "app" ./. "lighttpd" ./. "lighttpd.pid"  

stopFastCGI dir name = do
  exists <- doesFileExist pid
  if exists
     then do doing "Stopping fastcgi"
             id <- readFile pid
             -- TODO: make this compatible with windows
             runCommand $ "kill " ++ id
             deleteFile pid
             return ()
     else return ()
      where pid = dir ./. "app" ./. "fastcgi" ./. "fastcgi.pid"