From afad75cdd3a3b9a4b17f4fc25645bca7cecf5a16 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 21 Feb 2012 13:42:28 +0000 Subject: [PATCH] Implement 'whenjobs --daemon-stop' --- daemon/daemon.ml | 19 +++++++++++++++++-- lib/whenproto.x | 1 + tools/whenjobs.ml | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/daemon/daemon.ml b/daemon/daemon.ml index eca0218..347aff7 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -45,6 +45,9 @@ let jobsdir = ref "" (* Was debugging requested on the command line? *) let debug = ref false +(* The server. *) +let server = ref None + let esys = Unixqueue.standard_event_system () let timer_group = ref None @@ -58,12 +61,13 @@ let rec init j d = let addr = sprintf "%s/socket" !jobsdir in (try unlink addr with Unix_error _ -> ()); - ignore ( + server := Some ( Whenproto_srv.When.V1.create_server ~proc_reload_file ~proc_set_variable ~proc_get_variable ~proc_get_variable_names + ~proc_exit_daemon (Rpc_server.Unix addr) Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *) Rpc.Socket @@ -104,6 +108,17 @@ and proc_get_variable_names () = Array.sort compare vars; vars +and proc_exit_daemon () = + if !debug then Syslog.notice "remote call: exit_daemon"; + + match !server with + | None -> + `error "exit_daemon: no server handle" + | Some s -> + Rpc_server.stop_server ~graceful:true s; + server := None; + `ok + (* Reload the jobs file. *) and reload_file () = let file = sprintf "%s/jobs.cmo" !jobsdir in @@ -250,7 +265,7 @@ and schedule_next_everyjob () = let w = Unixqueue.new_wait_id esys in let t_diff = t -. Unix.time () in let t_diff = if t_diff < 0. then 0. else t_diff in - Unixqueue.add_resource esys g (Unixqueue.Wait w, t_diff); + Unixqueue.add_weak_resource esys g (Unixqueue.Wait w, t_diff); let run_jobs _ _ _ = List.iter run_job jobs; delete_timer (); diff --git a/lib/whenproto.x b/lib/whenproto.x index faa120d..58d3ca2 100644 --- a/lib/whenproto.x +++ b/lib/whenproto.x @@ -68,5 +68,6 @@ program When { void set_variable (variable_name, variable) = 2; variable get_variable (variable_name) = 3; variable_name_list get_variable_names (void) = 4; + status exit_daemon (void) = 5; } = 1; } = 0x20008081; diff --git a/tools/whenjobs.ml b/tools/whenjobs.ml index dade6c2..0810649 100644 --- a/tools/whenjobs.ml +++ b/tools/whenjobs.ml @@ -319,7 +319,15 @@ and daemon_start () = assert false and daemon_stop () = - assert false + let client = start_client () in + (match Whenproto_clnt.When.V1.exit_daemon client () with + | `ok -> () + | `error msg -> + eprintf "whenjobs: daemon-stop: %s\n" msg; + suggest_check_server_logs (); + exit 1 + ); + stop_client client and daemon_restart () = assert false -- 1.8.3.1