Skip to content

Instantly share code, notes, and snippets.

@rhowardiv
Last active October 1, 2015 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rhowardiv/2007851 to your computer and use it in GitHub Desktop.
Save rhowardiv/2007851 to your computer and use it in GitHub Desktop.
my bash wrapper around lsyncd; daemonize this
#!/bin/bash
# Just a wrapper around lsyncd
# Keep two places in sync
HERE=/home/rhoward/ayi/
THERE=rhoward-dev.ayisnap.com:/var/www/html/areyouinterested.com
# Check that no previously running syncs are still running;
# this causes boffo logging
CURRENT_SYNC=$(ps aux | grep "rsync.\+$HERE" | grep -v '0 grep')
if [ -n "$CURRENT_SYNC" ]; then
echo "I think that a previously running sync is still in progress:"
echo "$CURRENT_SYNC"
echo "Please wait for the process to complete, or kill it before calling $0 again!"
exit 1
fi
# send a configuration to lsyncd
CONF=/tmp/lsyncd_rh-dev.conf
LOG=/tmp/lsyncd_rh-dev.log
PIDFILE=/tmp/lsyncd_rh-dev.pid
cat > $CONF <<CONF
settings = {
logfile = "$LOG",
pidfile = "$PIDFILE",
delay = 1,
}
sync {
default.rsync,
source = "$HERE",
target = "$THERE",
exclude = { ".git", "*.swp", "*.swo", "*.swpx", "*.swx", "*~" }
}
CONF
on_exit () {
rm "$CONF"
kill $(cat "$PIDFILE")
rm "$PIDFILE"
notify-send --urgency=critical lsyncd 'lsyncd exited'
}
trap on_exit EXIT
lsyncd "$CONF"
# give lsyncd time to create log file
sleep 2
notify-send "lsyncd" "Started."
tail -f -n0 "$LOG" | while read -d "=" L; do
L="$(echo "$L" | tail -n +3 | grep -v '^/tags\|/$\|Finished a list\|4913$' | head)"
if [[ -n "$L" ]]; then
notify-send "lsyncd" "$(echo -n "$L")"
fi
done
@rhowardiv
Copy link
Author

Just a bunch of unrefined crap to get lsyncd working how I wanted. I tried having lsyncd log to stdout but it was doing weird things, so this is what I got working.

Just change HERE and THERE for you, run it and background it.

To stop, kill the tail process; this will exit the script which will then clean up pid and conf files (it leaves the log file in place).

@rhowardiv
Copy link
Author

One more thing about the notify-send calls; if you do something like start this in a Gnu screen session which you then disconnect from, the notifications will stop working; D-Bus cannot handle the change in environment. (For details see e.g. http://www.stderr.nl/Blog/Software/Linux/ScreenAndX.html)

If you have any issues with notifications stopping, just start this script from a bespoke terminal (running in your X session) which you can then close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment