Module Lwt_daemon


module Lwt_daemon: sig .. end
Daemon helpers

val daemonize : ?syslog:bool ->
?stdin:[ `Close | `Dev_null | `Keep ] ->
?stdout:[ `Close | `Dev_null | `Keep | `Log of Lwt_log.logger | `Log_default ] ->
?stderr:[ `Close | `Dev_null | `Keep | `Log of Lwt_log.logger | `Log_default ] ->
?directory:string -> ?umask:[ `Keep | `Set of int ] -> unit -> unit
Put the current running process into daemon mode. I.e. it forks and exit the parent, detach it from its controlling terminal, and redict standard intputs/outputs..

Notes:

If syslog is true (the default), then Lwt_log.default is set to Lwt_log.syslog ~facility:`Daemon (), otherwise it is kept unchanged.

stdin is one of:

stdout and stderr control how the two associated file descriptors are redirected: Both stdout and stderr defaults to `Log_default.

Warning: do not redirect an output to a logger logging into this outpout, for example this code will create an infinite loop:

        let logger = Lwt_log.channel ~close_mode:`Keep ~channel:Lwt_io.stderr () in
        Lwt_daemon.daemonize ~syslog:false ~stderr:(`Log logger) ();
        prerr_endline "foo"
      

The current working directory is set to directory, which defaults to "/".

umask may be one of:

It defaults to `Set 0o022.