angel 0.4.2 → 0.4.3
raw patch · 3 files changed
+70/−2 lines, 3 filesdep ~basedep ~process
Dependency ranges changed: base, process
Files
- Angel/PidFile.hs +52/−0
- README.md +4/−0
- angel.cabal +14/−2
+ Angel/PidFile.hs view
@@ -0,0 +1,52 @@+module Angel.PidFile ( startMaybeWithPidFile+ , startWithPidFile+ , clearPIDFile) where++import Control.Applicative ( (<$>)+ , (<*>) )+import Control.Exception.Base ( catch+ , finally+ , SomeException)+import Control.Monad (when)+import System.Process ( CreateProcess+ , createProcess+ , ProcessHandle )++-- Wish I didn't have to do this :(+import System.Process.Internals ( PHANDLE+ , ProcessHandle__(..)+ , withProcessHandle+ )+import System.Posix.Files ( removeLink+ , fileExist)++startMaybeWithPidFile :: CreateProcess -> Maybe FilePath -> (ProcessHandle -> IO a) -> IO a+startMaybeWithPidFile procSpec (Just pidFile) = startWithPidFile procSpec pidFile+startMaybeWithPidFile procSpec Nothing = withPHandle procSpec++startWithPidFile :: CreateProcess -> FilePath -> (ProcessHandle -> IO a) -> IO a+startWithPidFile procSpec pidFile action = do+ withPHandle procSpec $ \pHandle -> do+ mPid <- getPID pHandle+ maybe (return ()) write mPid+ action pHandle `finally` clearPIDFile pidFile+ where write = writePID pidFile++withPHandle :: CreateProcess -> (ProcessHandle -> IO a) -> IO a+withPHandle procSpec action = do+ (_, _, _, pHandle) <- createProcess procSpec+ action pHandle++writePID :: FilePath -> PHANDLE -> IO ()+writePID pidFile = writeFile pidFile . show++clearPIDFile :: FilePath -> IO ()+clearPIDFile pidFile = do ex <- fileExist pidFile+ when ex rm+ where exists = fileExist pidFile+ rm = removeLink pidFile++getPID :: ProcessHandle -> IO (Maybe PHANDLE)+getPID pHandle = withProcessHandle pHandle getPID'+ where getPID' h @ (OpenHandle t) = return (h, Just t)+ getPID' h @ (ClosedHandle t) = return (h, Nothing)
README.md view
@@ -260,6 +260,10 @@ CHANGELOG ---------+### 0.4.3++* Fix install failure from pidfile module not being accounted for.+ ### 0.4.2 * Add `pidfile` option to program spec to specify a pidfile location.
angel.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.4.2+Version: 0.4.3 -- A short (one-line) description of the package. -- Synopsis: @@ -89,6 +89,7 @@ Angel.Job, Angel.Log, Angel.Util+ Angel.PidFile -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source. -- Build-tools: @@ -103,5 +104,16 @@ Hs-Source-Dirs: ., test Build-Depends: base Build-Depends: hspec- Build-depends: time+ Build-depends: base >= 4.0 && < 5+ Build-depends: process >= 1.0 && < 2.0+ Build-depends: mtl+ Build-depends: MissingH+ Build-depends: configurator >= 0.1+ Build-depends: stm >= 2.0+ Build-depends: containers >= 0.3+ Build-depends: unordered-containers >= 0.1.4+ Build-depends: unix >= 2.4+ Build-depends: time+ Build-depends: old-locale+ Build-depends: text>=0.11 Extensions: OverloadedStrings,ScopedTypeVariables,BangPatterns,ViewPatterns