no-startup flag introduced, whyever someone wants this, I'm generally for more configureability

This commit is contained in:
Axel Kittenberger 2010-07-27 13:00:32 +00:00
parent daa6166020
commit 2e2bc28c27
3 changed files with 62 additions and 31 deletions

View File

@ -100,6 +100,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<para>If a <option>&lt;no-daemon&gt;</option> node is present lsyncd will not detach and log to stdout/stderr. Default is to detach as daemon.</para> <para>If a <option>&lt;no-daemon&gt;</option> node is present lsyncd will not detach and log to stdout/stderr. Default is to detach as daemon.</para>
<programlisting> &lt;no-daemon/&gt;</programlisting> <programlisting> &lt;no-daemon/&gt;</programlisting>
<para>If a <option>&lt;no-startup&gt;</option> node is present lsyncd will not initiate the recursive rsync call on startup. Not adviced, know what you are doing if using this.</para>
<programlisting> &lt;no-startup/&gt;</programlisting>
<para>If a <option>&lt;dry-run&gt;</option> node is present lsyncd will not call any actions (rsync) for test purposes. Default is not to run dry.</para> <para>If a <option>&lt;dry-run&gt;</option> node is present lsyncd will not call any actions (rsync) for test purposes. Default is not to run dry.</para>
<programlisting> &lt;dry-run/&gt;</programlisting> <programlisting> &lt;dry-run/&gt;</programlisting>

View File

@ -200,6 +200,14 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<para>Do not detach, log to stdout/stderr.</para> <para>Do not detach, log to stdout/stderr.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--no-startup</option></term>
<listitem>
<para>Skips the inital recursive rsync. This option is not adviced and may lead to failures if the target
is missing directories. Know what you are doing if you use it.</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--pidfile <parameter>FILE</parameter></option></term> <term><option>--pidfile <parameter>FILE</parameter></option></term>

View File

