diff --git a/bin/builder_db.ml b/bin/builder_db.ml index 0232d6c..af5682c 100644 --- a/bin/builder_db.ml +++ b/bin/builder_db.ml @@ -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 = diff --git a/bin/builder_system.ml b/bin/builder_system.ml new file mode 100644 index 0000000..551ca84 --- /dev/null +++ b/bin/builder_system.ml @@ -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" diff --git a/bin/builder_web_app.ml b/bin/builder_web_app.ml index 37829bc..7602e87 100644 --- a/bin/builder_web_app.ml +++ b/bin/builder_web_app.ml @@ -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 diff --git a/bin/dune b/bin/dune index 2eee321..04a7bfc 100644 --- a/bin/dune +++ b/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)) diff --git a/bin/migrations/builder_migrations.ml b/bin/migrations/builder_migrations.ml index ab83d49..e1b713d 100644 --- a/bin/migrations/builder_migrations.ml +++ b/bin/migrations/builder_migrations.ml @@ -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 = diff --git a/bin/migrations/dune b/bin/migrations/dune index 9150bfb..b27283f 100644 --- a/bin/migrations/dune +++ b/bin/migrations/dune @@ -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)) diff --git a/packaging/debian/builder-web.service b/packaging/debian/builder-web.service index 7ac1d3c..2835d92 100644 --- a/packaging/debian/builder-web.service +++ b/packaging/debian/builder-web.service @@ -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