I have installed on a Debian system the package libocamlnet-ocaml-dev
.
I brings /usr/lib/ocaml/netcgi2-apache/netcgi2-apache.cma
and several other caml archives. However, the name in the META file is netcgi_apache
. Then when I set the Ocaml/Apache module to load netcgi2-apache
there is an error because netcgi_apache.cma
is not found. I have managed to fix this issue with a symlink and make the library available with the two names.
Now, I am trying to use the Netcgi_apache
module.
I have:
loyer@ks3001154:~/public_html/ocaml$ ocamlc /usr/lib/ocaml/netcgi2-apache/netcgi_apache.cma essai.ml
File "essai.ml", line 1, characters 19-36:
1 | let process (cgi : Netcgi_apache.cgi) =
^^^^^^^^^^^^^^^^^
Error: Unbound module Netcgi_apache
loyer@ks3001154:~/public_html/ocaml$ ocamlc /usr/lib/ocaml/netcgi2-apache/netcgi2-apache.cma essai.ml
File "essai.ml", line 1, characters 19-36:
1 | let process (cgi : Netcgi_apache.cgi) =
^^^^^^^^^^^^^^^^^
Error: Unbound module Netcgi_apache
Shouldn’t the netcgi2-apache.cma
bring the require module ?
I note that I have /usr/lib/ocaml/netcgi2-apache/netcgi_apache_mod.mli
and its .cmi
, but not its implementation (.cma
)
The compiler needs to see the .cmi
file of the module Netcgi_apache
. Something like:
ocamlc -I /usr/lib/ocaml/netcgi2-apache/ /usr/lib/ocaml/netcgi2-apache/netcgi_apache.cma essai.ml
should work.
You don’t use dune to compile your project?
I have tried manually because dune seems to use the opam directory path… and hasn’t worked either.
Note, the proposed -I /path_to_netcgi2-apache doesn’t work.
I guess, I will try to recompile the module in the Debian way and see how it has been done.
Maybe, ask Gerd Stolpman (the maintainer of ocamlnet) or in the ocamlnet-devel mailaing list or
open an issue in there:
https://sourceforge.net/p/ocamlnet/mailman/ocamlnet-devel/
If you are not strongly tied to Netcgi-apache, I would actually strongly recommend the Dream web framework: Dream — Tidy, feature-complete web framework
It’s very easy to get started:
let () =
Dream.run
@@ Dream.logger
@@ Dream.router [
Dream.get "/" (fun _ ->
Dream.html "hello world");
]
And of course, you get a standalone executable which is a nice bonus.
What is the error you get ? The same error ? According to what I see there the .cmi
should be there.
Oherwise something like ocamlfind ocamlc -linkpkg -package netcgi2_apache test.ml
will likely be easier.
$ ocamlfind ocamlc -linkpkg -package netcgi2_apache main.ml
ocamlfind: Package `netcgi2_apache' not found
$ $ ocamlc -I /usr/lib/ocaml/netcgi2-apache netcgi2_apache.cma main.ml
File "main.ml", line 1, characters 18-28:
1 | let process (cgi: Netcgi.cgi) =
^^^^^^^^^^
Error: Unbound module Netcgi
I have though about the dream server, but can’t start it:
$ cat /etc/systemd/system/dream.service
[Unit]
Description=Dream server
After=network.target
[Service]
Type=simple
Restart=on-failure
User=loyer # ensure minimal access to system
Group=nobody
ExecStart=/home/loyer/dream_server/_build/default/bin/server.exe
StandardOutput=file:/var/log/dream.log
StandardError=file:/var/log/dream.log
PrivateTmp=yes # hide contents of /tmp from other processes on system
[Install]
WantedBy=multi-user.target
$ sudo systemctl start dream
$ sudo systemctl status dream
â—Ź dream.service - Dream server
Loaded: loaded (/etc/systemd/system/dream.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-02-20 10:46:23 CET; 15s ago
Process: 1810506 ExecStart=/home/loyer/dream_server/_build/default/bin/server.exe (code=exited, status=217/USER)
Main PID: 1810506 (code=exited, status=217/USER)
CPU: 13ms
févr. 20 10:46:23 my_host.com systemd[1]: dream.service: Scheduled restart job, restart counter is at 5.
févr. 20 10:46:23 my_host.com systemd[1]: Stopped Dream server.
févr. 20 10:46:23 my_host.com systemd[1]: dream.service: Start request repeated too quickly.
févr. 20 10:46:23 my_host.com systemd[1]: dream.service: Failed with result 'exit-code'.
févr. 20 10:46:23 my_host.com systemd[1]: Failed to start Dream server.
(and there are no /var/log/dream.log
file. I have tried to change le log file (where the user has write rights… but it doesn’t change anything)
Maybe it’s called differently try ocamlfind list
to see the list of packages, also maybe that’s looking up in your opam, ocamlfind printconf
/ command -v ocamlfind
will tell you that. You may want to try with /usr/bin/ocamlfind
.
I guess by now you should see the pattern here. You need to locate the netcgi.cmi
file and add its directory to the includes, you will likely also need to add the cma that holds this module on the cli.
Didn’t look far but this 217/user error seems to be about inexistent user. I suspect it’s because loyer
doesn’t belong to the nobody
group.
1 Like
I have get it work.
Simply,
User=loyer # ensure minimal access to system
Try to find a loyer # ensure minimal access to system
user which doesn’t exist. I had just to suppress the comment.
1 Like