This commit is contained in:
Axel Kittenberger 2018-03-09 13:32:58 +01:00
parent 465deb1549
commit f77df7f3e2
1 changed files with 52 additions and 29 deletions

View File

@ -24,24 +24,30 @@ local rsyncpostcmd = {
maxProcesses = 1, maxProcesses = 1,
-- called whenever something is to be done -- called whenever something is to be done
action = function(inlet) action = function
local event = inlet.getEvent() (
local config = inlet.getConfig() inlet
)
local event = inlet.getEvent( )
local config = inlet.getConfig( )
-- if the event is a blanket event and not the startup, -- if the event is a blanket event and not the startup,
-- its there to spawn the webservice restart at the target. -- its there to spawn the webservice restart at the target.
if event.etype == "Blanket" then if event.etype == 'Blanket'
then
-- uses rawget to test if "isPostcmd" has been set without -- uses rawget to test if "isPostcmd" has been set without
-- triggering an error if not. -- triggering an error if not.
local isPostcmd = rawget(event, "isPostcmd") local isPostcmd = rawget( event, 'isPostcmd' )
if isPostcmd then
if isPostcmd
then
spawn(event, "/usr/bin/ssh", spawn(event, "/usr/bin/ssh",
config.host, config.postcmd) config.host, config.postcmd)
return return
else else
-- this is the startup, forwards it to default routine. -- this is the startup, forwards it to default routine.
return default.rsync.action(inlet) return default.rsync.action(inlet)
end end
error("this should never be reached") error( 'this should never be reached' )
end end
-- for any other event, a blanket event is created that -- for any other event, a blanket event is created that
-- will stack on the queue and do the postcmd when its finished -- will stack on the queue and do the postcmd when its finished
@ -53,33 +59,49 @@ local rsyncpostcmd = {
-- called when a process exited. -- called when a process exited.
-- this can be a rsync command, the startup rsync or the postcmd -- this can be a rsync command, the startup rsync or the postcmd
collect = function(agent, exitcode) collect = function
(
agent,
exitcode
)
-- for the ssh commands 255 is network error -> try again -- for the ssh commands 255 is network error -> try again
local isPostcmd = rawget(agent, "isPostcmd") local isPostcmd = rawget( agent, 'isPostcmd' )
if not agent.isList and agent.etype == "Blanket" and isPostcmd then
if exitcode == 255 then if not agent.isList and agent.etype == "Blanket" and isPostcmd
return "again" then
end if exitcode == 255 then return 'again' end
return return
else else
--- everything else, forward to default collection handler --- everything else, forward to default collection handler
return default.collect(agent,exitcode) return default.collect( agent,exitcode )
end end
error("this should never be reached") error( 'this should never be reached' )
end, end,
-- called before anything else -- called before anything else
-- builds the target from host and targetdir -- builds the target from host and targetdir
prepare = function(config, level, skipTarget) prepare = function
if not config.host then (
error("rsyncpostcmd neets 'host' configured", 4) config,
level,
skipTarget
)
if not config.host
then
error( 'rsyncpostcmd needs "host" configured', 4 )
end end
if not config.targetdir then
error("rsyncpostcmd needs 'targetdir' configured", 4) if not config.targetdir
then
error( 'rsyncpostcmd needs "targetdir" configured', 4)
end end
if not config.target then
if not config.target
then
config.target = config.host .. ":" .. config.targetdir config.target = config.host .. ":" .. config.targetdir
end end
return default.rsync.prepare(config, level, skipTarget) return default.rsync.prepare(config, level, skipTarget)
end end
} }
@ -87,9 +109,10 @@ local rsyncpostcmd = {
sync { sync {
rsyncpostcmd, rsyncpostcmd,
source = "src", delay = 3,
host = "beetle", source = '/path/to/src',
targetdir = "/path/to/trg", host = 'localhost',
postcmd = "/usr/local/bin/restart-servelt.sh", targetdir = '/path/to/trg',
postcmd = '/usr/local/bin/dopostcmd',
} }