From cb5860a98029772bfe3af081239fa2eb13075a32 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Mon, 16 Feb 2004 18:16:58 +0000 Subject: [PATCH] Ported to Helm_registry. --- helm/uwobo/Makefile | 2 +- helm/uwobo/uwobo.conf.xml.sample | 14 ++++ helm/uwobo/uwobo.ml | 134 +++++++++++++++---------------- 3 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 helm/uwobo/uwobo.conf.xml.sample diff --git a/helm/uwobo/Makefile b/helm/uwobo/Makefile index c2a97d7c5..9cec0e488 100644 --- a/helm/uwobo/Makefile +++ b/helm/uwobo/Makefile @@ -1,7 +1,7 @@ VERSION = 0.2.1 DISTDIR = uwobo-$(VERSION) DISTTARBALL = $(DISTDIR).tar.gz -REQUIRES = http gdome2 gdome2-xslt pcre unix +REQUIRES = http gdome2 gdome2-xslt pcre unix helm-registry COMMONOPTS = -package "$(REQUIRES)" -pp camlp4o OCAMLFIND = ocamlfind OCAMLC = $(OCAMLFIND) ocamlc $(COMMONOPTS) diff --git a/helm/uwobo/uwobo.conf.xml.sample b/helm/uwobo/uwobo.conf.xml.sample new file mode 100644 index 000000000..d138ee105 --- /dev/null +++ b/helm/uwobo/uwobo.conf.xml.sample @@ -0,0 +1,14 @@ + + +
+ /projects/helm/shared/V7_mowgli + /tmp/helm/cache +
+ +
+ /var/log/mowgli/uwobo + .log + + 58080 +
+
diff --git a/helm/uwobo/uwobo.ml b/helm/uwobo/uwobo.ml index a9755885d..d680f9e28 100644 --- a/helm/uwobo/uwobo.ml +++ b/helm/uwobo/uwobo.ml @@ -35,13 +35,15 @@ let debug_level = `Notice ;; let debug_print s = if debug then prerr_endline s ;; Http_common.debug := false ;; + + (* First of all we load the configuration *) +let _ = + let configuration_file = "/projects/helm/etc/uwobo.conf.xml" in + Helm_registry.load_from configuration_file +;; + (* other settings *) let daemon_name = "UWOBO OCaml" ;; -let default_log_base_file = "log/uwobo" ;; (* relative to execution dir *) -let log_extension = ".log" ;; -let default_port = 58080 ;; -let port_env_var = "UWOBO_PORT" ;; -let log_env_var = "UWOBO_LOG_FILE" ;; (* The extension _pid.log will be added *) let default_media_type = "text/html" ;; let default_encoding = "utf8" ;; @@ -59,24 +61,14 @@ let get_encoding props = Not_found -> default_encoding ;; -let port = - try - int_of_string (Sys.getenv port_env_var) - with - | Not_found -> default_port - | Failure "int_of_string" -> - prerr_endline "Warning: invalid port number" ; - exit (-1) -;; +let port = Helm_registry.get_int "uwobo.port";; + let logfilename_of_port port = - let basename = - try - Sys.getenv log_env_var - with - Not_found -> default_log_base_file - in - basename ^ "_" ^ string_of_int port ^ log_extension + let basename = Helm_registry.get "uwobo.log_basename" in + let extension = Helm_registry.get "uwobo.log_extension" in + basename ^ "_" ^ string_of_int port ^ extension ;; + let logfile = logfilename_of_port port;; let logfile_perm = 0o640 ;; @@ -216,55 +208,57 @@ let veillogger = new Uwobo_common.libXsltLogger ;; (* It can raise Failure "Connection refused" *) (* It can raise Failure "Port already in use" *) let start_new_session cmd_pipe res_pipe outchan port logfile = - let environment = - (* Here I am loosing the current value of port_env_var; *) - (* this should not matter *) - Unix.putenv port_env_var (string_of_int port) ; - Unix.environment () - in - (* Let's check that the port is free *) - (try - ignore - (Http_client.http_get - ("http://127.0.0.1:" ^ string_of_int port ^ "/help")) ; - raise (Failure "Port already in use") - with - Unix.Unix_error (Unix.ECONNREFUSED, _, _) -> () - ) ; - match Unix.fork () with - 0 -> - Unix.handle_unix_error - (function () -> - (* 1. We close all the open pipes to avoid duplicating them *) - Unix.close (Unix.descr_of_out_channel cmd_pipe) ; - Unix.close (Unix.descr_of_in_channel res_pipe) ; - Unix.close (Unix.descr_of_out_channel outchan) ; - (* 2. We redirect stdout and stderr to the logfile *) - Unix.close Unix.stdout ; - assert - (Unix.openfile logfile [Unix.O_WRONLY ; Unix.O_APPEND ; Unix.O_CREAT] - 0o664 = Unix.stdout) ; - Unix.close Unix.stderr ; - assert - (Unix.openfile logfile [Unix.O_WRONLY ; Unix.O_APPEND ; Unix.O_CREAT] - 0o664 = Unix.stderr) ; - prerr_endline "***** Starting a new session" ; - (* 3. We exec a new copy of uwobo *) - Unix.execve Sys.executable_name [||] environment ; - (* It should never reach this point *) - assert false - ) () - | child when child > 0 -> - (* let's check if the new UWOBO started correctly *) - Unix.sleep 5 ; - (* It can raise Failure "Connection refused" *) - (try - ignore - (Http_client.http_get - ("http://127.0.0.1:" ^ string_of_int port ^ "/help")) - with Unix.Unix_error (Unix.ECONNREFUSED, _, _) -> - raise (Failure "Connection refused")) - | _ -> failwith "Can't fork :-(" + (* Let's check that the port is free *) + (try + ignore + (Http_client.http_get + ("http://127.0.0.1:" ^ string_of_int port ^ "/help")) ; + raise (Failure "Port already in use") + with + Unix.Unix_error (Unix.ECONNREFUSED, _, _) -> () + ) ; + match Unix.fork () with + 0 -> + Unix.handle_unix_error + (function () -> + (* 1. We close all the open pipes to avoid duplicating them *) + Unix.close (Unix.descr_of_out_channel cmd_pipe) ; + Unix.close (Unix.descr_of_in_channel res_pipe) ; + Unix.close (Unix.descr_of_out_channel outchan) ; + (* 2. We redirect stdout and stderr to the logfile *) + Unix.close Unix.stdout ; + assert + (Unix.openfile logfile [Unix.O_WRONLY ; Unix.O_APPEND ; Unix.O_CREAT] + 0o664 = Unix.stdout) ; + Unix.close Unix.stderr ; + assert + (Unix.openfile logfile [Unix.O_WRONLY ; Unix.O_APPEND ; Unix.O_CREAT] + 0o664 = Unix.stderr) ; + prerr_endline "***** Starting a new session" ; + + (* 3. We set up a new environment *) + let environment = + (* Here I am loosing the current value of port_env_var; *) + (* this should not matter *) + Unix.putenv "UWOBO__PORT" (string_of_int port) ; + Unix.environment () + in + (* 4. We exec a new copy of uwobo *) + Unix.execve Sys.executable_name [||] environment ; + (* It should never reach this point *) + assert false + ) () + | child when child > 0 -> + (* let's check if the new UWOBO started correctly *) + Unix.sleep 5 ; + (* It can raise Failure "Connection refused" *) + (try + ignore + (Http_client.http_get + ("http://127.0.0.1:" ^ string_of_int port ^ "/help")) + with Unix.Unix_error (Unix.ECONNREFUSED, _, _) -> + raise (Failure "Connection refused")) + | _ -> failwith "Can't fork :-(" ;; (* request handler action -- 2.39.2