working on the new rsync config system

This commit is contained in:
Axel Kittenberger 2012-10-06 14:22:08 +02:00
parent 6f90c19196
commit a6b49c8650
5 changed files with 183 additions and 150 deletions

View File

@ -30,150 +30,137 @@ if default.direct then
error('default-direct already loaded') error('default-direct already loaded')
end end
default.direct = { local direct = { }
-- default.direct = direct
-- Spawns rsync for a list of events
--
action = function(inlet)
-- gets all events ready for syncing
local event, event2 = inlet.getEvent()
local config = inlet.getConfig()
if event.etype == 'Create' then --
if event.isdir then -- Spawns rsync for a list of events
spawn( --
event, direct.action = function(inlet)
'/bin/mkdir', -- gets all events ready for syncing
event.targetPath local event, event2 = inlet.getEvent()
) local config = inlet.getConfig()
else
-- 'cp -t', not supported on OSX if event.etype == 'Create' then
spawn( if event.isdir then
event, spawn(
'/bin/cp', event,
event.sourcePath, '/bin/mkdir',
event.targetPathdir event.targetPath
) )
end else
elseif event.etype == 'Modify' then -- 'cp -t', not supported on OSX
if event.isdir then spawn(
error("Do not know how to handle 'Modify' on dirs") event,
end
spawn(event,
'/bin/cp', '/bin/cp',
event.sourcePath, event.sourcePath,
event.targetPathdir event.targetPathdir
) )
elseif event.etype == 'Delete' then end
if not config.delete then elseif event.etype == 'Modify' then
inlet.discardEvent(event) if event.isdir then
end error("Do not know how to handle 'Modify' on dirs")
end
local tp = event.targetPath spawn(event,
-- extra security check '/bin/cp',
if tp == '' or tp == '/' or not tp then event.sourcePath,
error('Refusing to erase your harddisk!') event.targetPathdir
end )
spawn(event, '/bin/rm', '-rf', tp) elseif event.etype == 'Delete' then
elseif event.etype == 'Move' then if not config.delete then
local tp = event.targetPath
-- extra security check
if tp == '' or tp == '/' or not tp then
error('Refusing to erase your harddisk!')
end
local command = '/bin/mv $1 $2 || /bin/rm -rf $1'
if not config.delete then command = '/bin/mv $1 $2'; end
spawnShell(
event,
command,
event.targetPath,
event2.targetPath)
else
log('Warn', 'ignored an event of type "',event.etype, '"')
inlet.discardEvent(event) inlet.discardEvent(event)
end end
end,
----- local tp = event.targetPath
-- Called when collecting a finished child process -- extra security check
-- if tp == '' or tp == '/' or not tp then
collect = function(agent, exitcode) error('Refusing to erase your harddisk!')
local config = agent.config end
spawn(event, '/bin/rm', '-rf', tp)
elseif event.etype == 'Move' then
local tp = event.targetPath
-- extra security check
if tp == '' or tp == '/' or not tp then
error('Refusing to erase your harddisk!')
end
local command = '/bin/mv $1 $2 || /bin/rm -rf $1'
if not config.delete then command = '/bin/mv $1 $2'; end
spawnShell(
event,
command,
event.targetPath,
event2.targetPath)
else
log('Warn', 'ignored an event of type "',event.etype, '"')
inlet.discardEvent(event)
end
end
if not agent.isList and agent.etype == 'Init' then --
local rc = config.rsyncExitCodes[exitcode] -- Called when collecting a finished child process
if rc == 'ok' then --
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode) direct.collect = function(agent, exitcode)
elseif rc == 'again' then local config = agent.config
if settings.insist then
log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode) if not agent.isList and agent.etype == 'Init' then
else local rc = config.rsyncExitCodes[exitcode]
log('Error', 'Temporary or permanent failure on startup of "', if rc == 'ok' then
agent.source, '". Terminating since "insist" is not set.'); log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
terminate(-1) -- ERRNO elseif rc == 'again' then
end if settings.insist then
elseif rc == 'die' then log('Normal', 'Retrying 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', 'Temporary or permanent failure on startup of "',
rc = 'die' agent.source, '". Terminating since "insist" is not set.');
terminate(-1) -- ERRNO
end end
return rc elseif rc == 'die' then
log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
else
log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
rc = 'die'
end end
return rc
end
-- everything else is just as it is, -- everything else is just as it is,
-- there is no network to retry something. -- there is no network to retry something.
return return
end, end
----- --
-- Spawns the recursive startup sync -- Spawns the recursive startup sync
-- (currently) identical to default rsync. -- (currently) identical to default rsync.
-- --
init = default.rsync.init, direct.init = default.rsync.init
----- --
-- Checks the configuration. -- Checks the configuration.
-- --
prepare = function(config) direct.prepare = function( config, level )
if not config.target then
error('default.direct needs "target".', 4)
end
if config.rsyncOps then default.rsync.prepare( config, level + 1 )
error('did you mean rsyncOpts with "t"?', 4)
end
end,
----- end
-- Default delay is very short.
--
delay = 1,
------ --
-- Let the core not split move events. -- Default delay is very short.
-- --
onMove = true, direct.delay = 1
----- --
-- The rsync binary called. -- Let the core not split move events.
-- --
rsync = default.rsync.rsync, direct.onMove = true
----- --
-- By default do deletes. -- By default do deletes.
-- --
delete = true, direct.delete = true
----- --
-- rsync exit codes -- On many system multiple disk operations just rather slow down
-- -- than speed up.
rsyncExitCodes = default.rsyncExitCodes,
----- direct.maxProcesses = 1
-- On many system multiple disk operations just rather slow down
-- than speed up.
maxProcesses = 1,
}

