mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-22 14:48:29 +00:00
This commit is contained in:
parent
e575ab8d76
commit
e6d55c4784
@ -4,24 +4,65 @@
|
||||
-- TODO documentation-
|
||||
--
|
||||
settings = {
|
||||
logfile = "/tmp/lsyncd",
|
||||
-- logfile = "/tmp/lsyncd",
|
||||
nodaemon,
|
||||
loglevel = DEBUG,
|
||||
}
|
||||
|
||||
|
||||
------
|
||||
-- for testing purposes
|
||||
--
|
||||
slower = "sleep 10"
|
||||
slowbash = {
|
||||
startup = function(source, target)
|
||||
log(NORMAL, "cp -r from "..source.." -> "..target)
|
||||
return 0;
|
||||
end,
|
||||
|
||||
create = function(source, path, name, target)
|
||||
local src = source..path..name
|
||||
log(NORMAL, "create from "..source..path..name.." -> "..target..path..name)
|
||||
return exec("/bin/bash", "-c", slower.."&& cp '$1' '$2'", "/bin/bash",
|
||||
source..path..name, target..path..name)
|
||||
end,
|
||||
|
||||
attrib = function(source, path, name, target)
|
||||
-- ignore attribs
|
||||
return 0
|
||||
end,
|
||||
|
||||
delete = function(source, path, name, target)
|
||||
log(NORMAL, "delete "..target..path..name)
|
||||
return exec("/bin/bash", "-c", slower.." && rm $1", "/bin/bash",
|
||||
target..path..name)
|
||||
end,
|
||||
|
||||
move = function(source, path, name, destpath, destname, target)
|
||||
log(NORMAL, "move from " .. destination .. "/" .. path)
|
||||
return exec("/bin/bash", "-c", "sleep " .. slowsec .. " && rm $1 $2", "/bin/bash",
|
||||
source .. "/" .. path, target .. "/" .. path)
|
||||
end,
|
||||
}
|
||||
|
||||
-----
|
||||
-- lsyncd classic - sync with rsync
|
||||
--
|
||||
-- All functions return the pid of a spawned process
|
||||
-- or 0 if they didn't exec something.
|
||||
rsync = {
|
||||
default = function(source, path, target)
|
||||
----
|
||||
-- Called for every sync/target pair on startup
|
||||
startup = function(source, target)
|
||||
log(NORMAL, "startup recursive rsync: " .. source .. " -> " .. target)
|
||||
return exec("/usr/bin/rsync", "-ltrs", source, target)
|
||||
end,
|
||||
|
||||
default = function(source, target, path)
|
||||
return exec("/usr/bin/rsync", "--delete", "-ltds", source .. "/" .. path, target .. "/" .. path)
|
||||
end
|
||||
}
|
||||
|
||||
directory("s", "d", rsync)
|
||||
sync(slowbash, "s", "d")
|
||||
|
||||
----
|
||||
-- Called for every source .. target pair on startup
|
||||
-- Returns the pid of a spawned process
|
||||
-- Return 0 if you dont exec something.
|
||||
function startup_action(source, target)
|
||||
log(NORMAL, "startup recursive rsync: " .. source .. " -> " .. target)
|
||||
return exec("/usr/bin/rsync", "-ltrs", source, target)
|
||||
end
|
||||
|
||||
|
4
lsyncd.c
4
lsyncd.c
@ -1017,10 +1017,6 @@ main(int argc, char *argv[])
|
||||
lua_getglobal(L, "lsyncd_initialize");
|
||||
lua_call(L, 0, 0);
|
||||
|
||||
/* let lua code will perform startup calls like recursive rsync */
|
||||
lua_getglobal(L, "startup");
|
||||
lua_call(L, 0, 0);
|
||||
|
||||
masterloop(L);
|
||||
|
||||
/* cleanup */
|
||||
|
50
lsyncd.lua
50
lsyncd.lua
@ -22,7 +22,8 @@ lsyncd_version = "2.0b1"
|
||||
|
||||
----
|
||||
-- Shortcuts (which user is supposed to be able to use them as well)
|
||||
log = lsyncd.log
|
||||
log = lsyncd.log
|
||||
exec = lsyncd.exec
|
||||
|
||||
----
|
||||
-- Table of all directories to watch,
|
||||
@ -147,6 +148,18 @@ function lsyncd_initialize()
|
||||
-- and add the dir watch inclusively all subdirs
|
||||
attend_dir(asrc, "", target, nil)
|
||||
end
|
||||
|
||||
log(NORMAL, "--- startup ---")
|
||||
local pids = { }
|
||||
local pid
|
||||
for i, o in ipairs(origins) do
|
||||
if (o.actions.startup ~= nil) then
|
||||
pid = o.actions.startup(o.source, o.targetident)
|
||||
end
|
||||
table.insert(pids, pid)
|
||||
end
|
||||
lsyncd.wait_pids(pids, "startup_collector")
|
||||
log(NORMAL, "--- Entering normal operation with " .. #watches .. " monitored directories ---")
|
||||
end
|
||||
|
||||
----
|
||||
@ -239,15 +252,18 @@ end
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
----
|
||||
-- Adds one directory to be watched.
|
||||
-- Adds one directory (incl. subdir) to be synchronized.
|
||||
-- Users primary configuration device.
|
||||
--
|
||||
-- @param TODO
|
||||
--
|
||||
function directory(source_dir, target_identifier, actions)
|
||||
local o = { source = source_dir, targetident = target_identifier, actions = actions}
|
||||
function sync(actions, source_dir, target_identifier)
|
||||
local o = { actions = actions,
|
||||
source = source_dir,
|
||||
targetident = target_identifier,
|
||||
}
|
||||
table.insert(origins, o)
|
||||
return o
|
||||
return
|
||||
end
|
||||
|
||||
----
|
||||
@ -259,29 +275,5 @@ function default_overflow()
|
||||
end
|
||||
overflow = default_overflow
|
||||
|
||||
-----
|
||||
-- Called by core after initialization.
|
||||
--
|
||||
-- Default function will start an simultanous action for every
|
||||
-- source -> destination pair. And waits for these processes to finish
|
||||
--
|
||||
-- The user can override this function by specifing his/her own
|
||||
-- "startup". (and yet may still call default startup)
|
||||
--
|
||||
function default_startup()
|
||||
log(NORMAL, "--- startup ---")
|
||||
local pids = { }
|
||||
for i, o in ipairs(origins) do
|
||||
startup_action(o.source, o.targetident)
|
||||
table.insert(pids, pid)
|
||||
end
|
||||
lsyncd.wait_pids(pids, "startup_collector")
|
||||
log(NORMAL, "--- Entering normal operation with " .. #watches .. " monitored directories ---")
|
||||
end
|
||||
startup = default_startup
|
||||
|
||||
|
||||
----
|
||||
-- other functions the user might want to use
|
||||
exec = lsyncd.exec
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user