diff options
| author | Daniil Fedotov <dfedotov@pivotal.io> | 2016-02-17 11:11:57 +0000 |
|---|---|---|
| committer | Daniil Fedotov <dfedotov@pivotal.io> | 2016-02-17 11:11:57 +0000 |
| commit | 7104595588c739dc8e92671b0307adcb9b40ef2f (patch) | |
| tree | 67bfc4911d5e1a5617e13fb15effd2eb3c8f9d3b /src | |
| parent | 77bea34198bbbf4f67f726652e5144ca14d66601 (diff) | |
| download | rabbitmq-server-git-7104595588c739dc8e92671b0307adcb9b40ef2f.tar.gz | |
Support for plugin schemas
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit.erl | 25 | ||||
| -rw-r--r-- | src/rabbit_config.erl | 29 | ||||
| -rw-r--r-- | src/rabbit_plugins.erl | 17 |
3 files changed, 55 insertions, 16 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 2715b80eb5..7fafaf4d4d 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -272,14 +272,7 @@ start() -> boot() -> start_it(fun() -> - case rabbit_config:prepare_and_use_config() of - {error, Reason} -> - log_boot_error_and_exit( - generate_config_file, - "~nConfig file generation failed ~p", - [Reason]); - ok -> ok - end, + ensure_config(), ok = ensure_application_loaded(), HipeResult = rabbit_hipe:maybe_hipe_compile(), ok = start_logger(), @@ -293,8 +286,24 @@ boot() -> broker_start() end). +ensure_config() -> + case rabbit_config:prepare_and_use_config() of + {error, Reason} -> + {Format, Arg} = case Reason of + {generation_error, Error} -> {"~s", [Error]}; + Other -> {"~p", [Other]} + end, + log_boot_error_and_exit(generate_config_file, + "~nConfig file generation failed "++Format, + Arg); + ok -> ok + end. + + broker_start() -> Plugins = rabbit_plugins:setup(), + % Duplicate ensure_config to support plugin schemas. + ensure_config(), ToBeLoaded = Plugins ++ ?APPS, start_apps(ToBeLoaded), case os:type() of diff --git a/src/rabbit_config.erl b/src/rabbit_config.erl index 23e080ae4d..a6107aef6d 100644 --- a/src/rabbit_config.erl +++ b/src/rabbit_config.erl @@ -4,7 +4,8 @@ generate_config_file/3, prepare_and_use_config/0, prepare_config/1, - update_app_config/1]). + update_app_config/1, + schema_dir/0]). prepare_and_use_config() -> case config_exist() of @@ -59,23 +60,25 @@ update_app_config(ConfigFile) -> ok = application_controller:change_application_data([], [ConfigFile]). generate_config_file(ConfFiles, ConfDir, ScriptDir) -> - SchemaFile = filename:join([ScriptDir, "rabbitmq.schema"]), + SchemaDir = schema_dir(), + % SchemaFile = filename:join([ScriptDir, "rabbitmq.schema"]), Cuttlefish = filename:join([ScriptDir, "cuttlefish"]), GeneratedDir = filename:join([ConfDir, "generated"]), - AdditionalConfigArg = case get_additional_config() of + AdvancedConfigArg = case get_advanced_config() of {ok, FileName} -> [" -a ", FileName]; none -> [] end, rabbit_file:recursive_delete([GeneratedDir]), Command = lists:concat(["escript ", "\"", Cuttlefish, "\"", - " -f rabbitmq -i ", "\"", SchemaFile, "\"", + " -f rabbitmq -s ", "\"", SchemaDir, "\"", " -e ", "\"", ConfDir, "\"", [[" -c ", ConfFile] || ConfFile <- ConfFiles], - AdditionalConfigArg]), + AdvancedConfigArg]), + io:format("Command: ~s~n", [Command]), Result = rabbit_misc:os_cmd(Command), case string:str(Result, " -config ") of - 0 -> {error, {generaion_error, Result}}; + 0 -> {error, {generation_error, Result}}; _ -> [OutFile] = rabbit_file:wildcard("rabbitmq.*.config", GeneratedDir), ResultFile = filename:join([GeneratedDir, "rabbitmq.config"]), @@ -84,8 +87,18 @@ generate_config_file(ConfFiles, ConfDir, ScriptDir) -> {ok, ResultFile} end. -get_additional_config() -> - case init:get_argument(conf_additional) of +schema_dir() -> + case init:get_argument(conf_schema_dir) of + {ok, SchemaDir} -> SchemaDir; + _ -> + case code:priv_dir(rabbit) of + {error, bad_name} -> filename:join([".", "priv", "schema"]); + PrivDir -> filename:join([PrivDir, "schema"]) + end + end. + +get_advanced_config() -> + case init:get_argument(conf_advanced) of {ok, FileName} -> ConfigName = FileName ++ ".config", case rabbit_file:is_file(ConfigName) of diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index c7f5d501bf..ff7ec1a984 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -228,6 +228,7 @@ clean_plugin(Plugin, ExpandDir) -> prepare_dir_plugin(PluginAppDescPath) -> PluginEbinDir = filename:dirname(PluginAppDescPath), Plugin = filename:basename(PluginAppDescPath, ".app"), + copy_plugin_schema(Plugin, PluginAppDescPath), code:add_patha(PluginEbinDir), case filelib:wildcard(PluginEbinDir++ "/*.beam") of [] -> @@ -250,6 +251,22 @@ prepare_dir_plugin(PluginAppDescPath) -> %%---------------------------------------------------------------------------- +copy_plugin_schema(Plugin, PluginAppDescPath) -> + PluginSchema = filename:join([PluginAppDescPath, + "priv", + "schema", + [Plugin, ".schema"]]), + case rabbit_file:is_file(PluginSchema) of + false -> ok; + true -> + SchemaDir = rabbit_config:schema_dir(), + case rabbit_file:is_dir(SchemaDir) of + true -> file:copy(PluginSchema, SchemaDir); + false -> rabbit_log:info("Failed to copy plugin schema. " + "Schema dir doesn't exist") + end + end. + delete_recursively(Fn) -> case rabbit_file:recursive_delete([Fn]) of ok -> ok; |
