lsyncd/examples/lalarm.lua
2010-11-30 17:08:15 +00:00

43 lines
1.0 KiB
Lua

-----
-- User configuration file for lsyncd.
--
-- While this example does not do anything it shows
-- how user custom alarms can be now. It will log
-- "Beep!" every 5 seconds.
--
----
-- Defines a function to be called when the alarm
-- is raised.
-- @param timestamp ... timestamp this alarm was registered with
-- @param extra ... a free token to store anything in it.
-- here used as string.
--
lalarm = {
init = function(inlet)
-- creates the first alarm in 5 seconds from now.
inlet.alarm(now() + 5, "Beep")
end,
-- called when alarms ring
alarm = function(inlet, timestamp, extra)
log("Normal", extra)
spawn(inlet.createBlanketEvent(), "/bin/echo", "hello")
-- creates a new alarm in 5 seconds after this one rang
inlet.alarm(timestamp + 5, extra)
end,
action = function(inlet)
-- just discard anything that happes in source dir.
inlet.discardEvent(inlet.getEvent())
end
}
-----
-- Lsyncd needs to watch something, altough in this minimal example
-- it isnt used.
sync{source="/usr/local/etc/", lalarm }