mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-01 07:50:51 +00:00
Update index.md
This commit is contained in:
parent
938f2614af
commit
c5462daad0
|
@ -8,18 +8,21 @@ Layer 2 allows you to create one process per one event. However, as with default
|
||||||
For example this is the action used by default.rsync:
|
For example this is the action used by default.rsync:
|
||||||
|
|
||||||
{% highlight lua %}
|
{% highlight lua %}
|
||||||
action = function(inlet)
|
action = function( inlet )
|
||||||
local elist = inlet.getEvents()
|
local elist = inlet.getEvents( )
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig( )
|
||||||
local paths = elist.getPaths()
|
local paths = elist.getPaths( )
|
||||||
log("Normal", "rsyncing list\n", paths)
|
log( "Normal", "rsyncing list\n", table.concat( paths, '\n' ) )
|
||||||
spawn(elist, "/usr/bin/rsync",
|
spawn(elist, '/usr/bin/rsync',
|
||||||
"<", paths,
|
'<', table.concat( paths, '\000' ),
|
||||||
"--delete",
|
'--delete',
|
||||||
config.rsyncOpts .. "d",
|
config.rsync._computed,
|
||||||
"--include-from=-",
|
'--from0',
|
||||||
"--exclude=*",
|
'--include-from=-',
|
||||||
config.source, config.target)
|
'--exclude=*',
|
||||||
|
config.source,
|
||||||
|
config.target
|
||||||
|
)
|
||||||
end
|
end
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
|
@ -52,18 +55,20 @@ Layer 2 functions is nothing else than following layer 1 action loaded by the de
|
||||||
-----
|
-----
|
||||||
-- Default action calls user scripts on**** functions.
|
-- Default action calls user scripts on**** functions.
|
||||||
--
|
--
|
||||||
action = function(inlet)
|
action = function( inlet )
|
||||||
-- in case of moves getEvent returns the origin and destination of the move
|
-- in case of moves getEvent returns the origin and destination of the move
|
||||||
local event, event2 = inlet.getEvent()
|
local event, event2 = inlet.getEvent( )
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig( )
|
||||||
local func = config["on".. event.etype]
|
local func = config[ 'on'.. event.etype ]
|
||||||
if func then
|
if func
|
||||||
func(event, event2)
|
then
|
||||||
|
func( event, event2 )
|
||||||
end
|
end
|
||||||
-- if function didnt change the wait status its not interested
|
-- if function didnt change the wait status its not interested
|
||||||
-- in this event -> drop it.
|
-- in this event -> drop it.
|
||||||
if event.status == "wait" then
|
if event.status == "wait"
|
||||||
inlet.discardEvent(event)
|
then
|
||||||
|
inlet.discardEvent( event )
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
@ -76,16 +81,18 @@ Other than `action` Lsyncd calls `init` for each sync{} on initialization. This
|
||||||
-----
|
-----
|
||||||
-- called on (re)initalizing of lsyncd.
|
-- called on (re)initalizing of lsyncd.
|
||||||
--
|
--
|
||||||
init = function(inlet)
|
init = function( inlet )
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig( )
|
||||||
-- calls a startup if provided by user script.
|
-- calls a startup if provided by user script.
|
||||||
if type(config.onStartup) == "function" then
|
if type( config.onStartup ) == "function"
|
||||||
local event = inlet.createBlanketEvent()
|
then
|
||||||
config.onStartup(event)
|
local event = inlet.createBlanketEvent( )
|
||||||
if event.status == "wait" then
|
config.onStartup( event )
|
||||||
|
if event.status == 'wait'
|
||||||
|
then
|
||||||
-- user script did not spawn anything
|
-- user script did not spawn anything
|
||||||
-- thus the blanket event is deleted again.
|
-- thus the blanket event is deleted again.
|
||||||
inlet.discardEvent(event)
|
inlet.discardEvent( event )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -97,19 +104,24 @@ As another example this is the init of `default.rsync`. As specialty it changes
|
||||||
-----
|
-----
|
||||||
-- Spawns the recursive startup sync
|
-- Spawns the recursive startup sync
|
||||||
--
|
--
|
||||||
init = function(inlet)
|
init = function( inlet )
|
||||||
local config = inlet.getConfig()
|
local config = inlet.getConfig( )
|
||||||
local event = inlet.createBlanketEvent()
|
local event = inlet.createBlanketEvent( )
|
||||||
if string.sub(config.target, -1) ~= "/" then
|
if string.sub(config.target, -1) ~= "/"
|
||||||
|
then
|
||||||
config.target = config.target .. "/"
|
config.target = config.target .. "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
log("Normal", "recursive startup rsync: ", config.source,
|
log("Normal", "recursive startup rsync: ", config.source,
|
||||||
" -> ", config.target)
|
" -> ", config.target)
|
||||||
spawn(event, "/usr/bin/rsync",
|
|
||||||
|
spawn(event,
|
||||||
|
"/usr/bin/rsync",
|
||||||
"--delete",
|
"--delete",
|
||||||
config.rsyncOpts .. "r",
|
config.rsync._computed .. "r",
|
||||||
config.source,
|
config.source,
|
||||||
config.target)
|
config.target
|
||||||
|
)
|
||||||
end,
|
end,
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user