2011-02-08 15:10:48 +00:00
|
|
|
-----
|
|
|
|
-- User configuration file for lsyncd.
|
2011-02-08 15:16:29 +00:00
|
|
|
-- This needs lsyncd >= 2.0.3
|
2011-02-08 15:10:48 +00:00
|
|
|
--
|
|
|
|
-- This configuration will execute a command on the remote host
|
|
|
|
-- after every successfullycompleted rsync operation.
|
|
|
|
-- for example to restart servlets on the target host or so.
|
|
|
|
|
|
|
|
local rsyncpostcmd = {
|
|
|
|
|
|
|
|
-- based on default rsync.
|
|
|
|
default.rsync,
|
|
|
|
|
2015-01-30 07:25:53 +00:00
|
|
|
checkgauge = {
|
|
|
|
default.rsync.checkgauge,
|
|
|
|
host = true,
|
|
|
|
targetdir = true,
|
|
|
|
target = true,
|
|
|
|
postcmd = true,
|
|
|
|
},
|
|
|
|
|
2011-02-08 15:21:39 +00:00
|
|
|
-- for this config it is important to keep maxProcesses at 1, so
|
|
|
|
-- the postcmds will only be spawned after the rsync completed
|
2011-02-08 15:10:48 +00:00
|
|
|
maxProcesses = 1,
|
|
|
|
|
|
|
|
-- called whenever something is to be done
|
|
|
|
action = function(inlet)
|
|
|
|
local event = inlet.getEvent()
|
2011-02-08 15:16:29 +00:00
|
|
|
local config = inlet.getConfig()
|
2011-02-08 15:10:48 +00:00
|
|
|
-- 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
|
2011-02-08 15:21:39 +00:00
|
|
|
-- uses rawget to test if "isPostcmd" has been set without
|
2011-02-08 15:10:48 +00:00
|
|
|
-- triggering an error if not.
|
2011-02-08 15:16:29 +00:00
|
|
|
local isPostcmd = rawget(event, "isPostcmd")
|
2015-01-30 07:08:58 +00:00
|
|
|
if isPostcmd then
|
2012-09-07 06:58:44 +00:00
|
|
|
spawn(event, "/usr/bin/ssh",
|
2011-02-08 15:21:39 +00:00
|
|
|
config.host, config.postcmd)
|
2011-02-08 15:10:48 +00:00
|
|
|
return
|
|
|
|
else
|
|
|
|
-- this is the startup, forwards it to default routine.
|
2012-09-07 06:58:44 +00:00
|
|
|
return default.rsync.action(inlet)
|
2011-02-08 15:10:48 +00:00
|
|
|
end
|
|
|
|
error("this should never be reached")
|
|
|
|
end
|
2011-02-08 15:21:39 +00:00
|
|
|
-- for any other event, a blanket event is created that
|
2011-02-08 15:10:48 +00:00
|
|
|
-- will stack on the queue and do the postcmd when its finished
|
|
|
|
local sync = inlet.createBlanketEvent()
|
2011-02-08 15:16:29 +00:00
|
|
|
sync.isPostcmd = true
|
|
|
|
-- the original event is simply forwarded to the normal action handler
|
2011-02-08 15:10:48 +00:00
|
|
|
return default.rsync.action(inlet)
|
|
|
|
end,
|
|
|
|
|
2011-02-08 15:16:29 +00:00
|
|
|
-- called when a process exited.
|
|
|
|
-- this can be a rsync command, the startup rsync or the postcmd
|
2011-02-08 15:10:48 +00:00
|
|
|
collect = function(agent, exitcode)
|
2011-02-08 15:16:29 +00:00
|
|
|
-- 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
|
2011-02-08 15:10:48 +00:00
|
|
|
if exitcode == 255 then
|
|
|
|
return "again"
|
|
|
|
end
|
|
|
|
return
|
|
|
|
else
|
|
|
|
--- everything else, forward to default collection handler
|
|
|
|
return default.collect(agent,exitcode)
|
|
|
|
end
|
|
|
|
error("this should never be reached")
|
2014-01-03 08:11:48 +00:00
|
|
|
end,
|
2011-02-08 15:10:48 +00:00
|
|
|
|
2011-02-08 15:16:29 +00:00
|
|
|
-- called before anything else
|
|
|
|
-- builds the target from host and targetdir
|
2015-01-30 07:12:02 +00:00
|
|
|
prepare = function(config, level, skipTarget)
|
2011-02-08 15:10:48 +00:00
|
|
|
if not config.host then
|
|
|
|
error("rsyncpostcmd neets 'host' configured", 4)
|
|
|
|
end
|
|
|
|
if not config.targetdir then
|
|
|
|
error("rsyncpostcmd needs 'targetdir' configured", 4)
|
|
|
|
end
|
|
|
|
if not config.target then
|
|
|
|
config.target = config.host .. ":" .. config.targetdir
|
|
|
|
end
|
2015-01-30 07:12:02 +00:00
|
|
|
return default.rsync.prepare(config, level, skipTarget)
|
2011-02-08 15:10:48 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sync {
|
2012-09-07 06:58:44 +00:00
|
|
|
rsyncpostcmd,
|
2011-02-08 15:10:48 +00:00
|
|
|
source = "src",
|
|
|
|
host = "beetle",
|
|
|
|
targetdir = "/path/to/trg",
|
|
|
|
postcmd = "/usr/local/bin/restart-servelt.sh",
|
|
|
|
}
|
|
|
|
|