Skip to content

Commit

Permalink
Merge pull request #238 from ocsigen/config
Browse files Browse the repository at this point in the history
Using Ocsigen Server without configuration file (and with static linking)
  • Loading branch information
balat authored Aug 28, 2024
2 parents 2433a6d + 50bf9e4 commit 05a57ed
Show file tree
Hide file tree
Showing 47 changed files with 1,280 additions and 820 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.26.1
version=0.26.2
break-cases = fit
break-collection-expressions = fit-or-vertical
break-fun-decl = wrap
Expand Down
11 changes: 2 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include Makefile.options
include Makefile.config
include Makefile.options

### Building

.PHONY: default all
.PHONY: default all doc
default all: build

.PHONY: build
Expand Down Expand Up @@ -74,13 +74,6 @@ install.files:
@echo
@echo "## Run \"make doc\" and \"make install.doc\" to build and install the ocamldoc."
@echo INSTALL_CAN_PUT_PERMISSIONS: ${INSTALL_CAN_PUT_PERMISSIONS}
## Command pipe
$(INSTALL) -m ${INSTALL_MOD_755} -d $(dir $(TEMPROOT)$(COMMANDPIPE))
[ -p $(TEMPROOT)$(COMMANDPIPE) ] || \
{ mkfifo -m ${INSTALL_MOD_660} $(TEMPROOT)$(COMMANDPIPE); \
if [ "${INSTALL_CAN_PUT_PERMISSIONS}" = yes ]; \
then $(CHOWN) -R $(OCSIGENUSER):"$(OCSIGENGROUP)" $(TEMPROOT)$(COMMANDPIPE); \
fi; }
## Configuration files
$(INSTALL) -m ${INSTALL_MOD_755} -d $(TEMPROOT)$(CONFIGDIR)/conf.d
${INSTALL} -m ${INSTALL_MOD_644} ocsigenserver.conf.sample $(TEMPROOT)$(CONFIGDIR)/
Expand Down
2 changes: 1 addition & 1 deletion Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ INCS= -I ${BLD}/server/.ocsigenserver.objs/byte \
## ${SERVER_PACKAGE} is not only used to build the 'ocsigenserver' executable
## but also to generate src/baselib/ocsigen_config_static.ml

SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,lwt_log,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix,hmap
SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,lwt_log,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix

LIBS := -package ${SERVER_PACKAGE} ${INCS}

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.2
6.0.0
16 changes: 12 additions & 4 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DOC := baselib/ocsigen_cache.mli \
http/ocsigen_header.mli \
\
server/ocsigen_config.mli \
server/ocsigen_command.mli \
server/ocsigen_request.mli \
server/ocsigen_response.mli \
server/ocsigen_messages.mli \
Expand All @@ -26,10 +27,17 @@ DOC := baselib/ocsigen_cache.mli \
server/ocsigen_local_files.mli \
server/ocsigen_server.mli

PLUGINS_DOC := extensions/accesscontrol.mli extensions/authbasic.mli \
extensions/outputfilter.mli \
extensions/redirectmod.mli extensions/staticmod.mli \
extensions/deflatemod/deflatemod.mli
PLUGINS_DOC := extensions/accesscontrol.mli \
extensions/authbasic.mli \
extensions/outputfilter.mli \
extensions/extendconfiguration.mli \
extensions/redirectmod.mli \
extensions/rewritemod.mli \
extensions/userconf.mli \
extensions/revproxy.mli \
extensions/staticmod.mli \
extensions/deflatemod.mli \
extensions/cors.mli

all: doc wikidoc

Expand Down
21 changes: 18 additions & 3 deletions doc/indexdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
{1 Ocsigen server - API reference}
{!modules:
Ocsigen_server
}
{2 Extensions}
{!modules:
Staticmod
Extendconfiguration
Accesscontrol
Authbasic
Deflatemod
Redirectmod
Revproxy
Rewritemod
Outputfilter
Userconf
Cors
}

