summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defaults.ml2
-rw-r--r--src/defaults.mli1
-rw-r--r--src/vyconfd.ml60
3 files changed, 58 insertions, 5 deletions
diff --git a/src/defaults.ml b/src/defaults.ml
index 7bf46a8..f815266 100644
--- a/src/defaults.ml
+++ b/src/defaults.ml
@@ -1,7 +1,9 @@
type vyconf_defaults = {
config_file: string;
+ version: string
}
let defaults = {
config_file = "/etc/vyconfd.conf";
+ version = "0.0.1"
}
diff --git a/src/defaults.mli b/src/defaults.mli
index 48e5cdb..44ed76d 100644
--- a/src/defaults.mli
+++ b/src/defaults.mli
@@ -1,5 +1,6 @@
type vyconf_defaults = {
config_file: string;
+ version: string
}
val defaults : vyconf_defaults
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index 29345fb..3f80c1d 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -1,15 +1,65 @@
open Lwt
open Defaults
+open Vyconf_config
let () = Lwt_log.add_rule "*" Lwt_log.Info
-let config =
- let result = Vyconf_config.load defaults.config_file in
+(* Default VyConf configuration *)
+let daemonize = ref true
+let config_file = ref defaults.config_file
+let log_file = ref None
+let log_template = ref "$(date): $(message)"
+
+(* Global data *)
+
+(* Command line arguments *)
+let args = [
+ ("--no-daemon", Arg.Unit (fun () -> daemonize := false),
+ "Do not daemonize");
+ ("--config", Arg.String (fun s -> config_file := s),
+ (Printf.sprintf "<string> Configuration file, default is %s" defaults.config_file));
+ ("--log-file", Arg.String (fun s -> log_file := Some s),
+ "<string> Log file");
+ ("--version", Arg.Unit (fun () -> Printf.printf "VyConf version: %s\n" defaults.version; exit 0), "Print version and exit")
+ ]
+let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]"
+
+let load_config path =
+ let result = Vyconf_config.load path in
match result with
- | `Ok cfg -> cfg
- | `Error err ->
+ | Result.Ok cfg -> cfg
+ | Result.Error err ->
Lwt_log.fatal (Printf.sprintf "Could not load the configuration file %s" err); exit 1
+let setup_logger daemonize log_file template =
+ (*
+ If log file is specified, log to the file whether we are a daemon or not
+ If we are a daemon and log file is not specified, log to syslog
+ If we are not a daemon and log file is not specified, log to stderr
+ *)
+ match log_file with
+ | None ->
+ if daemonize then
+ begin
+ Lwt_log.default := Lwt_log.syslog ~template:template ~facility:`Daemon ();
+ Lwt.return_unit
+ end
+ else
+ begin
+ Lwt_log.default := Lwt_log.channel ~template:template ~close_mode:`Keep ~channel:Lwt_io.stderr ();
+ Lwt.return_unit
+ end
+ | Some file ->
+ let%lwt l = Lwt_log.file ~template:template ~mode:`Append ~file_name:file () in
+ Lwt_log.default := l; Lwt.return_unit
+let main_loop config () =
+ let%lwt () = setup_logger !daemonize !log_file !log_template in
+ let%lwt () = Lwt_log.notice @@ Printf.sprintf "Loading %s" config.app_name in
+ Lwt.return_unit
-let () = print_endline "This is VyConf. Or, rather, will be."
+let () =
+ let () = Arg.parse args (fun f -> ()) usage in
+ let config = load_config !config_file in
+ Lwt_main.run @@ main_loop config ()
+