summaryrefslogtreecommitdiff
path: root/src/startup.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-12-12 22:21:02 +0000
committerDaniil Baturin <daniil@baturin.org>2017-12-12 22:21:02 +0000
commit5f7d6a60287bac8f633b9c4e5e9e3f6f3a45da85 (patch)
treea60da9092db67505858322047be22ded98cf730b /src/startup.ml
parent8f2ff161343548a7d735808c203f0582fcb91145 (diff)
downloadvyconf-5f7d6a60287bac8f633b9c4e5e9e3f6f3a45da85.tar.gz
vyconf-5f7d6a60287bac8f633b9c4e5e9e3f6f3a45da85.zip
Add config load upon startup.
Diffstat (limited to 'src/startup.ml')
-rw-r--r--src/startup.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/startup.ml b/src/startup.ml
index c6e2f8c..69849e0 100644
--- a/src/startup.ml
+++ b/src/startup.ml
@@ -58,3 +58,29 @@ let create_server accept_connection sock =
let rec serve () =
Lwt_unix.accept sock >>= accept_connection >>= serve
in serve
+
+(** Load the appliance configuration file *)
+let load_config file =
+ try
+ let chan = open_in file in
+ let config = Curly_parser.config Curly_lexer.token (Lexing.from_channel chan) in
+ Ok config
+ with
+ | Sys_error msg -> Error msg
+ | Curly_parser.Error -> Error "Parse error"
+
+(** Load the appliance configuration file or the fallback config *)
+let load_config_failsafe main fallback =
+ let res = load_config main in
+ match res with
+ | Ok config -> config
+ | Error msg ->
+ Lwt_log.error
+ (Printf.sprintf "Failed to load config file %s: %s. Attempting to load fallback config %s" main msg fallback) |>
+ Lwt.ignore_result;
+ let res = load_config fallback in
+ begin
+ match res with
+ | Ok config -> config
+ | Error msg -> panic (Printf.sprintf "Failed to load fallback config %s: %s, exiting" fallback msg)
+ end