{2 Persistent data, writing in the logs, configuration file extension, polymorphic tables}
{!modules:
Expand All @@ -14,10 +31,8 @@ Ocsigen_config
{!modules:
Ocsigen_extensions
Ocsigen_local_files
Ocsigen_headers
Ocsigen_header
Ocsigen_stream
Ocsigen_comet
Authbasic
}

{2 Indexes}
Expand Down
3 changes: 1 addition & 2 deletions ocsigenserver.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "ocsigenserver"
version: "5.1.2"
version: "6.0.0"
maintainer: "[email protected]"
synopsis: "A full-featured and extensible Web server"
description: "Ocsigen Server implements most features of the HTTP protocol, and has a very powerful extension mechanism that makes it very easy to plug your own OCaml modules for generating pages. Many extensions are already implemented, like a reverse proxy, content compression, access control, authentication, etc."
Expand Down Expand Up @@ -59,7 +59,6 @@ depends: [
"ipaddr" {>= "2.1"}
"cohttp-lwt-unix" {>= "5.0.0" & < "6.0.0~"}
"conduit-lwt-unix" {>= "2.0.0"}
"hmap"
"xml-light"
"camlzip"
]
Expand Down
4 changes: 0 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ confs: ../ocsigenserver.conf.sample ../local/etc/ocsigenserver.conf
cat $< \
| sed s%_LOGDIR_%$(LOGDIR)%g \
| sed s%_DATADIR_%$(DATADIR)%g \
| sed s%_OCSIGENUSER_%$(OCSIGENUSER)%g \
| sed s%_OCSIGENGROUP_%"$(OCSIGENGROUP)"%g \
| sed s%_COMMANDPIPE_%$(COMMANDPIPE)%g \
| sed s%_MIMEFILE_%$(CONFIGDIR)/mime.types%g \
| sed s%_METADIR_%$(LIBDIR)%g \
Expand All @@ -30,8 +28,6 @@ confs: ../ocsigenserver.conf.sample ../local/etc/ocsigenserver.conf
| sed s%80\</port\>%8080\</port\>%g \
| sed s%_LOGDIR_%$(SRC)/local/var/log%g \
| sed s%_DATADIR_%$(SRC)/local/var/lib%g \
| sed s%\<user\>_OCSIGENUSER_\</user\>%%g \
| sed s%\<group\>_OCSIGENGROUP_\</group\>%%g \
| sed s%_COMMANDPIPE_%$(SRC)/local/var/run/ocsigenserver_command%g \
| sed s%_MIMEFILE_%$(SRC)/src/files/mime.types%g \
| sed s%_METADIR_%${LIBDIR}\"/\>\<findlib\ path=\"$(SRC)/src/files/\"/\>\<findlib\ path=\"$(SRC)/src/extensions/files/%g \
Expand Down
2 changes: 0 additions & 2 deletions src/baselib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ ocsigen_config_static.ml: ocsigen_config_static.ml.in ../../Makefile.config ../.
| sed s%_EXTDIR_%$(LIBDIR)/ocsigenserver/extensions%g \
| sed s%_STATICPAGESDIR_%$(STATICPAGESDIR)% \
| sed s%_UP_%$(UPLOADDIR)%g \
| sed s%_OCSIGENUSER_%$(OCSIGENUSER)%g \
| sed s%_OCSIGENGROUP_%"$(OCSIGENGROUP)"%g \
| sed s%_COMMANDPIPE_%$(COMMANDPIPE)%g \
| sed s%_CONFIGDIR_%$(CONFIGDIR)% \
| sed s%_ISNATIVE_%$(NATIVECODE_RUNTIME_DETECT)%g \
Expand Down
2 changes: 0 additions & 2 deletions src/baselib/ocsigen_config_static.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ let version_number = "_VERSION_"
let config_file = ref "_CONFIGDIR_/ocsigenserver.conf"
let is_native = Sys.backend_type = Sys.Native
let logdir = ref (Some "_LOGDIR_")
let default_user = ref "_OCSIGENUSER_"
let default_group = ref "_OCSIGENGROUP_"
let mimefile = ref "_CONFIGDIR_/mime.types"
let datadir = ref "_DATADIR_"
let bindir = ref "_BINDIR_"
Expand Down
2 changes: 0 additions & 2 deletions src/baselib/ocsigen_config_static.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ val version_number : string
val config_file : string ref
val is_native : bool
val logdir : string option ref
val default_user : string ref
val default_group : string ref
val mimefile : string ref
val datadir : string ref
val bindir : string ref
Expand Down
48 changes: 28 additions & 20 deletions src/baselib/ocsigen_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,39 @@ let loadfiles pre post force modules =
aux modules

let set_module_init_function name f =
init_functions := M.add name f !init_functions;
(* print_endline ("Added init_function for " ^ name); *)
(* print_endline ("get_init_on_load: " ^ string_of_bool (get_init_on_load ())); *)
init_functions := M.add name [f] !init_functions;
if get_init_on_load () then f ()

let add_module_init_function name f =
let update = function
| None (* no binding so far *) -> Some [f]
| Some old -> Some (f :: old)
in
init_functions := M.update name update !init_functions;
if get_init_on_load () then f ()

let init_module pre post force name =
let f =
try M.find name !init_functions
with Not_found as e -> raise (Dynlink_error ("named module " ^ name, e))
try
let l = List.rev @@ M.find name !init_functions in
fun () -> List.iter (fun f -> f ()) l
with Not_found ->
Lwt_log.ign_info_f ~section "No init function for named module %s." name;
fun () -> ()
in
try
if force
then (
pre ();
Lwt_log.ign_info_f ~section
"Initializing %s (will be initialized every time)" name;
try f (); post () with e -> post (); raise e)
else if not (isloaded name)
then (
pre ();
Lwt_log.ign_info_f ~section "Initializing module %s " name;
(try f (); post () with e -> post (); raise e);
addloaded name)
else Lwt_log.ign_info_f ~section "Module %s already initialized." name
with e -> raise (Dynlink_error (name, e))
if force
then (
pre ();
Lwt_log.ign_info_f ~section
"Initializing %s (will be initialized every time)" name;
try f (); post () with e -> post (); raise e)
else if not (isloaded name)
then (
pre ();
Lwt_log.ign_info_f ~section "Initializing module %s " name;
(try f (); post () with e -> post (); raise e);
addloaded name)
else Lwt_log.ign_info_f ~section "Module %s already initialized." name

(************************************************************************)
(* Manipulating Findlib's search path *)
Expand Down
8 changes: 7 additions & 1 deletion src/baselib/ocsigen_loader.mli
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ val loadfiles : (unit -> unit) -> (unit -> unit) -> bool -> string list -> unit
but the last one, and [loadfile pre post force] for the last one
(if any). *)

val add_module_init_function : string -> (unit -> unit) -> unit
(** [add_module_init_function name f] adds function [f]
to the initialisation functions to be run
when [init_module name] is called. *)

val set_module_init_function : string -> (unit -> unit) -> unit
(** [set_module_init_function name f] registers the function [f], which will
be used to initialize the module when [init_module name] is called. *)
be used to initialize the module when [init_module name] is called.
Will replace the prvious value. *)

val init_module : (unit -> unit) -> (unit -> unit) -> bool -> string -> unit
(** [init_module pre post force name] runs the init function for the module
Expand Down
Loading

0 comments on commit 05a57ed

Please sign in to comment.