View File

@ -296,8 +296,6 @@ rsync.prepare = function(
skipTarget -- used by rsyncssh, do not check for target skipTarget -- used by rsyncssh, do not check for target
) )
level = level or 4
-- --
-- First let default.prepare test the checkgauge -- First let default.prepare test the checkgauge
-- --
@ -363,11 +361,42 @@ rsync.prepare = function(
) )
end end
--
-- computes the rsync arguments into one list -- computes the rsync arguments into one list
local rsync = config.rsync; --
local crsync = config.rsync;
rsync._computed = { true } --
local computed = rsync._computed -- everything implied by archive = true
--
local archiveFlags = {
recursive = true,
links = true,
perms = true,
times = true,
group = true,
owner = true,
devices = true,
specials = true,
hard_links = false,
acls = false,
xattrs = false,
}
--
-- if archive given the implications are filled in
--
if crsync.archive then
for k, v in pairs( archiveFlags ) do
if crsync[ k ] == nil then
crsync[ k ] = v
end
end
end
crsync._computed = { true }
local computed = crsync._computed
local computedN = 1 local computedN = 1
local shortFlags = { local shortFlags = {
@ -401,27 +430,42 @@ rsync.prepare = function(
local shorts = { '-' } local shorts = { '-' }
local shortsN = 2 local shortsN = 2
if config.rsync._extra then if crsync._extra then
for k, v in ipairs( config.rsync._extra ) do for k, v in ipairs( crsync._extra ) do
computed[ computedN ] = v computed[ computedN ] = v
computedN = computedN + 1 computedN = computedN + 1
end end
end end
for k, flag in pairs( shortFlags ) do for k, flag in pairs( shortFlags ) do
if config.rsync[k] then if crsync[ k ] then
shorts[ shortsN ] = flag shorts[ shortsN ] = flag
shortsN = shortsN + 1 shortsN = shortsN + 1
end end
end end
if config.rsync.rsh then if crsync.devices and crsync.specials then
computed[ computedN ] = '--rsh=' + config.rsync.rsh shorts[ shortsN ] = 'D'
shortsN = shortsN + 1
else
if crsync.devices then
computed[ computedN ] = '--devices'
computedN = computedN + 1
end
if crsync.specials then
computed[ computedN ] = '--specials'
computedN = computedN + 1
end
end
if crsync.rsh then
computed[ computedN ] = '--rsh=' + crsync.rsh
computedN = computedN + 1 computedN = computedN + 1
end end
if config.rsync.rsync_path then if crsync.rsync_path then
computed[ computedN ] = '--rsync-path=' + config.rsync.rsync_path computed[ computedN ] = '--rsync-path=' + crsync.rsync_path
computedN = computedN + 1 computedN = computedN + 1
end end

View File

@ -39,25 +39,27 @@ default.rsyncssh = rsyncssh
rsyncssh.checkgauge = { rsyncssh.checkgauge = {
-- unsets the inherited value of from default.rsync -- unsets the inherited value of from default.rsync
target = false, target = false,
onMove = true, onMove = true,
-- rsyncssh users host and targetdir -- rsyncssh users host and targetdir
host = true, host = true,
targetdir = true, targetdir = true,
sshExitCodes = true,
rsyncExitCodes = true,
-- ssh settings -- ssh settings
ssh = { ssh = {
binary = true, binary = true,
port = true, port = true,
_extra = true _extra = true
}, },
-- xargs settings -- xargs settings
xargs = { xargs = {
binary = true, binary = true,
delimiter = true, delimiter = true,
_extra = true _extra = true
} }
} }
@ -254,9 +256,9 @@ end
-- --
-- checks the configuration. -- checks the configuration.
-- --
rsyncssh.prepare = function( config ) rsyncssh.prepare = function( config, level )
default.rsync.prepare( config, 5, true ) default.rsync.prepare( config, level + 1, true )
if not config.host then if not config.host then
error('default.rsyncssh needs "host" configured', 4) error('default.rsyncssh needs "host" configured', 4)

View File

@ -352,6 +352,6 @@ default.prepare = function( config, level )
return return
end end
check( config, gauge, '', level or 2 ) check( config, gauge, '', level + 1 )
end end

View File

@ -2286,7 +2286,7 @@ local Syncs = ( function( )
if type( config.prepare ) == 'function' then if type( config.prepare ) == 'function' then
-- prepare is given a writeable copy of config -- prepare is given a writeable copy of config
config.prepare( config ) config.prepare( config, 4 )
end end