Permalink
Browse files

feature-script_dir: script_dir configuration option added.

script_dir option defines path to a directory which contains the init.lua file.
  • Loading branch information...
1 parent 1261b51 commit a8a6b2619e06105a0cebd37a1a1770d900ed1c50 @pmwkaa pmwkaa committed May 3, 2012
Showing with 59 additions and 2 deletions.
  1. +3 −0 cfg/core_cfg.cfg_tmpl
  2. +39 −0 cfg/tarantool_box_cfg.c
  3. +3 −0 cfg/tarantool_box_cfg.h
  4. +11 −2 src/tarantool_lua.m
  5. +1 −0 test/box/admin.result
  6. +2 −0 test/box/configuration.result
@@ -41,6 +41,9 @@ snap_dir=".", ro
# WAL directory (where WALs get saved/read)
wal_dir=".", ro
+# script directory (where init.lua is expected to be)
+script_dir=".", ro
+
# name of pid file
pid_file="tarantool.pid", ro
@@ -41,6 +41,7 @@ init_tarantool_cfg(tarantool_cfg *c) {
c->work_dir = NULL;
c->snap_dir = NULL;
c->wal_dir = NULL;
+ c->script_dir = NULL;
c->pid_file = NULL;
c->logger = NULL;
c->logger_nonblock = false;
@@ -88,6 +89,8 @@ fill_default_tarantool_cfg(tarantool_cfg *c) {
if (c->snap_dir == NULL) return CNF_NOMEMORY;
c->wal_dir = strdup(".");
if (c->wal_dir == NULL) return CNF_NOMEMORY;
+ c->script_dir = strdup(".");
+ if (c->script_dir == NULL) return CNF_NOMEMORY;
c->pid_file = strdup("tarantool.pid");
if (c->pid_file == NULL) return CNF_NOMEMORY;
c->logger = NULL;
@@ -190,6 +193,9 @@ static NameAtom _name__snap_dir[] = {
static NameAtom _name__wal_dir[] = {
{ "wal_dir", -1, NULL }
};
+static NameAtom _name__script_dir[] = {
+ { "script_dir", -1, NULL }
+};
static NameAtom _name__pid_file[] = {
{ "pid_file", -1, NULL }
};
@@ -540,6 +546,18 @@ acceptValue(tarantool_cfg* c, OptDef* opt, int check_rdonly) {
if (opt->paramValue.stringval && c->wal_dir == NULL)
return CNF_NOMEMORY;
}
+ else if ( cmpNameAtoms( opt->name, _name__script_dir) ) {
+ if (opt->paramType != stringType )
+ return CNF_WRONGTYPE;
+ c->__confetti_flags &= ~CNF_FLAG_STRUCT_NOTSET;
+ errno = 0;
+ if (check_rdonly && ( (opt->paramValue.stringval == NULL && c->script_dir == NULL) || strcmp(opt->paramValue.stringval, c->script_dir) != 0))
+ return CNF_RDONLY;
+ if (c->script_dir) free(c->script_dir);
+ c->script_dir = (opt->paramValue.stringval) ? strdup(opt->paramValue.stringval) : NULL;
+ if (opt->paramValue.stringval && c->script_dir == NULL)
+ return CNF_NOMEMORY;
+ }
else if ( cmpNameAtoms( opt->name, _name__pid_file) ) {
if (opt->paramType != stringType )
return CNF_WRONGTYPE;
@@ -1229,6 +1247,7 @@ typedef enum IteratorState {
S_name__work_dir,
S_name__snap_dir,
S_name__wal_dir,
+ S_name__script_dir,
S_name__pid_file,
S_name__logger,
S_name__logger_nonblock,
@@ -1426,6 +1445,16 @@ tarantool_cfg_iterator_next(tarantool_cfg_iterator_t* i, tarantool_cfg *c, char
return NULL;
}
snprintf(buf, PRINTBUFLEN-1, "wal_dir");
+ i->state = S_name__script_dir;
+ return buf;
+ case S_name__script_dir:
+ *v = (c->script_dir) ? strdup(c->script_dir) : NULL;
+ if (*v == NULL && c->script_dir) {
+ free(i);
+ out_warning(CNF_NOMEMORY, "No memory to output value");
+ return NULL;
+ }
+ snprintf(buf, PRINTBUFLEN-1, "script_dir");
i->state = S_name__pid_file;
return buf;
case S_name__pid_file:
@@ -1986,6 +2015,9 @@ dup_tarantool_cfg(tarantool_cfg* dst, tarantool_cfg* src) {
if (dst->wal_dir) free(dst->wal_dir);dst->wal_dir = src->wal_dir == NULL ? NULL : strdup(src->wal_dir);
if (src->wal_dir != NULL && dst->wal_dir == NULL)
return CNF_NOMEMORY;
+ if (dst->script_dir) free(dst->script_dir);dst->script_dir = src->script_dir == NULL ? NULL : strdup(src->script_dir);
+ if (src->script_dir != NULL && dst->script_dir == NULL)
+ return CNF_NOMEMORY;
if (dst->pid_file) free(dst->pid_file);dst->pid_file = src->pid_file == NULL ? NULL : strdup(src->pid_file);
if (src->pid_file != NULL && dst->pid_file == NULL)
return CNF_NOMEMORY;
@@ -2093,6 +2125,8 @@ destroy_tarantool_cfg(tarantool_cfg* c) {
free(c->snap_dir);
if (c->wal_dir != NULL)
free(c->wal_dir);
+ if (c->script_dir != NULL)
+ free(c->script_dir);
if (c->pid_file != NULL)
free(c->pid_file);
if (c->logger != NULL)
@@ -2231,6 +2265,11 @@ cmp_tarantool_cfg(tarantool_cfg* c1, tarantool_cfg* c2, int only_check_rdonly) {
return diff;
}
+ if (confetti_strcmp(c1->script_dir, c2->script_dir) != 0) {
+ snprintf(diff, PRINTBUFLEN - 1, "%s", "c->script_dir");
+
+ return diff;
+}
if (confetti_strcmp(c1->pid_file, c2->pid_file) != 0) {
snprintf(diff, PRINTBUFLEN - 1, "%s", "c->pid_file");
@@ -94,6 +94,9 @@ typedef struct tarantool_cfg {
/* WAL directory (where WALs get saved/read) */
char* wal_dir;
+ /* script directory (where init.lua is expected to be) */
+ char* script_dir;
+
/* name of pid file */
char* pid_file;
View
@@ -48,6 +48,7 @@
/** tarantool start-up file */
#define TARANTOOL_LUA_INIT_SCRIPT "init.lua"
+struct tarantool_cfg cfg;
struct lua_State *tarantool_L;
/* Remember the output of the administrative console in the
@@ -1082,8 +1083,16 @@ static char format_to_opcode(char format)
{
struct lua_State *L = (struct lua_State *) L_ptr;
struct stat st;
+
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s",
+ ((cfg.script_dir) ? cfg.script_dir : "."),
+ TARANTOOL_LUA_INIT_SCRIPT);
+
+ say_info("trying to load %s", path);
+
/* checking that Lua start-up file exist. */
- if (stat(TARANTOOL_LUA_INIT_SCRIPT, &st)) {
+ if (stat(path, &st)) {
/*
* File doesn't exist. It's OK, tarantool may not have
* start-up file.
@@ -1092,7 +1101,7 @@ static char format_to_opcode(char format)
}
/* execute start-up file */
- if (tarantool_lua_dofile(L, TARANTOOL_LUA_INIT_SCRIPT))
+ if (tarantool_lua_dofile(L, path))
panic("%s", lua_tostring(L, -1));
}
@@ -42,6 +42,7 @@ configuration:
work_dir: (null)
snap_dir: "."
wal_dir: "."
+ script_dir: "."
pid_file: "box.pid"
logger: "cat - >> tarantool.log"
logger_nonblock: "true"
@@ -20,6 +20,7 @@ configuration:
work_dir: (null)
snap_dir: "."
wal_dir: "."
+ script_dir: "."
pid_file: "box.pid"
logger: "cat - >> tarantool.log"
logger_nonblock: "true"
@@ -83,6 +84,7 @@ configuration:
work_dir: (null)
snap_dir: "."
wal_dir: "."
+ script_dir: "."
pid_file: "box.pid"
logger: "cat - >> tarantool.log"
logger_nonblock: "true"

0 comments on commit a8a6b26

Please sign in to comment.