From fa40f4c1c0f1bee54b22a15bfa61ab7b093101ac Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Sat, 13 Dec 2008 17:30:52 +0000 Subject: [PATCH] introducing --stubborn, to startup regardless if startup rsyncs work or not.\nsmall fixes --- Makefile.am | 4 ++-- lsyncd.c | 25 ++++++++++++++++++++----- manpage.lsyncd.conf.xml | 12 ++++++++++++ manpage.lsyncd.xml | 24 ++++++++++++++++-------- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Makefile.am b/Makefile.am index c1ffa01..366cbd8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,10 +31,10 @@ lsyncd.conf.xml.5: manpage.lsyncd.conf.xml $(XP) $(DB2MAN) $< AM_CFLAGS=-Wall -AM_LIBS= +AM_LDFLAGS= if XML_CONFIG DEFS+=-DXML_CONFIG AM_CFLAGS += `xml2-config --cflags` -AM_CFLAGS += `xml2-config --libs` +AM_LDFLAGS += `xml2-config --libs` endif diff --git a/lsyncd.c b/lsyncd.c index 2c579f9..b13cb45 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -195,6 +195,14 @@ int flag_dryrun = 0; */ int flag_nodaemon = 0; +/** + * Global Option: if true, ignore rsync errors on startup. + * (during normal operations they have to be ignored eitherway, + * since rsync may also fail due e.g. the directory already + * beeing deleted when lsyncd wants to sync it.) + */ +int flag_stubborn = 0; + /** * Global Option: pidfile, which holds the PID of the running daemon process. */ @@ -851,7 +859,7 @@ bool buildpath(char *pathname, } strcat(pathname, dirname); } - printlogf(LOG_NORMAL, " BUILDPATH(%d, %s, %s) -> %s", watch, dirname, prefix, pathname); + printlogf(LOG_DEBUG, " BUILDPATH(%d, %s, %s) -> %s", watch, dirname, prefix, pathname); return true; } @@ -1231,6 +1239,7 @@ void print_help(char *arg0) printf(" --no-daemon Do not detach, log to stdout/stderr\n"); printf(" --pidfile FILE Create a file containing pid of the daemon\n"); printf(" --scarce Only log errors\n"); + printf(" --stubborn Ignore rsync errors on startup.\n"); printf(" --version Print version an exit.\n"); printf("\n"); printf("Take care that lsyncd is allowed to write to the logfile specified.\n"); @@ -1424,6 +1433,8 @@ bool parse_settings(xmlNodePtr node) { loglevel = 3; } else if (!xmlStrcmp(snode->name, BAD_CAST "no-daemon")) { flag_nodaemon = 1; + } else if (!xmlStrcmp(snode->name, BAD_CAST "stubborn")) { + flag_stubborn = 1; } else { fprintf(stderr, "error unknown node in \"%s\"", snode->name); exit(LSYNCD_BADCONFIGFILE); @@ -1508,7 +1519,8 @@ bool parse_options(int argc, char **argv) {"logfile", 1, NULL, 0}, {"no-daemon", 0, &flag_nodaemon, 1}, {"pidfile", 1, NULL, 0}, - {"scarce", 0, &loglevel, 3}, + {"scarce", 0, &loglevel, 3}, + {"stubborn", 0, &flag_stubborn, 1}, {"version", 0, NULL, 0}, {NULL, 0, NULL, 0} }; @@ -1784,9 +1796,12 @@ int main(int argc, char **argv) char **target; for (target = dir_confs[i].targets; *target; ++target) { if (!action(&dir_confs[i], dir_confs[i].source, *target, true)) { - printlogf(LOG_ERROR, "Initial rsync from %s to %s failed", - dir_confs[i].source, *target); - exit(LSYNCD_EXECFAIL); + printlogf(LOG_ERROR, "Initial rsync from %s to %s failed%s", + dir_confs[i].source, *target, + flag_stubborn ? ", but continuing because being stubborn." : "."); + if (!flag_stubborn) { + exit(LSYNCD_EXECFAIL); + } } } } diff --git a/manpage.lsyncd.conf.xml b/manpage.lsyncd.conf.xml index 7a4b3f0..40ee71b 100644 --- a/manpage.lsyncd.conf.xml +++ b/manpage.lsyncd.conf.xml @@ -84,22 +84,34 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ SETTINGS Next is optionally a node. It controls lsyncd global settings. All settings are optional. <settings> + If a node is present all debug messages will be logged. Default is a normal verbosity. <debug/> + If a node is present only error messages will be logged. Default is a normal verbosity. <scarce/> + + If a node is present lsyncd will continue even if the startup sync fails. Default is being not stubborn. + <stubborn/> + If a node is present lsyncd will not detach and log to stdout/stderr. Default is to detach as daemon. <no-daemon/> + If a node is present lsyncd will not call any actions (rsync) for test purposes. Default is not to run dry. <dry-run/> + With an entry an exclusion file can be specified with a "filename" parameter. This will be passed to rsync and follows rsyncs grammar for exclude files. Default is not to pass an exlude file to rsync. <exclude-from filename="/etc/lsyncd.exclude"/> + With a node to location of the logfile can be changed. Default is /var/log/lsyncd. Take care that the user which lsyncd is running with can write to this file. <logfile filename="/var/log/lsyncd"/> + A node specifies the binary lsyncd will call to sync stuff. Usually you want this to be rsync. Default is /usr/bin/rsync. <binary filename="/usr/bin/rsync"/> + If a node is present lsyncd will write its pid there. Default is not to write a pidfile. <pidfile filename="/var/run/lsyncd.pid"/> + With a node you can control the arguments lsyncd will call the <binary> (rsync) with. Each child node will specify one argument. <option> specifies a literal argument. Only %r will be replaced with 'r' when rsycnd is supposed to work recursive (on startup of lsyncd) or 'd' on normal operations. <exclude-file> will be replaced with if an <exclude-from> file is specified. <source> will be replaced the source directory to sync from. <destination> will be replace to the target to sync to. Default arguments are . <callopts> <option text="-lt%r"/> diff --git a/manpage.lsyncd.xml b/manpage.lsyncd.xml index 208f545..54f4f7e 100644 --- a/manpage.lsyncd.xml +++ b/manpage.lsyncd.xml @@ -91,15 +91,16 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ &dhpackage; + - + source target... @@ -139,6 +140,13 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ + + + + Call this binary to sync (DEFAULT: /usr/bin/rsync). + + + @@ -183,13 +191,6 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ - - - - Call this binary to sync (DEFAULT: /usr/bin/rsync). - - - @@ -203,6 +204,13 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ Only log errors. + + + + + Continue even if startup sync fails. + +