Refactor default_datadir into library builder_system
This commit is contained in:
parent
977678b325
commit
b43c6f4d79
7 changed files with 26 additions and 48 deletions
|
@ -320,35 +320,22 @@ let help man_format cmds = function
|
|||
then `Help (man_format, Some 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 doc = "sqlite3 database path" in
|
||||
Cmdliner.Arg.(value &
|
||||
opt non_dir_file (default_datadir ^ "/builder.sqlite3") &
|
||||
opt non_dir_file (Builder_system.default_datadir ^ "/builder.sqlite3") &
|
||||
info ~doc ["dbpath"])
|
||||
|
||||
let dbpath_new =
|
||||
let doc = "sqlite3 database path" in
|
||||
Cmdliner.Arg.(value &
|
||||
opt string (default_datadir ^ "/builder.sqlite3") &
|
||||
opt string (Builder_system.default_datadir ^ "/builder.sqlite3") &
|
||||
info ~doc ["dbpath"])
|
||||
|
||||
let datadir =
|
||||
let doc = "data directory" in
|
||||
Cmdliner.Arg.(value &
|
||||
opt dir default_datadir &
|
||||
opt dir Builder_system.default_datadir &
|
||||
info ~doc ["datadir"])
|
||||
|
||||
let jobname =
|
||||
|
|
12
bin/builder_system.ml
Normal file
12
bin/builder_system.ml
Normal 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"
|
|
@ -120,22 +120,9 @@ let ip_port : (Ipaddr.V4.t * int) Arg.converter =
|
|||
in
|
||||
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 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 doc = "port" in
|
||||
|
|
9
bin/dune
9
bin/dune
|
@ -1,11 +1,16 @@
|
|||
(library
|
||||
(name builder_system)
|
||||
(modules builder_system)
|
||||
(libraries bos))
|
||||
|
||||
(executable
|
||||
(public_name builder-web)
|
||||
(name 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
|
||||
(public_name builder-db)
|
||||
(name 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))
|
||||
|
|
|
@ -59,23 +59,10 @@ let help man_format migrations = function
|
|||
then `Help (man_format, Some 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 doc = "data directory containing builder.sqlite3 and data files" in
|
||||
Cmdliner.Arg.(value &
|
||||
opt dir default_datadir &
|
||||
opt dir Builder_system.default_datadir &
|
||||
info ~doc ["datadir"])
|
||||
|
||||
let setup_log =
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(executable
|
||||
(public_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))
|
||||
|
|
|
@ -6,7 +6,7 @@ After=syslog.target network.target
|
|||
Type=simple
|
||||
User=builder
|
||||
Group=builder
|
||||
ExecStart=/usr/bin/builder-web --datadir /var/lib/builder-web/
|
||||
ExecStart=/usr/bin/builder-web
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
Loading…
Reference in a new issue