mirror of https://github.com/octoleo/lsyncd.git
This commit is contained in:
parent
22af17bc64
commit
3482ce51ef
25
lsyncd.c
25
lsyncd.c
|
@ -97,10 +97,17 @@ static struct settings {
|
||||||
* LOG_ERROR errors only
|
* LOG_ERROR errors only
|
||||||
*/
|
*/
|
||||||
int log_level;
|
int log_level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if lsyncd shall not daemonize.
|
||||||
|
*/
|
||||||
|
bool nodaemon;
|
||||||
|
|
||||||
} settings = {
|
} settings = {
|
||||||
.log_file = NULL,
|
.log_file = NULL,
|
||||||
.log_syslog = false,
|
.log_syslog = false,
|
||||||
.log_level = 0,
|
.log_level = 0,
|
||||||
|
.nodaemon = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -950,6 +957,24 @@ l_configure(lua_State *L)
|
||||||
* from this on log to configurated log end instead of
|
* from this on log to configurated log end instead of
|
||||||
* stdout/stderr */
|
* stdout/stderr */
|
||||||
running = true;
|
running = true;
|
||||||
|
if (!settings.nodaemon) {
|
||||||
|
if (!settings.log_file) {
|
||||||
|
settings.log_syslog = true;
|
||||||
|
}
|
||||||
|
if (daemon(0, 0)) {
|
||||||
|
logstring("Error", "Failed to daemonize");
|
||||||
|
exit(-1); //ERRNO
|
||||||
|
}
|
||||||
|
is_daemon = true;
|
||||||
|
}
|
||||||
|
} else if (!strcmp(command, "nodaemon")) {
|
||||||
|
settings.nodaemon = true;
|
||||||
|
} else if (!strcmp(command, "logfile")) {
|
||||||
|
const char * file = luaL_checkstring(L, 2);
|
||||||
|
if (settings.log_file) {
|
||||||
|
free(settings.log_file);
|
||||||
|
}
|
||||||
|
settings.log_file = s_strdup(file);
|
||||||
} else {
|
} else {
|
||||||
printlogf(L, "Error",
|
printlogf(L, "Error",
|
||||||
"Internal error, unknown parameter in l_configure(%s)",
|
"Internal error, unknown parameter in l_configure(%s)",
|
||||||
|
|
70
lsyncd.lua
70
lsyncd.lua
|
@ -1922,19 +1922,26 @@ end
|
||||||
function runner.help()
|
function runner.help()
|
||||||
io.stdout:write(
|
io.stdout:write(
|
||||||
[[
|
[[
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
run a config file:
|
runs a config file:
|
||||||
lsyncd [OPTIONS] [CONFIG-FILE]
|
lsyncd [OPTIONS] [CONFIG-FILE]
|
||||||
|
|
||||||
default rsync behaviour:
|
default rsync behaviour:
|
||||||
lsyncd [OPTIONS] -rsync [SOURCE] [TARGET1] [TARGET2] ...
|
lsyncd [OPTIONS] -rsync [SOURCE] [TARGET]
|
||||||
|
|
||||||
|
default rssh behaviour:
|
||||||
|
lsyncd [OPTIONS] -rssh [SOURCE] [HOST] [TARGETDIR]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-help Shows this
|
-help Shows this
|
||||||
-log all Logs everything
|
-log all Logs everything (debug)
|
||||||
-log scarce Logs errors only
|
-log scarce Logs errors only
|
||||||
-log [Category] Turns on logging for a debug category
|
-log [Category] Turns on logging for a debug category
|
||||||
|
-logfile FILE Writes log to FILE (DEFAULT: uses syslog)
|
||||||
|
-nodaemon Does not detach and logs to stdout/stderr
|
||||||
-runner FILE Loads lsyncds lua part from FILE
|
-runner FILE Loads lsyncds lua part from FILE
|
||||||
|
-version Prints versions and exits
|
||||||
|
|
||||||
LICENSE:
|
LICENSE:
|
||||||
GPLv2 or any later version.
|
GPLv2 or any later version.
|
||||||
|
@ -1964,6 +1971,10 @@ function runner.configure(args)
|
||||||
-- log is handled by core already.
|
-- log is handled by core already.
|
||||||
log =
|
log =
|
||||||
{1, nil},
|
{1, nil},
|
||||||
|
logfile =
|
||||||
|
{1, function(file)
|
||||||
|
clSettings.logfile=file
|
||||||
|
end},
|
||||||
nodaemon =
|
nodaemon =
|
||||||
{0, function()
|
{0, function()
|
||||||
clSettings.nodaemon=true
|
clSettings.nodaemon=true
|
||||||
|
@ -1974,10 +1985,15 @@ function runner.configure(args)
|
||||||
table.insert(clSettings.syncs, {"rsync", src, trg})
|
table.insert(clSettings.syncs, {"rsync", src, trg})
|
||||||
end},
|
end},
|
||||||
rssh =
|
rssh =
|
||||||
{2, function(src, trg)
|
{3, function(src, host, tdir)
|
||||||
clSettings.syncs = clSettings.syncs or {}
|
clSettings.syncs = clSettings.syncs or {}
|
||||||
table.insert(clSettings.syncs, {"rssh", src, trg})
|
table.insert(clSettings.syncs, {"rssh", src, host, tdir})
|
||||||
end},
|
end},
|
||||||
|
version =
|
||||||
|
{0, function()
|
||||||
|
io.stdout:write("Version: ", lsyncd_version,"\n")
|
||||||
|
os.exit(0)
|
||||||
|
end}
|
||||||
}
|
}
|
||||||
-- filled with all args that were non --options
|
-- filled with all args that were non --options
|
||||||
local nonopts = {}
|
local nonopts = {}
|
||||||
|
@ -1994,6 +2010,10 @@ function runner.configure(args)
|
||||||
end
|
end
|
||||||
local o = options[a]
|
local o = options[a]
|
||||||
if o then
|
if o then
|
||||||
|
if i + o[1] > #args then
|
||||||
|
log("Error",a," needs ",o[1]," arguments")
|
||||||
|
os.exit(-1) -- ERRNO
|
||||||
|
end
|
||||||
if o[2] then
|
if o[2] then
|
||||||
if o[1] == 0 then
|
if o[1] == 0 then
|
||||||
o[2]()
|
o[2]()
|
||||||
|
@ -2001,6 +2021,8 @@ function runner.configure(args)
|
||||||
o[2](args[i + 1])
|
o[2](args[i + 1])
|
||||||
elseif o[1] == 2 then
|
elseif o[1] == 2 then
|
||||||
o[2](args[i + 1], args[i + 2])
|
o[2](args[i + 1], args[i + 2])
|
||||||
|
elseif o[1] == 3 then
|
||||||
|
o[2](args[i + 1], args[i + 2], args[i + 3])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
i = i + o[1]
|
i = i + o[1]
|
||||||
|
@ -2038,14 +2060,44 @@ function runner.initialize()
|
||||||
-- creates settings if user didnt
|
-- creates settings if user didnt
|
||||||
settings = settings or {}
|
settings = settings or {}
|
||||||
|
|
||||||
-- TODO X2
|
|
||||||
|
|
||||||
-- From this point on, no globals may be created anymore
|
-- From this point on, no globals may be created anymore
|
||||||
lockGlobals()
|
lockGlobals()
|
||||||
|
|
||||||
|
-- Copies simple settings to "key=true" settings.
|
||||||
|
for k, v in ipairs(settings) do
|
||||||
|
if settings[v] then
|
||||||
|
log("Error", "Double setting '"..v.."'")
|
||||||
|
os.exit(-1) -- ERRNO
|
||||||
|
end
|
||||||
|
settings[v]=true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- All command line settings overwrite settings
|
||||||
|
for k, v in pairs(clSettings) do
|
||||||
|
if k ~= "syncs" then
|
||||||
|
settings[k]=v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- adds syncs specified by command line.
|
||||||
|
if clSettings.syncs then
|
||||||
|
for _, s in ipairs(clSettings.syncs) do
|
||||||
|
if s[1] == "rsync" then
|
||||||
|
sync{default.rsync, source=s[2], target=s[3]}
|
||||||
|
elseif s[1] == "rssh" then
|
||||||
|
sync{default.rssh, source=s[2], host=s[3], targetdir=s[4]}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if settings.nodaemon then
|
||||||
|
lsyncd.configure("nodaemon")
|
||||||
|
end
|
||||||
|
if settings.logfile then
|
||||||
|
lsyncd.configure("logfile", settings.logfile)
|
||||||
|
end
|
||||||
-----
|
-----
|
||||||
-- transfers some defaults to settings
|
-- transfers some defaults to settings
|
||||||
-- TODO: loop
|
|
||||||
if settings.statusIntervall == nil then
|
if settings.statusIntervall == nil then
|
||||||
settings.statusIntervall = default.statusIntervall
|
settings.statusIntervall = default.statusIntervall
|
||||||
end
|
end
|
||||||
|
@ -2054,7 +2106,7 @@ function runner.initialize()
|
||||||
if Syncs.size() == 0 then
|
if Syncs.size() == 0 then
|
||||||
log("Error", "Nothing to watch!")
|
log("Error", "Nothing to watch!")
|
||||||
log("Error", "Use sync(SOURCE, TARGET, BEHAVIOR) in your config file.");
|
log("Error", "Use sync(SOURCE, TARGET, BEHAVIOR) in your config file.");
|
||||||
terminate(-1) -- ERRNO
|
os.exit(-1) -- ERRNO
|
||||||
end
|
end
|
||||||
|
|
||||||
-- from now on use logging as configured instead of stdout/err.
|
-- from now on use logging as configured instead of stdout/err.
|
||||||
|
|
Loading…
Reference in New Issue