Refactor default_datadir into library builder_system

This commit is contained in:
Robur 2021-11-12 13:21:12 +00:00
parent 977678b325
commit b43c6f4d79
7 changed files with 26 additions and 48 deletions

View file

@ -320,35 +320,22 @@ let help man_format cmds = function
then `Help (man_format, Some cmd) then `Help (man_format, Some cmd)
else `Error (true, "Unknown command: " ^ cmd) else `Error (true, "Unknown command: " ^ cmd)
let uname =
let cmd = Bos.Cmd.(v "uname" % "-s") in
lazy (match Bos.OS.Cmd.(run_out cmd |> out_string |> success) with
| Ok s when s = "FreeBSD" -> `FreeBSD
| Ok s when s = "Linux" -> `Linux
| Ok s -> invalid_arg (Printf.sprintf "OS %s not supported\n" s)
| Error (`Msg m) -> invalid_arg m)
let default_datadir =
match Lazy.force uname with
| `FreeBSD -> "/var/db/builder-web"
| `Linux -> "/var/lib/builder-web"
let dbpath = let dbpath =
let doc = "sqlite3 database path" in let doc = "sqlite3 database path" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt non_dir_file (default_datadir ^ "/builder.sqlite3") & opt non_dir_file (Builder_system.default_datadir ^ "/builder.sqlite3") &
info ~doc ["dbpath"]) info ~doc ["dbpath"])
let dbpath_new = let dbpath_new =
let doc = "sqlite3 database path" in let doc = "sqlite3 database path" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt string (default_datadir ^ "/builder.sqlite3") & opt string (Builder_system.default_datadir ^ "/builder.sqlite3") &
info ~doc ["dbpath"]) info ~doc ["dbpath"])
let datadir = let datadir =
let doc = "data directory" in let doc = "data directory" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt dir default_datadir & opt dir Builder_system.default_datadir &
info ~doc ["datadir"]) info ~doc ["datadir"])
let jobname = let jobname =

12
bin/builder_system.ml Normal file
View file

@ -0,0 +1,12 @@
let uname =
let cmd = Bos.Cmd.(v "uname" % "-s") in
lazy (match Bos.OS.Cmd.(run_out cmd |> out_string |> success) with
| Ok s when s = "FreeBSD" -> `FreeBSD
| Ok s when s = "Linux" -> `Linux
| Ok s -> invalid_arg (Printf.sprintf "OS %s not supported" s)
| Error (`Msg m) -> invalid_arg m)
let default_datadir =
match Lazy.force uname with
| `FreeBSD -> "/var/db/builder-web"
| `Linux -> "/var/lib/builder-web"

View file

@ -120,22 +120,9 @@ let ip_port : (Ipaddr.V4.t * int) Arg.converter =
in in
parse, fun ppf (ip, port) -> Format.fprintf ppf "%a:%d" Ipaddr.V4.pp ip port parse, fun ppf (ip, port) -> Format.fprintf ppf "%a:%d" Ipaddr.V4.pp ip port
let uname =
let cmd = Bos.Cmd.(v "uname" % "-s") in
lazy (match Bos.OS.Cmd.(run_out cmd |> out_string |> success) with
| Ok s when s = "FreeBSD" -> `FreeBSD
| Ok s when s = "Linux" -> `Linux
| Ok s -> invalid_arg (Printf.sprintf "OS %s not supported" s)
| Error (`Msg m) -> invalid_arg m)
let default_datadir =
match Lazy.force uname with
| `FreeBSD -> "/var/db/builder-web"
| `Linux -> "/var/lib/builder-web"
let datadir = let datadir =
let doc = "data directory" in let doc = "data directory" in
Arg.(value & opt dir default_datadir & info [ "d"; "datadir" ] ~doc) Arg.(value & opt dir Builder_system.default_datadir & info [ "d"; "datadir" ] ~doc)
let port = let port =
let doc = "port" in let doc = "port" in

View file

@ -1,11 +1,16 @@
(library
(name builder_system)
(modules builder_system)
(libraries bos))
(executable (executable
(public_name builder-web) (public_name builder-web)
(name builder_web_app) (name builder_web_app)
(modules builder_web_app) (modules builder_web_app)
(libraries builder_web mirage-crypto-rng.unix cmdliner logs.cli metrics metrics-lwt metrics-influx metrics-rusage ipaddr ipaddr.unix http_status_metrics)) (libraries builder_web builder_system mirage-crypto-rng.unix cmdliner logs.cli metrics metrics-lwt metrics-influx metrics-rusage ipaddr ipaddr.unix http_status_metrics))
(executable (executable
(public_name builder-db) (public_name builder-db)
(name builder_db) (name builder_db)
(modules builder_db) (modules builder_db)
(libraries builder_db caqti.blocking uri bos fmt logs logs.cli logs.fmt cmdliner mirage-crypto-rng.unix)) (libraries builder_db builder_system caqti.blocking uri bos fmt logs logs.cli logs.fmt cmdliner mirage-crypto-rng.unix))

View file

@ -59,23 +59,10 @@ let help man_format migrations = function
then `Help (man_format, Some migration) then `Help (man_format, Some migration)
else `Error (true, "Unknown migration: " ^ migration) else `Error (true, "Unknown migration: " ^ migration)
let uname =
let cmd = Bos.Cmd.(v "uname" % "-s") in
lazy (match Bos.OS.Cmd.(run_out cmd |> out_string |> success) with
| Ok s when s = "FreeBSD" -> `FreeBSD
| Ok s when s = "Linux" -> `Linux
| Ok s -> invalid_arg (Printf.sprintf "OS %s not supported" s)
| Error (`Msg m) -> invalid_arg m)
let default_datadir =
match Lazy.force uname with
| `FreeBSD -> "/var/db/builder-web"
| `Linux -> "/var/lib/builder-web"
let datadir = let datadir =
let doc = "data directory containing builder.sqlite3 and data files" in let doc = "data directory containing builder.sqlite3 and data files" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt dir default_datadir & opt dir Builder_system.default_datadir &
info ~doc ["datadir"]) info ~doc ["datadir"])
let setup_log = let setup_log =

View file

@ -1,4 +1,4 @@
(executable (executable
(public_name builder-migrations) (public_name builder-migrations)
(name builder_migrations) (name builder_migrations)
(libraries builder_db caqti caqti-driver-sqlite3 caqti.blocking cmdliner logs logs.cli logs.fmt opam-format bos duration)) (libraries builder_system builder_db caqti caqti-driver-sqlite3 caqti.blocking cmdliner logs logs.cli logs.fmt opam-format bos duration))

View file

@ -6,7 +6,7 @@ After=syslog.target network.target
Type=simple Type=simple
User=builder User=builder
Group=builder Group=builder
ExecStart=/usr/bin/builder-web --datadir /var/lib/builder-web/ ExecStart=/usr/bin/builder-web
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target