This commit is contained in:
Axel Kittenberger 2018-03-09 13:32:58 +01:00
parent 465deb1549
commit f77df7f3e2

View File

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