hdaemonize: utilities for UNIX daemon writing

[ bsd3, library, system ] [ Propose Tags ]

Provides two functions that help writing better UNIX daemons, daemonize and serviced: daemonize does what a daemon should do (forking and closing descriptors), while serviced does that and more (syslog interface, PID file writing, start-stop-restart command line handling, dropping privileges).


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1, 0.2, 0.3, 0.4, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.4.1, 0.4.5.0, 0.5.0.0, 0.5.0.1, 0.5.0.2, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5.6, 0.5.7
Dependencies base, extensible-exceptions, haskell98, hsyslog, unix [details]
License BSD-3-Clause
Author Anton Tayanovskyy
Maintainer Anton Tayanovskyy <name.surname@gmail.com>
Category System
Home page http://github.com/toyvo/hdaemonize/tree/master
Uploaded by AntonTayanovskyy at 2009-03-14T13:05:30Z
Distributions LTSHaskell:0.5.7, NixOS:0.5.7, Stackage:0.5.7
Reverse Dependencies 3 direct, 5 indirect [details]
Downloads 17587 total (84 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hdaemonize-0.2

[back to package description]
`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.