(* 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
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
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
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 ();
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;
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