Skip to content

Commit

Permalink
Fix Tarantool's start in background
Browse files Browse the repository at this point in the history
$ 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 1b33012 (origin/gh-5999)
Author: Roman Khabibov <roman.habibov@tarantool.org>
Date:   Tue Mar 9 16:47:11 2021 +0300

    box: set box.cfg options via environment variables

commit 9db64ae
Author: Roman Tsisyk <roman@tarantool.org>
Date:   Thu Aug 17 16:59:16 2017 +0300

    lua: add '-' command line option

Closes #6128
  • Loading branch information
ligurio committed Nov 2, 2021
1 parent ee5f3eb commit cc6172d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lua/init.c
Expand Up @@ -36,6 +36,7 @@
#endif

#include <lua.h>
#include <stdio.h>
#include <lauxlib.h>
#include <lualib.h>
#include <lj_cdata.h>
Expand All @@ -45,6 +46,8 @@
#include "version.h"
#include "backtrace.h"
#include "coio.h"
#include <stdio.h>
#include "cfg.h"
#include "lua/fiber.h"
#include "lua/fiber_cond.h"
#include "lua/fiber_channel.h"
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions test/box-tap/gh-5602-environment-cfg-test-cases.lua
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions test/box-tap/gh-5602-environment-vars-cfg.test.lua
Expand Up @@ -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)
Expand Down

0 comments on commit cc6172d

Please sign in to comment.