daemons: Daemons in Haskell made fun and easy

[ control, gpl, library, network, program, system ] [ Propose Tags ]

Control.Pipe.C3 provides simple RPC-like wrappers for pipes.

Control.Pipe.Serialize provides serialization and incremental deserialization pipes.

Control.Pipe.Socket provides functions to setup pipes around sockets.

System.Daemon provides a high-level interface to starting daemonized programs that are controlled through sockets.

System.Posix.Daemon provides a low-level interface to starting, and controlling detached jobs.

See the README.md file and the homepage for details.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.2.1, 0.3.0, 0.4.0
Change log NEWS.md
Dependencies base (>=4 && <5), bytestring, cereal, containers, daemons, data-default, directory, filepath, ghc-prim, network, pipes (>=4.0.0), transformers, unix [details]
License GPL-3.0-only
Author Alexandru Scvortov <scvalex@gmail.com>
Maintainer scvalex@gmail.com
Category System, Control, Network
Home page https://github.com/scvalex/daemons
Source repo head: git clone git://github.com/scvalex/daemons.git
Uploaded by AlexandruScvortov at 2013-09-15T16:32:02Z
Distributions NixOS:0.4.0
Reverse Dependencies 3 direct, 0 indirect [details]
Executables name, queue, addone, memo
Downloads 6503 total (24 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 daemons-0.2.0

[back to package description]

daemons

Daemons in Haskell made fun and easy

Example

Here's AddOne, a simple daemon that waits for a number and responds with the incremented number.

import Data.Default ( def )
import System.Environment ( getArgs )
import System.Daemon

addOne :: Int -> IO Int
addOne n = return (n + 1)

main :: IO ()
main = do
    ensureDaemonRunning "addOne" def addOne
    [n] <- getArgs
    res <- runClient "localhost" 5000 ((read n) :: Int)
    print (res :: Maybe Int)

Running it, we see:

% addone 22
Daemon started on port 5000
Just 23
% addone 41
Just 42

The two important functions above are ensureDaemonRunning, which checks if a daemon named addOne is already running, and starts it if not, and runClient which connects to the daemon running on localhost:5000, passes it a number, and waits for the response.

What would I use this for?

  • You can use the runDetached from System.Posix.Daemon to turn your program into a daemon for Unix-like systems. You'd want to do this for practically every program that's meant to run as a server.

  • You can use the functions from Control.Pipe.C3, Socket, and Serialize to communicate with running Haskell program. At the simplest, you could query the program for its status, or instruct it to shutdown cleanly. A more complex use would be adding a full REPL into a running Haskell process (think erl -remsh).

  • You can use the helpers from System.Daemon to trivially do the above. Check out the following tutorials and examples for details.

Tutorials and examples

  • Memo - in which we write an in-memory key-value store,

  • Queue

    • a task queue using the streaming interface of daemons.

Installation

This package is on Hackage. To install it, run:

cabal update
cabal install daemons

Modules

  • Control.Pipe.C3 provides simple RPC-like wrappers for pipes.

  • Control.Pipe.Serialize provides pipes to serialize and deserialize streams of strict ByteStrings using cereal.

  • Control.Pipe.Socket provides functions to setup strict ByteString pipes around sockets.

  • System.Daemon provides a high-level interface to starting daemonized programs that are controlled through sockets.

  • System.Posix.Daemon provides a low-level interface to starting, and controlling detached jobs.

See also