let debug_print s = if debug then prerr_endline s;;
Http_common.debug := false;;
let logfile = Some "uwobo.log";; (* relative to execution dir *)
-let logfile_perm = 0o644;;
+let logfile_perm = 0o640;;
(* other settings *)
let daemon_name = "UWOBO OCaml";;
let styles = new Uwobo_styles.styles in
(* (3) clean up actions *)
let last_process = ref true in
+ let http_child = ref None in
let die_nice () = (** at_exit callback *)
if !last_process then begin
+ (match !http_child with
+ | None -> ()
+ | Some pid -> Unix.kill pid Sys.sigterm);
syslogger#log `Notice (sprintf "%s is terminating, bye!" daemon_name);
syslogger#disable;
close_out logger_outchan
end
in
at_exit die_nice;
+ ignore (Sys.signal Sys.sigterm
+ (Sys.Signal_handle (fun _ -> raise Sys.Break)));
syslogger#log `Notice
(sprintf "%s started and listening on port %d" daemon_name port);
syslogger#log `Notice (sprintf "current directory is %s" (Sys.getcwd ()));
let (res_pipe_exit, res_pipe_entrance) = Unix.pipe () in
match Unix.fork () with
| child when child > 0 -> (* (4) parent: listen on cmd pipe for updates *)
+ http_child := Some child;
let stop_http_daemon () = (* kill child *)
debug_print (sprintf "Grandparent: killing pid %d" child);
Unix.kill child Sys.sigterm; (* kill child ... *)