mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 14:43:09 +00:00
working on the new rsync config system
This commit is contained in:
parent
6f90c19196
commit
a6b49c8650
@ -30,150 +30,137 @@ if default.direct then
|
||||
error('default-direct already loaded')
|
||||
end
|
||||
|
||||
default.direct = {
|
||||
local 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()
|
||||
default.direct = direct
|
||||
|
||||
if event.etype == 'Create' then
|
||||
if event.isdir then
|
||||
spawn(
|
||||
event,
|
||||
'/bin/mkdir',
|
||||
event.targetPath
|
||||
)
|
||||
else
|
||||
-- 'cp -t', not supported on OSX
|
||||
spawn(
|
||||
event,
|
||||
'/bin/cp',
|
||||
event.sourcePath,
|
||||
event.targetPathdir
|
||||
)
|
||||
end
|
||||
elseif event.etype == 'Modify' then
|
||||
if event.isdir then
|
||||
error("Do not know how to handle 'Modify' on dirs")
|
||||
end
|
||||
spawn(event,
|
||||
--
|
||||
-- Spawns rsync for a list of events
|
||||
--
|
||||
direct.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
|
||||
spawn(
|
||||
event,
|
||||
'/bin/mkdir',
|
||||
event.targetPath
|
||||
)
|
||||
else
|
||||
-- 'cp -t', not supported on OSX
|
||||
spawn(
|
||||
event,
|
||||
'/bin/cp',
|
||||
event.sourcePath,
|
||||
event.targetPathdir
|
||||
)
|
||||
elseif event.etype == 'Delete' then
|
||||
if not config.delete then
|
||||
inlet.discardEvent(event)
|
||||
end
|
||||
|
||||
local tp = event.targetPath
|
||||
-- extra security check
|
||||
if tp == '' or tp == '/' or not tp then
|
||||
error('Refusing to erase your harddisk!')
|
||||
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, '"')
|
||||
end
|
||||
elseif event.etype == 'Modify' then
|
||||
if event.isdir then
|
||||
error("Do not know how to handle 'Modify' on dirs")
|
||||
end
|
||||
spawn(event,
|
||||
'/bin/cp',
|
||||
event.sourcePath,
|
||||
event.targetPathdir
|
||||
)
|
||||
elseif event.etype == 'Delete' then
|
||||
if not config.delete then
|
||||
inlet.discardEvent(event)
|
||||
end
|
||||
end,
|
||||
|
||||
-----
|
||||
-- Called when collecting a finished child process
|
||||
--
|
||||
collect = function(agent, exitcode)
|
||||
local config = agent.config
|
||||
local tp = event.targetPath
|
||||
-- extra security check
|
||||
if tp == '' or tp == '/' or not tp then
|
||||
error('Refusing to erase your harddisk!')
|
||||
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]
|
||||
if rc == 'ok' then
|
||||
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
|
||||
elseif rc == 'again' then
|
||||
if settings.insist then
|
||||
log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
|
||||
else
|
||||
log('Error', 'Temporary or permanent failure on startup of "',
|
||||
agent.source, '". Terminating since "insist" is not set.');
|
||||
terminate(-1) -- ERRNO
|
||||
end
|
||||
elseif rc == 'die' then
|
||||
log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
|
||||
--
|
||||
-- Called when collecting a finished child process
|
||||
--
|
||||
direct.collect = function(agent, exitcode)
|
||||
local config = agent.config
|
||||
|
||||
if not agent.isList and agent.etype == 'Init' then
|
||||
local rc = config.rsyncExitCodes[exitcode]
|
||||
if rc == 'ok' then
|
||||
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
|
||||
elseif rc == 'again' then
|
||||
if settings.insist then
|
||||
log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
|
||||
else
|
||||
log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
|
||||
rc = 'die'
|
||||
log('Error', 'Temporary or permanent failure on startup of "',
|
||||
agent.source, '". Terminating since "insist" is not set.');
|
||||
terminate(-1) -- ERRNO
|
||||
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
|
||||
return rc
|
||||
end
|
||||
|
||||
-- everything else is just as it is,
|
||||
-- there is no network to retry something.
|
||||
return
|
||||
end,
|
||||
-- everything else is just as it is,
|
||||
-- there is no network to retry something.
|
||||
return
|
||||
end
|
||||
|
||||
-----
|
||||
-- Spawns the recursive startup sync
|
||||
-- (currently) identical to default rsync.
|
||||
--
|
||||
init = default.rsync.init,
|
||||
--
|
||||
-- Spawns the recursive startup sync
|
||||
-- (currently) identical to default rsync.
|
||||
--
|
||||
direct.init = default.rsync.init
|
||||
|
||||
-----
|
||||
-- Checks the configuration.
|
||||
--
|
||||
prepare = function(config)
|
||||
if not config.target then
|
||||
error('default.direct needs "target".', 4)
|
||||
end
|
||||
--
|
||||
-- Checks the configuration.
|
||||
--
|
||||
direct.prepare = function( config, level )
|
||||
|
||||
if config.rsyncOps then
|
||||
error('did you mean rsyncOpts with "t"?', 4)
|
||||
end
|
||||
end,
|
||||
default.rsync.prepare( config, level + 1 )
|
||||
|
||||
-----
|
||||
-- Default delay is very short.
|
||||
--
|
||||
delay = 1,
|
||||
end
|
||||
|
||||
------
|
||||
-- Let the core not split move events.
|
||||
--
|
||||
onMove = true,
|
||||
--
|
||||
-- Default delay is very short.
|
||||
--
|
||||
direct.delay = 1
|
||||
|
||||
-----
|
||||
-- The rsync binary called.
|
||||
--
|
||||
rsync = default.rsync.rsync,
|
||||
--
|
||||
-- Let the core not split move events.
|
||||
--
|
||||
direct.onMove = true
|
||||
|
||||
-----
|
||||
-- By default do deletes.
|
||||
--
|
||||
delete = true,
|
||||
--
|
||||
-- By default do deletes.
|
||||
--
|
||||
direct.delete = true
|
||||
|
||||
-----
|
||||
-- rsync exit codes
|
||||
--
|
||||
rsyncExitCodes = default.rsyncExitCodes,
|
||||
--
|
||||
-- On many system multiple disk operations just rather slow down
|
||||
-- than speed up.
|
||||
|
||||
-----
|
||||
-- On many system multiple disk operations just rather slow down
|
||||
-- than speed up.
|
||||
|
||||
maxProcesses = 1,
|
||||
}
|
||||
direct.maxProcesses = 1
|
||||
|
@ -296,8 +296,6 @@ rsync.prepare = function(
|
||||
skipTarget -- used by rsyncssh, do not check for target
|
||||
)
|
||||
|
||||
level = level or 4
|
||||
|
||||
--
|
||||
-- First let default.prepare test the checkgauge
|
||||
--
|
||||
@ -363,11 +361,42 @@ rsync.prepare = function(
|
||||
)
|
||||
end
|
||||
|
||||
--
|
||||
-- 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 shortFlags = {
|
||||
@ -401,27 +430,42 @@ rsync.prepare = function(
|
||||
local shorts = { '-' }
|
||||
local shortsN = 2
|
||||
|
||||
if config.rsync._extra then
|
||||
for k, v in ipairs( config.rsync._extra ) do
|
||||
if crsync._extra then
|
||||
for k, v in ipairs( crsync._extra ) do
|
||||
computed[ computedN ] = v
|
||||
computedN = computedN + 1
|
||||
end
|
||||
end
|
||||
|
||||
for k, flag in pairs( shortFlags ) do
|
||||
if config.rsync[k] then
|
||||
if crsync[ k ] then
|
||||
shorts[ shortsN ] = flag
|
||||
shortsN = shortsN + 1
|
||||
end
|
||||
end
|
||||
|
||||
if config.rsync.rsh then
|
||||
computed[ computedN ] = '--rsh=' + config.rsync.rsh
|
||||
if crsync.devices and crsync.specials then
|
||||
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
|
||||
end
|
||||
|
||||
if config.rsync.rsync_path then
|
||||
computed[ computedN ] = '--rsync-path=' + config.rsync.rsync_path
|
||||
if crsync.rsync_path then
|
||||
computed[ computedN ] = '--rsync-path=' + crsync.rsync_path
|
||||
computedN = computedN + 1
|
||||
end
|
||||
|
||||
|
@ -39,25 +39,27 @@ default.rsyncssh = rsyncssh
|
||||
rsyncssh.checkgauge = {
|
||||
|
||||
-- unsets the inherited value of from default.rsync
|
||||
target = false,
|
||||
onMove = true,
|
||||
target = false,
|
||||
onMove = true,
|
||||
|
||||
-- rsyncssh users host and targetdir
|
||||
host = true,
|
||||
targetdir = true,
|
||||
host = true,
|
||||
targetdir = true,
|
||||
sshExitCodes = true,
|
||||
rsyncExitCodes = true,
|
||||
|
||||
-- ssh settings
|
||||
ssh = {
|
||||
binary = true,
|
||||
port = true,
|
||||
_extra = true
|
||||
binary = true,
|
||||
port = true,
|
||||
_extra = true
|
||||
},
|
||||
|
||||
-- xargs settings
|
||||
xargs = {
|
||||
binary = true,
|
||||
delimiter = true,
|
||||
_extra = true
|
||||
binary = true,
|
||||
delimiter = true,
|
||||
_extra = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,9 +256,9 @@ end
|
||||
--
|
||||
-- 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
|
||||
error('default.rsyncssh needs "host" configured', 4)
|
||||
|
@ -352,6 +352,6 @@ default.prepare = function( config, level )
|
||||
return
|
||||
end
|
||||
|
||||
check( config, gauge, '', level or 2 )
|
||||
check( config, gauge, '', level + 1 )
|
||||
end
|
||||
|
||||
|
@ -2286,7 +2286,7 @@ local Syncs = ( function( )
|
||||
if type( config.prepare ) == 'function' then
|
||||
|
||||
-- prepare is given a writeable copy of config
|
||||
config.prepare( config )
|
||||
config.prepare( config, 4 )
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user