From: David Scott Date: Fri, 18 Dec 2009 20:48:34 +0000 (+0000) Subject: CA-33440: Add [-daemon] and [-pidfile] arguments to the fork/exec daemon. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=4893168a8c83314bcfaa39249eb259daf7dee47b;p=xcp%2Fxen-api-libs.git CA-33440: Add [-daemon] and [-pidfile] arguments to the fork/exec daemon. This will make it easier to write an init.d script. Signed-off-by: David Scott --- diff --git a/forking_executioner/fe_main.ml b/forking_executioner/fe_main.ml index e93aab9..5a5f149 100644 --- a/forking_executioner/fe_main.ml +++ b/forking_executioner/fe_main.ml @@ -1,3 +1,7 @@ + +(** We write our PID here when we're ready to receive connections. *) +let default_pidfile = "/var/run/fe.pid" + open Fe_debug let setup sock cmdargs id_to_fd_map env = @@ -39,11 +43,26 @@ let setup sock cmdargs id_to_fd_map env = end let _ = - (* Unixext.daemonize ();*) + let pidfile = ref default_pidfile in + let daemonize = ref false in + + Arg.parse (Arg.align [ + "-daemon", Arg.Set daemonize, "Create a daemon"; + "-pidfile", Arg.Set_string pidfile, Printf.sprintf "Set the pid file (default \"%s\")" !pidfile; + ]) + (fun _ -> failwith "Invalid argument") + "Usage: fe [-daemon] [-pidfile filename]"; + + if !daemonize then Unixext.daemonize (); + Sys.set_signal Sys.sigpipe (Sys.Signal_ignore); let main_sock = Fecomms.open_unix_domain_sock_server "/var/xapi/forker/main" in + Unixext.pidfile_write !pidfile; + + (* At this point the init.d script should return and we are listening on our socket. *) + while true do try let (sock,addr) = Unix.accept main_sock in