mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-12 14:17:47 +00:00
Report tunnel status in status file
This commit is contained in:
parent
60e6505473
commit
f722ec14f8
30
lsyncd.c
30
lsyncd.c
@ -1923,6 +1923,33 @@ l_jiffies_add( lua_State *L )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Adds a number in seconds to a jiffy timestamp.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
l_jiffies_concat( lua_State *L )
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
clock_t *p1 = ( clock_t * ) lua_touserdata( L, 1 );
|
||||||
|
clock_t *p2 = ( clock_t * ) lua_touserdata( L, 2 );
|
||||||
|
|
||||||
|
if( p1 && p2 )
|
||||||
|
{
|
||||||
|
logstring( "Error", "Cannot add two timestamps!" );
|
||||||
|
exit( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
if (p1) {
|
||||||
|
snprintf( buf, sizeof(buf), "%Lf", (long double)(*p1));
|
||||||
|
lua_pushfstring(L, "%s%s", &buf, luaL_checkstring( L, 2));
|
||||||
|
} else {
|
||||||
|
snprintf( buf, sizeof(buf), "%Lf", (long double)(*p2));
|
||||||
|
lua_pushfstring(L, "%s%s", luaL_checkstring( L, 1), &buf);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
| Subracts two jiffy timestamps resulting in a number in seconds
|
| Subracts two jiffy timestamps resulting in a number in seconds
|
||||||
@ -2029,6 +2056,9 @@ register_lsyncd( lua_State *L )
|
|||||||
lua_pushcfunction( L, l_jiffies_eq );
|
lua_pushcfunction( L, l_jiffies_eq );
|
||||||
lua_setfield( L, mt, "__eq" );
|
lua_setfield( L, mt, "__eq" );
|
||||||
|
|
||||||
|
lua_pushcfunction( L, l_jiffies_concat );
|
||||||
|
lua_setfield( L, mt, "__concat" );
|
||||||
|
|
||||||
lua_pop( L, 1 ); // pop(mt)
|
lua_pop( L, 1 ); // pop(mt)
|
||||||
|
|
||||||
#ifdef WITH_INOTIFY
|
#ifdef WITH_INOTIFY
|
||||||
|
48
lsyncd.lua
48
lsyncd.lua
@ -3232,11 +3232,12 @@ Tunnel = (function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
local TUNNEL_STATUS = {
|
local TUNNEL_STATUS = {
|
||||||
DOWN = 0,
|
UNKNOWN = 0,
|
||||||
DISABLED = 1,
|
DOWN = 1,
|
||||||
CONNECTING = 2,
|
DISABLED = 2,
|
||||||
UP = 3,
|
CONNECTING = 3,
|
||||||
RETRY_TIMEOUT = 4,
|
UP = 4,
|
||||||
|
RETRY_TIMEOUT = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
local nextTunnelName = 1
|
local nextTunnelName = 1
|
||||||
@ -3286,6 +3287,16 @@ Tunnel = (function()
|
|||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the status of tunnel as text
|
||||||
|
function Tunnel:statusText()
|
||||||
|
for n, i in pairs(TUNNEL_STATUS) do
|
||||||
|
if self.status == i then
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return TUNNEL_STATUS.UNKNOWN
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Returns next alarm
|
-- Returns next alarm
|
||||||
--
|
--
|
||||||
@ -3555,7 +3566,24 @@ Tunnel = (function()
|
|||||||
return self.status == TUNNEL_STATUS.UP
|
return self.status == TUNNEL_STATUS.UP
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Writes a status report about this tunnel
|
||||||
|
--
|
||||||
|
function Tunnel:statusReport(f)
|
||||||
|
f:write( 'Tunnel: name=', self.options.name, ' status=', self:statusText(), '\n' )
|
||||||
|
|
||||||
|
f:write( 'Running processes: ', self.processes:size( ), '\n')
|
||||||
|
|
||||||
|
for pid, prc in self.processes:walk( )
|
||||||
|
do
|
||||||
|
f:write(" pid=", pid, " type=", prc.type, " started=", ''..prc.started, '\n')
|
||||||
|
end
|
||||||
|
|
||||||
|
f:write( '\n' )
|
||||||
|
end
|
||||||
|
|
||||||
return Tunnel
|
return Tunnel
|
||||||
|
|
||||||
end)() -- Tunnel scope
|
end)() -- Tunnel scope
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -3659,7 +3687,8 @@ local Tunnels = ( function
|
|||||||
size = size,
|
size = size,
|
||||||
invoke = invoke,
|
invoke = invoke,
|
||||||
getAlarm = getAlarm,
|
getAlarm = getAlarm,
|
||||||
killAll = killAll
|
killAll = killAll,
|
||||||
|
statusReport = statusReport
|
||||||
}
|
}
|
||||||
end )( )
|
end )( )
|
||||||
|
|
||||||
@ -4878,6 +4907,13 @@ local StatusFile = ( function
|
|||||||
f:write( '\n' )
|
f:write( '\n' )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i, t in Tunnels.iwalk( )
|
||||||
|
do
|
||||||
|
t:statusReport( f )
|
||||||
|
|
||||||
|
f:write( '\n' )
|
||||||
|
end
|
||||||
|
|
||||||
Inotify.statusReport( f )
|
Inotify.statusReport( f )
|
||||||
|
|
||||||
f:close( )
|
f:close( )
|
||||||
|
Loading…
Reference in New Issue
Block a user