From cc6172def8ff5f1e76530676c4082a78e82631ca Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Sat, 31 Jul 2021 21:57:31 +0300 Subject: [PATCH] Fix Tarantool's start in background $ TT_PID_FILE=tarantool.pid TT_LOG=tarantool.log TT_BACKGROUND=true TT_LISTEN=3301 tarantool -e 'box.cfg{}' $ tail -3 tarantool.log 2021-11-02 16:05:43.672 [2341202] main init.c:696 E> LuajitError: cannot read stdin: Resource temporarily unavailable 2021-11-02 16:05:43.672 [2341202] main F> fatal error, exiting the event loop 2021-11-02 16:05:43.672 [2341202] main F> fatal error, exiting the event loop $ commit 1b330121ec7dafcc0fc6ab63279e0dc52f9f947c (origin/gh-5999) Author: Roman Khabibov Date: Tue Mar 9 16:47:11 2021 +0300 box: set box.cfg options via environment variables commit 9db64aedbfe2815e827fd7ba323cdc84f88c5178 Author: Roman Tsisyk Date: Thu Aug 17 16:59:16 2017 +0300 lua: add '-' command line option Closes #6128 --- src/lua/init.c | 20 +++++++++++++++++++ .../gh-5602-environment-cfg-test-cases.lua | 8 ++++++++ .../gh-5602-environment-vars-cfg.test.lua | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/src/lua/init.c b/src/lua/init.c index 127e935d7021..7b8a54297514 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -36,6 +36,7 @@ #endif #include +#include #include #include #include @@ -45,6 +46,8 @@ #include "version.h" #include "backtrace.h" #include "coio.h" +#include +#include "cfg.h" #include "lua/fiber.h" #include "lua/fiber_cond.h" #include "lua/fiber_channel.h" @@ -647,6 +650,17 @@ run_script_f(va_list ap) is_a_tty = inj->iparam; }); + /* + int background = 0; + lua_getglobal(L, "box"); + if (lua_isnil(L, -1)) { + lua_getfield(L, -1, "cfg"); + if (lua_istable(L, -1)) { + background = cfg_geti("background"); + } + } + */ + if (path && strcmp(path, "-") != 0 && access(path, F_OK) == 0) { /* Execute script. */ if (luaL_loadfile(L, path) != 0) @@ -659,6 +673,12 @@ run_script_f(va_list ap) goto luajit_error; if (lua_main(L, argc, argv) != 0) goto error; + } else if (is_option_e_ran) { + /* Execute a string passed with option -e */ + if (luaL_loadstring(L, "print()") != 0) + goto luajit_error; + if (lua_main(L, argc, argv) != 0) + goto error; } else if (!is_option_e_ran) { interactive = true; } diff --git a/test/box-tap/gh-5602-environment-cfg-test-cases.lua b/test/box-tap/gh-5602-environment-cfg-test-cases.lua index 72031778bad6..e4ee9f96ffec 100755 --- a/test/box-tap/gh-5602-environment-cfg-test-cases.lua +++ b/test/box-tap/gh-5602-environment-cfg-test-cases.lua @@ -67,5 +67,13 @@ if arg[1] == '5' then end test:is(err_msg, exp_err, 'bad strip_core value') end +if arg[1] == '6' then + test:plan(5) + test:ok(status, 'box.cfg is successful') + test:is(box.cfg['listen'], '3301', 'listen') + test:is(box.cfg['background'], true, 'background') + test:is(box.cfg['pid_file'], 'tarantool.pid', 'pid file') + test:is(box.cfg['log'], 'tarantool.log', 'log file') +end os.exit(test:check() and 0 or 1) diff --git a/test/box-tap/gh-5602-environment-vars-cfg.test.lua b/test/box-tap/gh-5602-environment-vars-cfg.test.lua index be1e402eec4a..0f6680702686 100755 --- a/test/box-tap/gh-5602-environment-vars-cfg.test.lua +++ b/test/box-tap/gh-5602-environment-vars-cfg.test.lua @@ -39,6 +39,11 @@ local cases = { 'TT_BACKGROUND=true TT_VINYL_TIMEOUT=60.1', 'TT_SQL_CACHE_SIZE=a', 'TT_STRIP_CORE=a', + ('%s %s %s %s'):format( + 'TT_LISTEN=3301', + 'TT_LOG=tarantool.log', + 'TT_PID_FILE=tarantool.pid', + 'TT_BACKGROUND=true'), } test:plan(1)