From 377de9472716266bb932813a8f7a7ba9aa1630fb Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 23 Jan 2017 23:04:50 +0700 Subject: 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 --- src/vyconf_config.ml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') 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 *) -- cgit v1.2.3