From 188b691bea28e25e770673ead2a8650d369e4f4a Mon Sep 17 00:00:00 2001 From: Bernard Gray Date: Wed, 5 Dec 2018 17:05:18 +1100 Subject: [PATCH] add onepass option to exit after initial sync --- default.lua | 9 ++++++++- lsyncd.c | 5 +++++ lsyncd.h | 1 + lsyncd.lua | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/default.lua b/default.lua index d689260..8a43598 100644 --- a/default.lua +++ b/default.lua @@ -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 diff --git a/lsyncd.c b/lsyncd.c index 5ab21fd..9bde274 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -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 ); diff --git a/lsyncd.h b/lsyncd.h index 1961a5c..9a4ec67 100644 --- a/lsyncd.h +++ b/lsyncd.h @@ -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; diff --git a/lsyncd.lua b/lsyncd.lua index 3c9a75a..7622808 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -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 )