mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-11-10 15:20:58 +00:00
This commit is contained in:
parent
219da8d754
commit
f59ca19ff3
@ -17,23 +17,12 @@ prefix = "sleep 1 && "
|
|||||||
slowbash = {
|
slowbash = {
|
||||||
delay = 5,
|
delay = 5,
|
||||||
|
|
||||||
init = function(inlet)
|
onStartup = function(event)
|
||||||
local c = inlet.getConfig()
|
local config = event.config
|
||||||
log("Normal", "cp -r from ", c.source, " -> ", c.target)
|
log("Normal", "cp -r from ", config.source, " -> ", config.target)
|
||||||
|
spawnShell(event,
|
||||||
-- collect gets called when spawned process finished
|
|
||||||
local function collect(event, exitcode)
|
|
||||||
if exitcode == 0 then
|
|
||||||
log("Normal", "Startup of '",c.source,"' finished.")
|
|
||||||
else
|
|
||||||
log("Error", "Failure on startup of '",c.source,"'.")
|
|
||||||
terminate(-1) -- ERRNO
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
spawnShell(inlet.createBlanketEvent(), collect,
|
|
||||||
[[if [ "$(ls -A $1)" ]; then cp -r "$1"* "$2"; fi]],
|
[[if [ "$(ls -A $1)" ]; then cp -r "$1"* "$2"; fi]],
|
||||||
c.source, c.target)
|
config.source, config.target)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
onCreate = function(event)
|
onCreate = function(event)
|
||||||
@ -56,9 +45,9 @@ slowbash = {
|
|||||||
spawnShell(event, "ok", prefix..[[rm -rf "$1"]], t)
|
spawnShell(event, "ok", prefix..[[rm -rf "$1"]], t)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
onMove = function(event, eventd)
|
onMove = function(originEvent, destinationEvent)
|
||||||
local t = event.targetPathname
|
local t = originEvent.targetPathname
|
||||||
local d = eventd.targetPathname
|
local d = destinationEvent.targetPathname
|
||||||
log("Normal", "Spawning Move from ",t," to ",d)
|
log("Normal", "Spawning Move from ",t," to ",d)
|
||||||
spawnShell(event, "ok", prefix..[[mv "$1" "$2"]], t, d)
|
spawnShell(event, "ok", prefix..[[mv "$1" "$2"]], t, d)
|
||||||
end,
|
end,
|
||||||
|
50
lsyncd.lua
50
lsyncd.lua
@ -495,17 +495,10 @@ local Sync = (function()
|
|||||||
if delay.status ~= "active" then
|
if delay.status ~= "active" then
|
||||||
error("internal fail, collecting a non-active process")
|
error("internal fail, collecting a non-active process")
|
||||||
end
|
end
|
||||||
if delay.collector then
|
InletControl.setSync(self)
|
||||||
local cr
|
|
||||||
if type(delay.collector) == "function" then
|
|
||||||
InletControl.setSync(self)
|
|
||||||
cr = delay.collector(InletControl.toEvent(delay), exitcode)
|
|
||||||
else
|
|
||||||
cr = delay.collector
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- TODO honor return codes of the collector
|
|
||||||
|
|
||||||
|
local rc = self.config.collector(InletControl.toEvent(delay), exitcode)
|
||||||
|
-- TODO honor return codes of the collector
|
||||||
-- Remove the delay.
|
-- Remove the delay.
|
||||||
local found
|
local found
|
||||||
for i, d in ipairs(self.delays) do
|
for i, d in ipairs(self.delays) do
|
||||||
@ -1363,12 +1356,11 @@ end
|
|||||||
-- @param binary binary to call
|
-- @param binary binary to call
|
||||||
-- @param ... arguments
|
-- @param ... arguments
|
||||||
--
|
--
|
||||||
function spawn(agent, collector, binary, ...)
|
function spawn(agent, binary, ...)
|
||||||
local pid = lsyncd.exec(binary, ...)
|
local pid = lsyncd.exec(binary, ...)
|
||||||
if pid and pid > 0 then
|
if pid and pid > 0 then
|
||||||
local sync, delay = InletControl.getInterior(agent)
|
local sync, delay = InletControl.getInterior(agent)
|
||||||
delay.status = "active"
|
delay.status = "active"
|
||||||
delay.collector = collector
|
|
||||||
sync.processes[pid] = delay
|
sync.processes[pid] = delay
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1376,8 +1368,8 @@ end
|
|||||||
-----
|
-----
|
||||||
-- Spawns a child process using bash.
|
-- Spawns a child process using bash.
|
||||||
--
|
--
|
||||||
function spawnShell(agent, collector, command, ...)
|
function spawnShell(agent, command, ...)
|
||||||
return spawn(agent, collector, "/bin/sh", "-c", command, "/bin/sh", ...)
|
return spawn(agent, "/bin/sh", "-c", command, "/bin/sh", ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1483,6 +1475,36 @@ default = {
|
|||||||
Delete = { Attrib = 1, Modify = 1, Create = 3, Delete = 1 },
|
Delete = { Attrib = 1, Modify = 1, Create = 3, Delete = 1 },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Called when collecting a finished child process
|
||||||
|
--
|
||||||
|
collect = function(event, exitcode)
|
||||||
|
if event.etype == "Blanket" then
|
||||||
|
if exitcode == 0 then
|
||||||
|
log("Normal", "Startup of '",c.source,"' finished.")
|
||||||
|
else
|
||||||
|
log("Error", "Failure on startup of '",c.source,"'.")
|
||||||
|
terminate(-1) -- ERRNO
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
log("Normal", "Finished ",event.atype,
|
||||||
|
" on ",event.sourcename," = ",exitcode)
|
||||||
|
end,
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- called on (re)initalizing of lsyncd.
|
||||||
|
--
|
||||||
|
init = function(inlet)
|
||||||
|
local config = inlet.getConfig()
|
||||||
|
|
||||||
|
-- creates a prior startup if configured
|
||||||
|
if type(config.onStartup) == "function" then
|
||||||
|
local event = inlet.createBlanketEvent()
|
||||||
|
config.onStartup(event)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- TODO
|
-- TODO
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user