Add emqx_gen_config module
This commit is contained in:
parent
c5d16a3368
commit
cfd91f481e
|
@ -0,0 +1,106 @@
|
|||
##############################
|
||||
# Erlang VM Args
|
||||
##############################
|
||||
|
||||
## NOTE:
|
||||
##
|
||||
## Arguments configured in this file might be overridden by configs from `emqx.conf`.
|
||||
##
|
||||
## Some basic VM arguments are to be configured in `emqx.conf`,
|
||||
## such as `node.name` for `-name` and `node.cooke` for `-setcookie`.
|
||||
|
||||
## Sets the maximum number of simultaneously existing processes for this system.
|
||||
#+P 2048000
|
||||
|
||||
## Sets the maximum number of simultaneously existing ports for this system.
|
||||
#+Q 1024000
|
||||
|
||||
## Sets the maximum number of ETS tables
|
||||
#+e 256000
|
||||
|
||||
## Sets the maximum number of atoms the virtual machine can handle.
|
||||
#+t 1048576
|
||||
|
||||
## Set the location of crash dumps
|
||||
#-env ERL_CRASH_DUMP log/crash.dump
|
||||
|
||||
## Set how many times generational garbages collections can be done without
|
||||
## forcing a fullsweep collection.
|
||||
#-env ERL_FULLSWEEP_AFTER 1000
|
||||
|
||||
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
|
||||
## (Disabled by default..use with caution!)
|
||||
#-heart
|
||||
|
||||
## Specify the erlang distributed protocol.
|
||||
## Can be one of: inet_tcp, inet6_tcp, inet_tls
|
||||
#-proto_dist inet_tcp
|
||||
|
||||
## Specify SSL Options in the file if using SSL for Erlang Distribution.
|
||||
## Used only when -proto_dist set to inet_tls
|
||||
#-ssl_dist_optfile etc/ssl_dist.conf
|
||||
|
||||
## Specifies the net_kernel tick time in seconds.
|
||||
## This is the approximate time a connected node may be unresponsive until
|
||||
## it is considered down and thereby disconnected.
|
||||
#-kernel net_ticktime 60
|
||||
|
||||
## Sets the distribution buffer busy limit (dist_buf_busy_limit).
|
||||
#+zdbbl 8192
|
||||
|
||||
## Sets default scheduler hint for port parallelism.
|
||||
+spp true
|
||||
|
||||
## Sets the number of threads in async thread pool. Valid range is 0-1024.
|
||||
#+A 8
|
||||
|
||||
## Sets the default heap size of processes to the size Size.
|
||||
#+hms 233
|
||||
|
||||
## Sets the default binary virtual heap size of processes to the size Size.
|
||||
#+hmbs 46422
|
||||
|
||||
## Sets the number of IO pollsets to use when polling for I/O.
|
||||
#+IOp 1
|
||||
|
||||
## Sets the number of IO poll threads to use when polling for I/O.
|
||||
#+IOt 1
|
||||
|
||||
## Sets the number of scheduler threads to create and scheduler threads to set online.
|
||||
#+S 8:8
|
||||
|
||||
## Sets the number of dirty CPU scheduler threads to create and dirty CPU scheduler threads to set online.
|
||||
#+SDcpu 8:8
|
||||
|
||||
## Sets the number of dirty I/O scheduler threads to create.
|
||||
#+SDio 10
|
||||
|
||||
## Suggested stack size, in kilowords, for scheduler threads.
|
||||
#+sss 32
|
||||
|
||||
## Suggested stack size, in kilowords, for dirty CPU scheduler threads.
|
||||
#+sssdcpu 40
|
||||
|
||||
## Suggested stack size, in kilowords, for dirty IO scheduler threads.
|
||||
#+sssdio 40
|
||||
|
||||
## Sets scheduler bind type.
|
||||
## Can be one of: u, ns, ts, ps, s, nnts, nnps, tnnps, db
|
||||
#+sbt db
|
||||
|
||||
## Sets a user-defined CPU topology.
|
||||
#+sct L0-3c0-3p0N0:L4-7c0-3p1N1
|
||||
|
||||
## Sets the mapping of warning messages for error_logger
|
||||
#+W w
|
||||
-kernel net_ticktime 60
|
||||
-env ERL_CRASH_DUMP log/crash.dump
|
||||
+e 256000
|
||||
-env ERL_FULLSWEEP_AFTER 1000
|
||||
+Q 1024000
|
||||
+P 2048000
|
||||
+A 32
|
||||
-setcookie emqxsecretcookie
|
||||
-proto_dist inet_tcp
|
||||
-name emqx@127.0.0.1
|
||||
+zdbbl 8192
|
|
@ -27,6 +27,8 @@
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
start(_Type, _Args) ->
|
||||
|
||||
emqx_gen_config:generate_config("etc/emqx.conf", "etc/plugins", "data/configs", "releases/3.1/schema"),
|
||||
%% We'd like to configure the primary logger level here, rather than set the
|
||||
%% kernel config `logger_level` before starting the erlang vm.
|
||||
%% This is because the latter approach an annoying debug msg will be printed out:
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
%% Copyright (c) 2013-2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
|
||||
-module(emqx_gen_config).
|
||||
|
||||
-include("logger.hrl").
|
||||
|
||||
-export([generate_config/4]).
|
||||
|
||||
generate_config(EmqCfg, PluginsEtc, DestDir, SchemaDir) ->
|
||||
case mergeconf(EmqCfg, PluginsEtc, DestDir) of
|
||||
{error, Error} ->
|
||||
exit(Error);
|
||||
AppConf ->
|
||||
Schemas = filelib:wildcard("*.schema", SchemaDir),
|
||||
Schemas1 = lists:map(
|
||||
fun(Schema) ->
|
||||
filename:join(SchemaDir, Schema)
|
||||
end, Schemas),
|
||||
Schemas2 = cuttlefish_schema:files(Schemas1),
|
||||
case cuttlefish_generator:map(Schemas2, cuttlefish_conf:file(AppConf)) of
|
||||
{error, Error1} ->
|
||||
exit(Error1);
|
||||
AllConfigs ->
|
||||
[[application:set_env(App, Key, Val) || {Key, Val} <- Configs]|| {App, Configs} <- AllConfigs]
|
||||
end
|
||||
end.
|
||||
|
||||
mergeconf(EmqCfg, PluginsEtc, DestDir) ->
|
||||
filelib:ensure_dir(DestDir),
|
||||
AppConf = filename:join(DestDir, appconf()),
|
||||
case file:open(AppConf, [write]) of
|
||||
{ok, DestFd} ->
|
||||
CfgFiles = [EmqCfg | cfgfiles(PluginsEtc)],
|
||||
lists:foreach(fun(CfgFile) ->
|
||||
{ok, CfgData} = file:read_file(CfgFile),
|
||||
file:write(DestFd, CfgData),
|
||||
file:write(DestFd, <<"\n">>)
|
||||
end, CfgFiles),
|
||||
file:close(DestFd),
|
||||
AppConf;
|
||||
{error, Error} ->
|
||||
?LOG(error, "Error opening file: ", [Error]),
|
||||
{error, Error}
|
||||
end.
|
||||
|
||||
appconf() ->
|
||||
{{Y, M, D}, {H, MM, S}} = calendar:local_time(),
|
||||
lists:flatten(
|
||||
io_lib:format(
|
||||
"app.~4..0w.~2..0w.~2..0w.~2..0w.~2..0w.~2..0w.conf", [Y, M, D, H, MM, S])).
|
||||
|
||||
cfgfiles(Dir) ->
|
||||
[filename:join(Dir, CfgFile) || CfgFile <- filelib:wildcard("*.conf", Dir)].
|
Loading…
Reference in New Issue