hdaemonize 0.1 → 0.2
raw patch · 3 files changed
+94/−7 lines, 3 filesdep +extensible-exceptionsPVP ok
version bump matches the API change (PVP)
Dependencies added: extensible-exceptions
API changes (from Hackage documentation)
Files
- README +85/−0
- System/Posix/Daemonize.hs +5/−4
- hdaemonize.cabal +4/−3
+ README view
@@ -0,0 +1,85 @@+`hdaemonize-0.2`+=================++`hdaemonize` is a simple library that hides some of the complexities+of writing UNIX daemons in Haskell. ++Obtaining+-----------++The latest version is available (BSD license) at+[GitHub](http://github.com/toyvo/hdaemonize/tree/master). ++Using+-------++The synopsis is:++ import System.Posix.Daemonize+ main = daemonize $ program++This code will make `program` do what good daemons should do, that is,+detach from the terminal, close file descriptors, create a new process+group, and so on.++If you want more functionality than that, it is available as a+`serviced` function.++Here is an example:++ import Control.Concurrent+ import System.Posix.Daemonize++ loop i log = do threadDelay $ 10^6+ log (show i)+ writeFile "/tmp/counter" $ show i+ if i == 5 then undefined else loop (i + 1) log++ main = serviced (loop 0)++Let us say this program is compiled as `mydaemon`. Then:++ # mydaemon start++starts the service. A second call to start will complain that the+program is already running. ++During its execution, mydaemon will simply write a new number to+`/tmp/counter` every second, until it reaches 5. Then, an exception+will be thrown. This exception will be caught by `hdaemonize`, and+logged to `/var/log/daemon.log` or similar (this is depends on how+`syslog` works on your platorm). `log (show i)` will leave messages+in the same file.++When the exception is thrown, the program will be restared in 5+seconds, and will start counting from 0 again.++The following commands are also made available:++ # mydaemon stop+ # mydaemon restart+ +Finally, `mydaemon` drops privileges. By default it changes the+effective user and group ids to those of the `daemon` user, but it+prefers to use those of `mydaemon`, if present.+++Changelog+---------++* 0.2+ * provided documentation+ * backported to older GHC versions, tested on 6.8.1++* 0.1+ * initial public release+++Authors+-------++Anton Tayanovskyy <name.surname@gmail.com>, bug reports and feature+requests welcome.++The code is originally based on a public posting by+[Andre Nathan](http://sneakymustard.com/), used by permission.
System/Posix/Daemonize.hs view
@@ -3,8 +3,9 @@ {- originally based on code from http://sneakymustard.com/2008/12/11/haskell-daemons -} + import Control.Concurrent-import Control.Exception+import Control.Exception.Extensible import Prelude hiding (catch) import System import System.Exit@@ -30,13 +31,13 @@ do setFileCreationMask 0 forkProcess p- exitSuccess+ exitImmediately ExitSuccess where p = do createSession forkProcess p'- exitSuccess+ exitImmediately ExitSuccess p' = do changeWorkingDirectory "/" closeFileDescriptors@@ -80,7 +81,7 @@ process name ["start"] = pidExists name >>= f where f True = do error "PID file exists. Process already running?"- exitFailure+ exitImmediately (ExitFailure 1) f False = daemonize (program' name) process name ["stop"] =
hdaemonize.cabal view
@@ -1,6 +1,6 @@ Name: hdaemonize-Version: 0.1-Cabal-Version: >= 1.2+Version: 0.2+Cabal-Version: >= 1.6 License: BSD3 License-file: LICENSE Author: Anton Tayanovskyy@@ -14,8 +14,9 @@ more (syslog interface, PID file writing, start-stop-restart command line handling, dropping privileges). Build-Type: Simple+Extra-Source-Files: README Library- Build-Depends: base, unix, haskell98, hsyslog+ Build-Depends: base, unix, haskell98, hsyslog, extensible-exceptions Exposed-modules: System.Posix.Daemonize