Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
2bc82ed3
Commit
2bc82ed3
authored
10 years ago
by
Dmitry E. Oboukhov
Browse files
Options
Downloads
Patches
Plain Diff
It is possible to use symlinks to tarantoolctl from /etc/init.d.
parent
0808a001
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
extra/dist/dist.lua
+78
-14
78 additions, 14 deletions
extra/dist/dist.lua
src/lua/fio.cc
+58
-0
58 additions, 0 deletions
src/lua/fio.cc
test/box/fio.result
+36
-1
36 additions, 1 deletion
test/box/fio.result
test/box/fio.test.lua
+12
-1
12 additions, 1 deletion
test/box/fio.test.lua
with
184 additions
and
16 deletions
extra/dist/dist.lua
+
78
−
14
View file @
2bc82ed3
...
...
@@ -77,13 +77,19 @@ returns code C<0>.
Return code != 0 in other cases. Can complain in log (stderr) if pid file
exists and socket doesn't, etc.
=head2 separate instances control
If You use SysV init, You can use symlink from
C<dist.lua> to C</etc/init.d/instance_name[.lua]>.
C<dist.lua> detects if it is started by symlink and uses
instance_name as C<`basename $0 .lua`>.
=head1 COPYRIGHT
Copyright (C) 2010-2013 Tarantool AUTHORS:
please see AUTHORS file.
=cut
]]
...
...
@@ -96,16 +102,56 @@ local console = require 'console'
local
socket
=
require
'socket'
local
ffi
=
require
'ffi'
local
os
=
require
'os'
local
fiber
=
require
'fiber'
ffi
.
cdef
[[ int kill(int pid, int sig); ]]
if
arg
[
1
]
==
nil
or
arg
[
2
]
==
nil
then
log
.
error
(
"Usage: dist.lua {start|stop|logrotate} instance"
)
os.exit
(
-
1
)
local
available_commands
=
{
'start'
,
'stop'
,
'logrotate'
,
'status'
,
'enter'
,
'restart'
}
local
function
usage
()
log
.
error
(
"Usage: %s {%s} instance_name"
,
arg
[
0
],
table.concat
(
available_commands
,
'|'
))
os.exit
(
1
)
end
local
cmd
=
arg
[
1
]
local
instance
=
fio
.
basename
(
arg
[
2
],
'.lua'
)
local
valid_cmd
=
false
for
_
,
vcmd
in
pairs
(
available_commands
)
do
if
cmd
==
vcmd
then
valid_cmd
=
true
break
end
end
if
not
valid_cmd
then
usage
()
end
local
instance
if
arg
[
2
]
==
nil
then
local
istat
=
fio
.
lstat
(
arg
[
0
])
if
istat
==
nil
then
log
.
error
(
"Can't stat %s: %s"
,
arg
[
0
],
errno
.
strerror
())
os.exit
(
1
)
end
if
not
istat
:
is_link
()
then
usage
()
end
instance
=
fio
.
basename
(
arg
[
0
],
'.lua'
)
arg
[
2
]
=
instance
else
instance
=
fio
.
basename
(
arg
[
2
],
'.lua'
)
end
-- shift argv to remove 'tarantoolctl' from arg[0]
for
i
=
0
,
128
do
...
...
@@ -215,20 +261,18 @@ wrapper_cfg = function(cfg)
return
res
end
if
cmd
==
'start'
then
box
.
cfg
=
wrapper_cfg
dofile
(
instance_lua
)
elseif
cmd
==
'stop'
then
function
stop
()
log
.
info
(
"Stopping instance..."
)
if
fio
.
stat
(
force_cfg
.
pid_file
)
==
nil
then
log
.
error
(
"Process is not running (pid: %s)"
,
force_cfg
.
pid_file
)
os.exit
(
-
1
)
return
0
end
local
f
=
fio
.
open
(
force_cfg
.
pid_file
,
'O_RDONLY'
)
if
f
==
nil
then
log
.
error
(
"Can't read pid file %s: %s"
,
force_cfg
.
pid_file
,
errno
.
strerror
())
return
-
1
end
local
str
=
f
:
read
(
64
)
...
...
@@ -239,14 +283,34 @@ elseif cmd == 'stop' then
if
pid
==
nil
or
pid
<=
0
then
log
.
error
(
"Broken pid file %s"
,
force_cfg
.
pid_file
)
fio
.
unlink
(
force_cfg
.
pid_file
)
os.exit
(
-
1
)
return
-
1
end
if
ffi
.
C
.
kill
(
pid
,
15
)
<
0
then
log
.
error
(
"Can't kill process %d: %s"
,
pid
,
errno
.
strerror
())
fio
.
unlink
(
force_cfg
.
pid_file
)
return
-
1
end
os.exit
(
-
1
)
return
0
end
function
start
()
log
.
info
(
"Starting instance..."
)
box
.
cfg
=
wrapper_cfg
dofile
(
instance_lua
)
end
if
cmd
==
'start'
then
os.exit
(
start
())
elseif
cmd
==
'stop'
then
os.exit
(
stop
())
elseif
cmd
==
'restart'
then
stop
()
fiber
.
sleep
(
1
)
start
()
elseif
cmd
==
'logrotate'
then
if
fio
.
stat
(
console_sock
)
==
nil
then
...
...
This diff is collapsed.
Click to expand it.
src/lua/fio.cc
+
58
−
0
View file @
2bc82ed3
...
...
@@ -292,6 +292,32 @@ lbox_fio_pushtimespec(struct lua_State *L, const struct timespec *ts)
lua_settable(L, -3); \
}
#define DEF_STAT_METHOD(method_name, macro_name) \
static int \
lbox_fio_stat_##method_name(struct lua_State *L) \
{ \
if (lua_gettop(L) < 1 || !lua_istable(L, 1)) \
luaL_error(L, "usage: stat:" #method_name "()"); \
lua_pushliteral(L, "mode"); \
lua_gettable(L, 1); \
int mode = lua_tointeger(L, -1); \
lua_pop(L, 1); \
lua_pushboolean(L, macro_name(mode) ? 1 : 0); \
return 1; \
}
DEF_STAT_METHOD
(
is_reg
,
S_ISREG
);
DEF_STAT_METHOD
(
is_dir
,
S_ISDIR
);
DEF_STAT_METHOD
(
is_chr
,
S_ISCHR
);
DEF_STAT_METHOD
(
is_blk
,
S_ISBLK
);
DEF_STAT_METHOD
(
is_fifo
,
S_ISFIFO
);
#ifdef S_ISLNK
DEF_STAT_METHOD
(
is_link
,
S_ISLNK
);
#endif
#ifdef S_ISSOCK
DEF_STAT_METHOD
(
is_sock
,
S_ISSOCK
);
#endif
static
int
lbox_fio_pushstat
(
struct
lua_State
*
L
,
const
struct
stat
*
stat
)
{
...
...
@@ -316,6 +342,34 @@ lbox_fio_pushstat(struct lua_State *L, const struct stat *stat)
PUSHTABLE
(
"mtime"
,
lbox_fio_pushtimespec
,
&
stat
->
st_mtim
);
PUSHTABLE
(
"atime"
,
lbox_fio_pushtimespec
,
&
stat
->
st_atim
);
#endif
int
top
=
lua_gettop
(
L
);
/* metatable for tables *stat */
lua_newtable
(
L
);
lua_pushliteral
(
L
,
"__index"
);
lua_newtable
(
L
);
static
const
struct
luaL_Reg
stat_methods
[]
=
{
{
"is_reg"
,
lbox_fio_stat_is_reg
},
{
"is_dir"
,
lbox_fio_stat_is_dir
},
{
"is_chr"
,
lbox_fio_stat_is_chr
},
{
"is_blk"
,
lbox_fio_stat_is_blk
},
{
"is_fifo"
,
lbox_fio_stat_is_fifo
},
#ifdef S_ISLNK
{
"is_link"
,
lbox_fio_stat_is_link
},
#endif
#ifdef S_ISSOCK
{
"is_sock"
,
lbox_fio_stat_is_sock
},
#endif
{
NULL
,
NULL
}
};
luaL_register
(
L
,
NULL
,
stat_methods
);
lua_settable
(
L
,
-
3
);
lua_setmetatable
(
L
,
top
);
lua_settop
(
L
,
top
);
return
1
;
}
...
...
@@ -525,6 +579,9 @@ lbox_fio_close(struct lua_State *L)
return
1
;
}
void
tarantool_lua_fio_init
(
struct
lua_State
*
L
)
{
...
...
@@ -649,6 +706,7 @@ tarantool_lua_fio_init(struct lua_State *L)
lua_settable
(
L
,
-
3
);
lua_pushliteral
(
L
,
"seek"
);
lua_newtable
(
L
);
PUSHTABLE
(
"SEEK_SET"
,
lua_pushinteger
,
SEEK_SET
);
...
...
This diff is collapsed.
Click to expand it.
test/box/fio.result
+
36
−
1
View file @
2bc82ed3
...
...
@@ -74,10 +74,45 @@ fh1 ~= nil
---
- true
...
fh1:stat().size
f1s = fh1:stat()
---
...
f1s.size
---
- 0
...
f1s.is_reg()
---
- error: 'usage: stat:is_reg()'
...
f1s:is_reg()
---
- true
...
f1s:is_dir()
---
- false
...
f1s:is_link()
---
- false
...
f1s:is_sock()
---
- false
...
f1s:is_fifo()
---
- false
...
f1s:is_chr()
---
- false
...
f1s:is_blk()
---
- false
...
fh1:seek(121)
---
- 121
...
...
This diff is collapsed.
Click to expand it.
test/box/fio.test.lua
+
12
−
1
View file @
2bc82ed3
...
...
@@ -32,7 +32,18 @@ file4 = fio.pathjoin(tmpdir, 'file.4')
fh1
=
fio
.
open
(
file1
,
{
'O_RDWR'
,
'O_TRUNC'
,
'O_CREAT'
},
0777
)
fh1
~=
nil
fh1
:
stat
().
size
f1s
=
fh1
:
stat
()
f1s
.
size
f1s
.
is_reg
()
f1s
:
is_reg
()
f1s
:
is_dir
()
f1s
:
is_link
()
f1s
:
is_sock
()
f1s
:
is_fifo
()
f1s
:
is_chr
()
f1s
:
is_blk
()
fh1
:
seek
(
121
)
fh1
:
stat
().
size
fh1
:
write
(
"Hello, world"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment