restart: bool;
live_reload: bool;
disable_socket: bool;
+ config_test: bool;
}
+let get_config_filename config_file =
+ match config_file with
+ | Some name -> name
+ | None -> Define.default_config_dir ^ "/oxenstored.conf"
+
let do_argv =
let pidfile = ref "" and tracefile = ref "" (* old xenstored compatibility *)
and domain_init = ref true
and restart = ref false
and live_reload = ref false
and disable_socket = ref false
+ and config_test = ref false
+ and help = ref false
in
let speclist =
("-T", Arg.Set_string tracefile, ""); (* for compatibility *)
("--restart", Arg.Set restart, "Read database on starting");
("--live", Arg.Set live_reload, "Read live dump on startup");
+ ("--config-test", Arg.Set config_test, "Test validity of config file");
("--disable-socket", Arg.Unit (fun () -> disable_socket := true), "Disable socket");
+ ("--help", Arg.Set help, "Display this list of options")
] in
let usage_msg = "usage : xenstored [--config-file <filename>] [--no-domain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] [--disable-socket]" in
Arg.parse speclist (fun _ -> ()) usage_msg;
+ let () =
+ if !help then begin
+ if !live_reload then
+ (*
+ Transform --live --help into --config-test for backward compat with
+ running code during live update.
+ Caller will validate config and exit
+ *)
+ config_test := true
+ else begin
+ Arg.usage_string speclist usage_msg |> print_endline;
+ exit 0
+ end
+ end
+ in
{
domain_init = !domain_init;
activate_access_log = !activate_access_log;
restart = !restart;
live_reload = !live_reload;
disable_socket = !disable_socket;
+ config_test = !config_test;
}
let ring_scan_interval = ref 20
-let parse_config filename =
+let parse_config ?(strict=false) filename =
let pidfile = ref default_pidfile in
let options = [
("merge-activate", Config.Set_bool Transaction.do_coalesce);
("xenstored-port", Config.Set_string Domains.xenstored_port); ] in
begin try Config.read filename options (fun _ _ -> raise Not_found)
with
- | Config.Error err -> List.iter (fun (k, e) ->
+ | Config.Error err as e -> List.iter (fun (k, e) ->
match e with
| "unknown key" -> eprintf "config: unknown key %s\n" k
| _ -> eprintf "config: %s: %s\n" k e
) err;
+ if strict then raise e
| Sys_error m -> eprintf "error: config: %s\n" m;
end;
!pidfile
let () =
Printexc.set_uncaught_exception_handler Logging.fallback_exception_handler;
let cf = do_argv in
+ if cf.config_test then begin
+ let path = config_filename cf in
+ let _pidfile:string = parse_config ~strict:true path in
+ Printf.printf "Configuration valid at %s\n%!" path;
+ exit 0
+ end;
let pidfile =
if Sys.file_exists (config_filename cf) then
parse_config (config_filename cf)