]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
CA-33440: Add [-daemon] and [-pidfile] arguments to the fork/exec daemon.
authorDavid Scott <dave.scott@eu.citrix.com>
Fri, 18 Dec 2009 20:48:34 +0000 (20:48 +0000)
committerDavid Scott <dave.scott@eu.citrix.com>
Fri, 18 Dec 2009 20:48:34 +0000 (20:48 +0000)
This will make it easier to write an init.d script.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
forking_executioner/fe_main.ml

index e93aab941bf8faf658b74f87fe684ec57dab4584..5a5f14941004b7fba5c928026aa3814363924626 100644 (file)
@@ -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