From ec325138c21b2e2bf2064b1e12293643b981399e Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Tue, 17 May 2016 23:05:39 +0100 Subject: [PATCH] add lsyncd to csync container --- build/boot/csync.sh | 14 ++++--- build/boot/lsync.sh | 88 ++++++++++++++++++++++++++++++++++++++++++ build/make/csync.mk | 4 +- build/runit/lsyncd | 3 ++ build/scripts/csync.sh | 23 ++++++++++- 5 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 build/boot/lsync.sh create mode 100644 build/runit/lsyncd diff --git a/build/boot/csync.sh b/build/boot/csync.sh index 33fb06e..dd4d046 100644 --- a/build/boot/csync.sh +++ b/build/boot/csync.sh @@ -1,9 +1,11 @@ #!/bin/bash set -e -HOST_ETC_CSYNC=/host/etc/csync -if [ ! -e $CSYNC_CONFIG ]; then - cp /usr/local/etc/csync2* $HOST_ETC_CSYNC/ - csync2 -k $HOST_ETC_CSYNC/csync2.pem +HOST_DIR=`dirname $CSYNC_CONFIG` +CONTAINER_DIR=/usr/local/etc +if [ ! -e $HOST_DIR/csync2.pem ]; then + csync2 -k $HOST_DIR/csync2.pem + cp -f $CONTAINER_DIR/csync2* $HOST_DIR/ fi -rm -r /usr/local/etc -ln -sf $HOST_ETC_CSYNC/ /usr/local/etc \ No newline at end of file +rm -r $CONTAINER_DIR +ln -sf $HOST_DIR/ $CONTAINER_DIR +cp -f $HOST_DIR/csync2_$HOSTNAME.cfg $HOST_DIR/csync2.cfg \ No newline at end of file diff --git a/build/boot/lsync.sh b/build/boot/lsync.sh new file mode 100644 index 0000000..f263654 --- /dev/null +++ b/build/boot/lsync.sh @@ -0,0 +1,88 @@ +#!/bin/bash +set -e +if [ ! -e $LSYNC_CONFIG ]; then + CSYNC_BIN=`which csync2` + CSYNC_CONFIG_DIR=`dirname $CSYNC_CONFIG` + cat << EOF > $LSYNC_CONFIG +settings { + logident = "lsyncd", + logfacility = "user", + logfile = "$LSYNC_LOG", + statusFile = "$LSYNC_STATUS", + statusInterval = 1 +} +initSync = { + delay = 1, + maxProcesses = 1, + action = function(inlet) + local config = inlet.getConfig() + local elist = inlet.getEvents(function(event) + return event.etype ~= "Init" + end) + local directory = string.sub(config.source, 1, -2) + local paths = elist.getPaths(function(etype, path) + return "\t" .. config.syncid .. ":" .. directory .. path + end) + log("Normal", "Processing syncing list:\n", table.concat(paths, "\n")) + spawn(elist, "$CSYNC_BIN", "-C", config.syncid, "-x") + end, + collect = function(agent, exitcode) + local config = agent.config + if not agent.isList and agent.etype == "Init" then + if exitcode == 0 then + log("Normal", "Startup of '", config.syncid, "' instance finished.") + elseif config.exitcodes and config.exitcodes[exitcode] == "again" then + log("Normal", "Retrying startup of '", config.syncid, "' instance.") + return "again" + else + log("Error", "Failure on startup of '", config.syncid, "' instance.") + terminate(-1) + end + return + end + local rc = config.exitcodes and config.exitcodes[exitcode] + if rc == "die" then + return rc + end + if agent.isList then + if rc == "again" then + log("Normal", "Retrying events list on exitcode = ", exitcode) + else + log("Normal", "Finished events list = ", exitcode) + end + else + if rc == "again" then + log("Normal", "Retrying ", agent.etype, " on ", agent.sourcePath, " = ", exitcode) + else + log("Normal", "Finished ", agent.etype, " on ", agent.sourcePath, " = ", exitcode) + end + end + return rc + end, + init = function(event) + local inlet = event.inlet; + local config = inlet.getConfig(); + log("Normal", "Recursive startup sync: ", config.syncid, ":", config.source) + spawn(event, "$CSYNC_BIN", "-C", config.syncid, "-x") + end, + prepare = function(config) + if not config.syncid then + error("Missing 'syncid' parameter.", 4) + end + local c = "csync2_" .. config.syncid .. ".cfg" + local f, err = io.open("$CSYNC_CONFIG_DIR" .. c, "r") + if not f then + error("Invalid 'syncid' parameter: " .. err, 4) + end + f:close() + end +} +local sources = { + -- change the node1 value with respective host + -- ["/home/website/public_html"] = "node1" +} +for key, value in pairs(sources) do + sync {initSync, source=key, syncid=value} +end +EOF +fi \ No newline at end of file diff --git a/build/make/csync.mk b/build/make/csync.mk index 32191f3..03fa022 100644 --- a/build/make/csync.mk +++ b/build/make/csync.mk @@ -1,4 +1,6 @@ csync: base sshd compile $(call script,$@) $(call runit,xinetd) - $(call boot,02,$@) \ No newline at end of file + $(call runit,lsyncd) + $(call boot,02,$@) + $(call boot,02,lsync) diff --git a/build/runit/lsyncd b/build/runit/lsyncd new file mode 100644 index 0000000..c451a71 --- /dev/null +++ b/build/runit/lsyncd @@ -0,0 +1,3 @@ +#!/bin/bash +set -e +/usr/local/bin/lsyncd -nodaemon $LSYNC_CONFIG \ No newline at end of file diff --git a/build/scripts/csync.sh b/build/scripts/csync.sh index 5ca3a9f..69d33a4 100644 --- a/build/scripts/csync.sh +++ b/build/scripts/csync.sh @@ -1,6 +1,10 @@ ## Configuration export_env CSYNC_VERSION 2.0 export_env CSYNC_CONFIG /host/etc/csync/csync2.cfg +export_env LSYNC_CONFIG /host/etc/lsyncd.conf +export_env LSYNC_LOG /host/var/log/lsyncd.log +export_env LSYNC_STATUS /host/var/log/lsyncd_status.log +export_env HOSTALIASES /host/etc/host.aliases ## Dependencies apt_install_permanent librsync-dev libsqlite3-dev libgnutls28-dev pkg-config @@ -15,7 +19,7 @@ make make install make cert -## xinetd +## Xinetd apt_install_permanent xinetd ## Configuration @@ -33,8 +37,25 @@ service csync2 EOF echo "csync2 30865/tcp" >> /etc/services +## Lsyncd dependencies +apt_install_permanent lua5.2 liblua5.2-dev bash-completion +ln -s /usr/share/bash-completion/completions/a2x /usr/bin/a2x +chmod +x /usr/bin/a2x + +## Lsyncd +cd /opt +git clone https://github.com/axkibe/lsyncd.git +cd lsyncd +mkdir build +cd build +cmake .. +sed -i 's,a2x,#,' CMakeFiles/manpage.dir/build.make +make +make install + ## Remove installation files if [ $MODE == "minimal" ]; then cd /opt rm -rf csync2-$CSYNC_VERSION* + rm -r lsyncd fi \ No newline at end of file