MyNixOS website logo
Description

Daemons in Haskell made fun and easy.

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.

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

Metadata

Version

0.4.0

Executables (4)

Show all
  • bin/addone
  • bin/name
  • bin/queue
  • bin/memo

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows