Skip to content
Snippets Groups Projects
Commit b6e7eb4b authored by Max Melentiev's avatar Max Melentiev Committed by Kirill Yukhin
Browse files

tarantoolctl: allow to start instances with delayed box.cfg{}

`tarantoolctl start` patches box.cfg two times:
1) before the init script to set default values and enforce some others,
2) after the init script to prevent changing a pid_file in runtime.

The second patching fails if an init file does not call
box.cfg{} before it's finished. This can take a place in apps with
managed instances which receive configuration from external server.

This patch moves the second patching into the box.cfg
wrapper created during the first patching. So the second patching
is performed only after box.cfg{} was invoked, so it does not fail anymore.

However there is relatively minor flaw for applications that
invoke box.cfg{} after init script is finished:
`tarantoolctl start` goes to background only when box.cfg{} is called.
Though this is not the case for daemon management systems like systemd,
as they handle backgrounding on their side

Fixes #4435

@TarantoolBot document
Title: tarantoolctl allows to start instances without a box.cfg{}

tarantoolctl now works for instances without box.cfg{} or
with delayed box.cfg{} call. This can be managed instances which receive
configuration from external server.

For such instances `tarantoolctl start` goes to background when
box.cfg{} is called, so it will wait until options for box.cfg are received.
However this is not the case for daemon management systems like systemd,
as they handle backgrounding on their side.
parent 75b14a35
No related branches found
No related tags found
No related merge requests found
......@@ -483,6 +483,16 @@ local function wrapper_cfg(cfg)
os.exit(1)
end
-- Prevent overwriting pid_file in subsequent box.cfg calls.
local box_cfg_mt = getmetatable(box.cfg)
local orig_cfg_call = box_cfg_mt.__call
box_cfg_mt.__call = function(old_cfg, new_cfg)
if old_cfg.pid_file ~= nil and new_cfg ~= nil and new_cfg.pid_file ~= nil then
new_cfg.pid_file = old_cfg.pid_file
end
orig_cfg_call(old_cfg, new_cfg)
end
return data
end
......@@ -547,18 +557,6 @@ local function start()
end
os.exit(1)
end
local box_cfg_mt = getmetatable(box.cfg)
if box_cfg_mt == nil then
log.error('box.cfg() is not called in an instance file')
os.exit(1)
end
local old_call = box_cfg_mt.__call
box_cfg_mt.__call = function(old_cfg, cfg)
if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then
cfg.pid_file = old_cfg.pid_file
end
old_call(old_cfg, cfg)
end
return 0
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment