summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-01-23 23:04:50 +0700
committerDaniil Baturin <daniil@baturin.org>2017-01-23 23:04:50 +0700
commit377de9472716266bb932813a8f7a7ba9aa1630fb (patch)
treeeb9da36b9ac3200f8608dbf5503c565d32406503
parent46efea7823acfef5230f33f4b27c99bc176aafbc (diff)
downloadvyconf-377de9472716266bb932813a8f7a7ba9aa1630fb.tar.gz
vyconf-377de9472716266bb932813a8f7a7ba9aa1630fb.zip
Add basepath option to the vyconfd config.
Right now the primary motivation is ease of testing without installing any appliance on a real system, but in real appliances, this may be handy for those who want things in /opt, even if I'm not a fan of /opt
-rw-r--r--src/vyconf_config.ml19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/vyconf_config.ml b/src/vyconf_config.ml
index 7a87c1a..9301f84 100644
--- a/src/vyconf_config.ml
+++ b/src/vyconf_config.ml
@@ -49,21 +49,24 @@ let optional_field default conf table field =
let value = get_field conf table field in
BatOption.default default value
+let (+/) l r = FilePath.concat l r
+
let load filename =
try
let open Defaults in
let conf_toml = Toml.Parser.from_filename filename |> Toml.Parser.unsafe in
+ let basepath = optional_field "" conf_toml "appliance" "basepath" in
let conf = empty_config in
(* Mandatory fields *)
- let conf = {conf with app_name = mandatory_field conf_toml "appliance" "name"} in
- let conf = {conf with data_dir = mandatory_field conf_toml "appliance" "data_dir"} in
- let conf = {conf with config_dir = mandatory_field conf_toml "appliance" "config_dir"} in
- let conf = {conf with program_dir = mandatory_field conf_toml "appliance" "program_dir"} in
- let conf = {conf with primary_config = mandatory_field conf_toml "appliance" "primary_config"} in
- let conf = {conf with fallback_config = mandatory_field conf_toml "appliance" "fallback_config"} in
+ let conf = {conf with app_name = basepath +/ (mandatory_field conf_toml "appliance" "name")} in
+ let conf = {conf with data_dir = basepath +/ (mandatory_field conf_toml "appliance" "data_dir")} in
+ let conf = {conf with config_dir = basepath +/ (mandatory_field conf_toml "appliance" "config_dir")} in
+ let conf = {conf with program_dir = basepath +/ (mandatory_field conf_toml "appliance" "program_dir")} in
+ let conf = {conf with primary_config = basepath +/ (mandatory_field conf_toml "appliance" "primary_config")} in
+ let conf = {conf with fallback_config = basepath +/ (mandatory_field conf_toml "appliance" "fallback_config")} in
(* Optional fields *)
- let conf = {conf with pid_file = optional_field defaults.pid_file conf_toml "vyconf" "pid_file"} in
- let conf = {conf with socket = optional_field defaults.socket conf_toml "vyconf" "socket"} in
+ let conf = {conf with pid_file = basepath +/ (optional_field defaults.pid_file conf_toml "vyconf" "pid_file")} in
+ let conf = {conf with socket = basepath +/ (optional_field defaults.socket conf_toml "vyconf" "socket")} in
let conf = {conf with log_template = optional_field defaults.log_template conf_toml "vyconf" "log_template"} in
let conf = {conf with log_level = optional_field defaults.log_level conf_toml "vyconf" "log_level"} in
(* log_file is already string option, so we don't need to unwrap *)