@ -233,6 +233,11 @@ int flag_nodaemon = 0;
*/ */
int flag_stubborn = 0; int flag_stubborn = 0;
/**
* Global Option: if true, lsyncd will not perform the startup sync.
*/
int flag_nostartup = 0;
/** /**
* Global Option: pidfile, which holds the PID of the running daemon process. * Global Option: pidfile, which holds the PID of the running daemon process.
*/ */
@ -1547,6 +1552,7 @@ void print_help(char *arg0)
printf(" --help Print this help text and exit.\n"); printf(" --help Print this help text and exit.\n");
printf(" --logfile FILE Put log here (DEFAULT: uses syslog if not specified)\n"); printf(" --logfile FILE Put log here (DEFAULT: uses syslog if not specified)\n");
printf(" --no-daemon Do not detach, log to stdout/stderr\n"); printf(" --no-daemon Do not detach, log to stdout/stderr\n");
printf(" --no-startup Do not execute a startup sync (disadviced, know what you doing)\n");
printf(" --pidfile FILE Create a file containing pid of the daemon\n"); printf(" --pidfile FILE Create a file containing pid of the daemon\n");
printf(" --scarce Only log errors\n"); printf(" --scarce Only log errors\n");
printf(" --stubborn Ignore rsync errors on startup.\n"); printf(" --stubborn Ignore rsync errors on startup.\n");
@ -1765,6 +1771,8 @@ bool parse_settings(xmlNodePtr node) {
loglevel = 3; loglevel = 3;
} else if (!xmlStrcmp(snode->name, BAD_CAST "no-daemon")) { } else if (!xmlStrcmp(snode->name, BAD_CAST "no-daemon")) {
flag_nodaemon = 1; flag_nodaemon = 1;
} else if (!xmlStrcmp(snode->name, BAD_CAST "no-startup")) {
flag_nostartup = 1;
} else if (!xmlStrcmp(snode->name, BAD_CAST "stubborn")) { } else if (!xmlStrcmp(snode->name, BAD_CAST "stubborn")) {
flag_stubborn = 1; flag_stubborn = 1;
} else { } else {
@ -1846,30 +1854,33 @@ void parse_options(int argc, char **argv)
char **target; char **target;
static struct option long_options[] = { static struct option long_options[] = {
{"binary", 1, NULL, 0}, {"binary", 1, NULL, 0},
#ifdef XML_CONFIG #ifdef XML_CONFIG
{"conf", 1, NULL, 0}, {"conf", 1, NULL, 0},
#endif #endif
{"debug", 0, &loglevel, 1}, {"debug", 0, &loglevel, 1},
{"delay", 1, NULL, 0}, {"delay", 1, NULL, 0},
{"dryrun", 0, &flag_dryrun, 1}, {"dryrun", 0, &flag_dryrun, 1},
{"exclude-from", 1, NULL, 0}, {"exclude-from", 1, NULL, 0},
{"help", 0, NULL, 0}, {"help", 0, NULL, 0},
{"logfile", 1, NULL, 0}, {"logfile", 1, NULL, 0},
{"no-daemon", 0, &flag_nodaemon, 1}, {"no-daemon", 0, &flag_nodaemon, 1},
{"pidfile", 1, NULL, 0}, {"no-startup", 0, &flag_nostartup, 1},
{"scarce", 0, &loglevel, 3}, {"pidfile", 1, NULL, 0},
{"stubborn", 0, &flag_stubborn, 1}, {"scarce", 0, &loglevel, 3},
{"version", 0, NULL, 0}, {"stubborn", 0, &flag_stubborn, 1},
{"version", 0, NULL, 0},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
bool read_conf = false;
#ifdef XML_CONFIG #ifdef XML_CONFIG
bool read_conf = false; // First determine if the config file should be read at all.
// First determine if the config file should be read at all. If read it // If so, read it before parsing all other options in detail,
// before parsing all options in detail, because command line options // because command line options should overwrite settings in
// should overwrite global settings in the conf file. // the confing file.
//
// There are 2 conditions in which the conf file is read, either // There are 2 conditions in which the conf file is read, either
// --conf FILE is given as option, or there isn't a SOURCE and // --conf FILE is given as option, or there isn't a SOURCE and
// DESTINATION given, in which getting the config from the conf // DESTINATION given, in which getting the config from the conf
@ -1911,7 +1922,8 @@ void parse_options(int argc, char **argv)
/* reset get option parser*/ /* reset get option parser*/
optind = 1; optind = 1;
#endif #endif
// now parse all the other options normally.
while (1) { while (1) {
int oi = 0; int oi = 0;
int c = getopt_long_only(argc, argv, "", long_options, &oi); int c = getopt_long_only(argc, argv, "", long_options, &oi);
@ -1997,7 +2009,7 @@ void parse_options(int argc, char **argv)
} }
} }
/* sanity checking here */ // some sanity checks
if (default_exclude_file) { if (default_exclude_file) {
check_absolute_path(default_exclude_file); check_absolute_path(default_exclude_file);
check_file_exists(default_exclude_file); check_file_exists(default_exclude_file);
@ -2005,6 +2017,9 @@ void parse_options(int argc, char **argv)
if (pidfile) { if (pidfile) {
check_absolute_path(pidfile); check_absolute_path(pidfile);
} }
if (flag_stubborn && flag_nostartup) {
printlogf(NORMAL, "Warning: specifying 'stubborn' when skipping with 'no-startup' has no effect.");
}
} }
/** /**
@ -2017,7 +2032,7 @@ bool parse_exclude_file(char *filename) {
ef = fopen(filename, "r"); ef = fopen(filename, "r");
if (ef == NULL) { if (ef == NULL) {
printlogf(ERROR, "Meh, cannot open exclude file '%s'\n", filename); printlogf(ERROR, "Cannot open exclude file '%s'\n", filename);
terminate(LSYNCD_FILENOTFOUND); terminate(LSYNCD_FILENOTFOUND);
} }
@ -2140,23 +2155,28 @@ int main(int argc, char **argv)
} }
// clears tosync stack again, because the startup // clears tosync stack again, because the startup
// super recursive rsync will handle it eitherway. // super recursive rsync will handle it eitherway
// or if nostartup user decided already to ignore it.
printlogf(DEBUG, "dumped tosync stack."); printlogf(DEBUG, "dumped tosync stack.");
tosync_pos = 0; tosync_pos = 0;
// startup recursive sync. // startup recursive sync.
for (i = 0; i < dir_conf_n; i++) { if (!flag_nostartup) {
char **target; for (i = 0; i < dir_conf_n; i++) {
for (target = dir_confs[i].targets; *target; ++target) { char **target;
if (!action(&dir_confs[i], dir_confs[i].source, *target, true)) { for (target = dir_confs[i].targets; *target; ++target) {
printlogf(ERROR, "Initial rsync from %s to %s failed%s", if (!action(&dir_confs[i], dir_confs[i].source, *target, true)) {
dir_confs[i].source, *target, printlogf(ERROR, "Initial rsync from %s to %s failed%s",
flag_stubborn ? ", but continuing because being stubborn." : "."); dir_confs[i].source, *target,
if (!flag_stubborn) { flag_stubborn ? ", but continuing because being stubborn." : ".");
terminate(LSYNCD_EXECFAIL); if (!flag_stubborn) {
} terminate(LSYNCD_EXECFAIL);
}
}
} }
} }
} else {
printlogf(NORMAL, "Skipped startup since nostartup flag is turned on.");
} }
printlogf(NORMAL, printlogf(NORMAL,