add onepass option to exit after initial sync

This commit is contained in:
Bernard Gray 2018-12-05 17:05:18 +11:00
parent 42413cabbe
commit 188b691bea
4 changed files with 30 additions and 1 deletions

View File

@ -120,7 +120,14 @@ default.collect = function
agent.target,
' finished.'
)
if settings('onepass')
then
log(
'Normal',
'onepass config set, exiting'
)
terminate( 0 )
end
return 'ok'
elseif rc == 'again'
then

View File

@ -91,6 +91,7 @@ struct settings settings = {
.log_facility = LOG_USER,
.log_level = LOG_NOTICE,
.nodaemon = false,
.onepass = false,
};
@ -1630,6 +1631,10 @@ l_configure( lua_State *L )
{
settings.nodaemon = true;
}
else if( !strcmp( command, "onepass" ) )
{
settings.onepass = true;
}
else if( !strcmp( command, "logfile" ) )
{
const char * file = luaL_checkstring( L, 2 );

View File

@ -57,6 +57,7 @@ extern struct settings {
int log_facility; // The syslog facility
int log_level; // -1 logs everything, 0 normal mode, LOG_ERROR errors only.
bool nodaemon; // True if Lsyncd shall not daemonize.
bool onepass; // True if Lsyncd should exit after first sync pass
char * pidfile; // If not NULL Lsyncd writes its pid into this file.
} settings;

View File

@ -75,6 +75,7 @@ local settingsCheckgauge =
logfile = true,
pidfile = true,
nodaemon = true,
onepass = true,
statusFile = true,
statusInterval = true,
logfacility = true,
@ -4614,6 +4615,7 @@ OPTIONS:
-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
-onepass Sync once and exit
-pidfile FILE Writes Lsyncds PID into FILE
-runner FILE Loads Lsyncds lua part from FILE
-version Prints versions and exits
@ -4729,6 +4731,15 @@ function runner.configure( args, monitors )
end
},
onepass =
{
0,
function
( )
clSettings.onepass = true
end
},
pidfile =
{
1,
@ -4968,6 +4979,11 @@ function runner.initialize( firstTime )
lsyncd.configure( 'nodaemon' )
end
if uSettings.onepass
then
lsyncd.configure( 'onepass' )
end
if uSettings.logfile
then
lsyncd.configure( 'logfile', uSettings.logfile )