Git Product home page Git Product logo

hdaemonize's Introduction

`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.3
    * merged with updates by madhadron

* 0.2
    * provided documentation
    * backported to older GHC versions, tested on 6.8.1

* 0.1
    * initial public release


Authors
-------

Anton Tayanovskyy <[email protected]>, bug reports and feature
requests welcome.

The code is originally based on a public posting by
[Andre Nathan](http://sneakymustard.com/), used by permission.

hdaemonize's People

Contributors

t0yv0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

madhadron

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.