mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-08 09:18:30 +00:00
cleanups
This commit is contained in:
parent
155dbf155c
commit
20edbe5f6e
@ -72,17 +72,22 @@ rsyncssh.checkgauge = {
|
|||||||
--
|
--
|
||||||
-- Spawns rsync for a list of events
|
-- Spawns rsync for a list of events
|
||||||
--
|
--
|
||||||
rsyncssh.action = function( inlet )
|
rsyncssh.action = function
|
||||||
|
(
|
||||||
|
inlet
|
||||||
|
)
|
||||||
local event, event2 = inlet.getEvent( )
|
local event, event2 = inlet.getEvent( )
|
||||||
|
|
||||||
local config = inlet.getConfig( )
|
local config = inlet.getConfig( )
|
||||||
|
|
||||||
-- makes move local on target host
|
-- makes move local on target host
|
||||||
-- if the move fails, it deletes the source
|
-- if the move fails, it deletes the source
|
||||||
if event.etype == 'Move' then
|
if event.etype == 'Move'
|
||||||
|
then
|
||||||
local path1 = config.targetdir .. event.path
|
local path1 = config.targetdir .. event.path
|
||||||
|
|
||||||
local path2 = config.targetdir .. event2.path
|
local path2 = config.targetdir .. event2.path
|
||||||
|
|
||||||
path1 = "'" .. path1:gsub ('\'', '\'"\'"\'') .. "'"
|
path1 = "'" .. path1:gsub ('\'', '\'"\'"\'') .. "'"
|
||||||
path2 = "'" .. path2:gsub ('\'', '\'"\'"\'') .. "'"
|
path2 = "'" .. path2:gsub ('\'', '\'"\'"\'') .. "'"
|
||||||
|
|
||||||
@ -181,10 +186,12 @@ rsyncssh.action = function( inlet )
|
|||||||
local elist = inlet.getEvents(
|
local elist = inlet.getEvents(
|
||||||
function( e )
|
function( e )
|
||||||
-- TODO use a table
|
-- TODO use a table
|
||||||
return e.etype ~= 'Move' and
|
return(
|
||||||
e.etype ~= 'Delete' and
|
e.etype ~= 'Move'
|
||||||
e.etype ~= 'Init' and
|
and e.etype ~= 'Delete'
|
||||||
e.etype ~= 'Blanket'
|
and e.etype ~= 'Init'
|
||||||
|
and e.etype ~= 'Blanket'
|
||||||
|
)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -193,13 +200,16 @@ rsyncssh.action = function( inlet )
|
|||||||
--
|
--
|
||||||
-- removes trailing slashes from dirs.
|
-- removes trailing slashes from dirs.
|
||||||
--
|
--
|
||||||
for k, v in ipairs( paths ) do
|
for k, v in ipairs( paths )
|
||||||
if string.byte( v, -1 ) == 47 then
|
do
|
||||||
|
if string.byte( v, -1 ) == 47
|
||||||
|
then
|
||||||
paths[k] = string.sub( v, 1, -2 )
|
paths[k] = string.sub( v, 1, -2 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local sPaths = table.concat( paths, '\n' )
|
local sPaths = table.concat( paths, '\n' )
|
||||||
|
|
||||||
local zPaths = table.concat( paths, '\000' )
|
local zPaths = table.concat( paths, '\000' )
|
||||||
|
|
||||||
log(
|
log(
|
||||||
@ -223,59 +233,76 @@ end
|
|||||||
-----
|
-----
|
||||||
-- Called when collecting a finished child process
|
-- Called when collecting a finished child process
|
||||||
--
|
--
|
||||||
rsyncssh.collect = function( agent, exitcode )
|
rsyncssh.collect = function
|
||||||
|
(
|
||||||
|
agent,
|
||||||
|
exitcode
|
||||||
|
)
|
||||||
local config = agent.config
|
local config = agent.config
|
||||||
|
|
||||||
if not agent.isList and agent.etype == 'Init' then
|
if not agent.isList and agent.etype == 'Init'
|
||||||
|
then
|
||||||
local rc = config.rsyncExitCodes[exitcode]
|
local rc = config.rsyncExitCodes[exitcode]
|
||||||
|
|
||||||
if rc == 'ok' then
|
if rc == 'ok'
|
||||||
|
then
|
||||||
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
|
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
|
||||||
elseif rc == 'again' then
|
elseif rc == 'again'
|
||||||
if settings('insist') then
|
then
|
||||||
log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
|
if settings('insist')
|
||||||
|
then
|
||||||
|
log( 'Normal', 'Retrying startup of "',agent.source,'": ', exitcode )
|
||||||
else
|
else
|
||||||
log('Error', 'Temporary or permanent failure on startup of "',
|
log( 'Error', 'Temporary or permanent failure on startup of "',
|
||||||
agent.source, '". Terminating since "insist" is not set.');
|
agent.source, '". Terminating since "insist" is not set.' );
|
||||||
terminate(-1) -- ERRNO
|
terminate( -1 ) -- ERRNO
|
||||||
end
|
end
|
||||||
|
elseif rc == 'die'
|
||||||
elseif rc == 'die' then
|
then
|
||||||
log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
|
log( 'Error', 'Failure on startup of "',agent.source,'": ', exitcode )
|
||||||
else
|
else
|
||||||
log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
|
log( 'Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode )
|
||||||
|
|
||||||
rc = 'die'
|
rc = 'die'
|
||||||
end
|
end
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if agent.isList then
|
if agent.isList
|
||||||
local rc = config.rsyncExitCodes[exitcode]
|
then
|
||||||
if rc == 'ok' then
|
local rc = config.rsyncExitCodes[ exitcode ]
|
||||||
log('Normal', 'Finished (list): ',exitcode)
|
|
||||||
elseif rc == 'again' then
|
if rc == 'ok'
|
||||||
log('Normal', 'Retrying (list): ',exitcode)
|
then
|
||||||
elseif rc == 'die' then
|
log( 'Normal', 'Finished (list): ', exitcode )
|
||||||
log('Error', 'Failure (list): ', exitcode)
|
elseif rc == 'again'
|
||||||
|
then
|
||||||
|
log( 'Normal', 'Retrying (list): ', exitcode )
|
||||||
|
elseif rc == 'die'
|
||||||
|
then
|
||||||
|
log( 'Error', 'Failure (list): ', exitcode )
|
||||||
else
|
else
|
||||||
log('Error', 'Unknown exitcode (list): ',exitcode)
|
log( 'Error', 'Unknown exitcode (list): ', exitcode )
|
||||||
|
|
||||||
rc = 'die'
|
rc = 'die'
|
||||||
end
|
end
|
||||||
return rc
|
return rc
|
||||||
else
|
else
|
||||||
local rc = config.sshExitCodes[exitcode]
|
local rc = config.sshExitCodes[exitcode]
|
||||||
|
|
||||||
if rc == 'ok' then
|
if rc == 'ok'
|
||||||
log('Normal', 'Finished ',agent.etype,' ',agent.sourcePath,': ',exitcode)
|
then
|
||||||
elseif rc == 'again' then
|
log( 'Normal', 'Finished ',agent.etype,' ',agent.sourcePath,': ',exitcode )
|
||||||
log('Normal', 'Retrying ',agent.etype,' ',agent.sourcePath,': ',exitcode)
|
elseif rc == 'again'
|
||||||
elseif rc == 'die' then
|
then
|
||||||
log('Normal', 'Failure ',agent.etype,' ',agent.sourcePath,': ',exitcode)
|
log( 'Normal', 'Retrying ',agent.etype,' ',agent.sourcePath,': ',exitcode )
|
||||||
|
elseif rc == 'die'
|
||||||
|
then
|
||||||
|
log( 'Normal', 'Failure ',agent.etype,' ',agent.sourcePath,': ',exitcode )
|
||||||
else
|
else
|
||||||
log('Error', 'Unknown exitcode ',agent.etype,' ',agent.sourcePath,': ',exitcode)
|
log( 'Error', 'Unknown exitcode ',agent.etype,' ',agent.sourcePath,': ',exitcode )
|
||||||
|
|
||||||
rc = 'die'
|
rc = 'die'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -287,8 +314,11 @@ end
|
|||||||
--
|
--
|
||||||
-- checks the configuration.
|
-- checks the configuration.
|
||||||
--
|
--
|
||||||
rsyncssh.prepare = function( config, level )
|
rsyncssh.prepare = function
|
||||||
|
(
|
||||||
|
config,
|
||||||
|
level
|
||||||
|
)
|
||||||
default.rsync.prepare( config, level + 1, true )
|
default.rsync.prepare( config, level + 1, true )
|
||||||
|
|
||||||
if not config.host
|
if not config.host
|
||||||
@ -458,20 +488,20 @@ rsyncssh.sshExitCodes = default.sshExitCodes
|
|||||||
rsyncssh.xargs = {
|
rsyncssh.xargs = {
|
||||||
|
|
||||||
--
|
--
|
||||||
-- the binary called (on target host)
|
-- the binary called ( on target host )
|
||||||
binary =
|
--
|
||||||
'/usr/bin/xargs',
|
binary = '/usr/bin/xargs',
|
||||||
|
|
||||||
--
|
--
|
||||||
-- delimiter, uses null by default, you might want to override this for older
|
-- delimiter, uses null by default, you might want to override this for older
|
||||||
-- by for example '\n'
|
-- by for example '\n'
|
||||||
delimiter =
|
--
|
||||||
'\000',
|
delimiter = '\000',
|
||||||
|
|
||||||
--
|
--
|
||||||
-- extra parameters
|
-- extra parameters
|
||||||
_extra =
|
--
|
||||||
{ '-0', 'rm -rf' }
|
_extra = { '-0', 'rm -rf' }
|
||||||
}
|
}
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -484,31 +514,26 @@ rsyncssh.ssh = {
|
|||||||
--
|
--
|
||||||
-- the binary called
|
-- the binary called
|
||||||
--
|
--
|
||||||
binary =
|
binary = '/usr/bin/ssh',
|
||||||
'/usr/bin/ssh',
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- if set adds this key to ssh
|
-- if set adds this key to ssh
|
||||||
--
|
--
|
||||||
identityFile =
|
identityFile = nil,
|
||||||
nil,
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- if set adds this special options to ssh
|
-- if set adds this special options to ssh
|
||||||
--
|
--
|
||||||
options =
|
options = nil,
|
||||||
nil,
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- if set connect to this port
|
-- if set connect to this port
|
||||||
--
|
--
|
||||||
port =
|
port = nil,
|
||||||
nil,
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- extra parameters
|
-- extra parameters
|
||||||
--
|
--
|
||||||
_extra =
|
_extra = { }
|
||||||
{ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user