diff --git a/config/default.rb b/config/default.rb index f95e48875..518b543f2 100644 --- a/config/default.rb +++ b/config/default.rb @@ -28,6 +28,10 @@ Vagrant::Config.run do |config| config.vm.share_folder("v-root", "/vagrant", ".") config.unison.folder_suffix = ".sync" + config.unison.script = "/tmp/vagrant-unison" + config.unison.options = "-terse -owner -group -batch" + config.unison.crontab_entry_file = "/tmp/vagrant-unison-crontab" + # TODO fix these # config.vm.sync_opts = "-terse -group -owner -batch -silent" # config.vm.sync_script = "/tmp/sync" diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 4622d7466..41a748cf9 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -79,14 +79,9 @@ module Vagrant class UnisonConfig < Base attr_accessor :folder_suffix - - # TODO figure out what is needed here, the options above were - # added after the fact so they are fine. Below needs to be - # reanalyzed: - attr_accessor :sync_opts - attr_accessor :sync_script - attr_accessor :sync_crontab_entry_file - attr_reader :sync_required + attr_accessor :script + attr_accessor :options + attr_accessor :crontab_entry_file end class VMConfig < Base diff --git a/templates/crontab_entry.erb b/templates/crontab_entry.erb deleted file mode 100644 index 6c075d58d..000000000 --- a/templates/crontab_entry.erb +++ /dev/null @@ -1 +0,0 @@ -* * * * * <%= scriptname %> '<%= syncopts %>' '<%= guestpath %>' '<%= syncpath %>' '-prefer <%= guestpath %>' diff --git a/templates/sync.erb b/templates/sync.erb deleted file mode 100644 index 139eb2afc..000000000 --- a/templates/sync.erb +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -TIMESTART=`date +%s` -while [ 1 ] -do - echo 'Syncing...' - unison $1 $2 $3 $4 - TIME=$((`date +%s`-$TIMESTART)) - echo $TIME - if [ $TIME -ge 50 ] - then - break - fi - sleep 1 -done diff --git a/templates/unison/crontab_entry.erb b/templates/unison/crontab_entry.erb new file mode 100644 index 000000000..c06032358 --- /dev/null +++ b/templates/unison/crontab_entry.erb @@ -0,0 +1 @@ +* * * * * <%= scriptname %> '<%= from %>' '<%= to %>' '<%= options %>' diff --git a/templates/unison/script.erb b/templates/unison/script.erb new file mode 100644 index 000000000..645b68e9a --- /dev/null +++ b/templates/unison/script.erb @@ -0,0 +1,56 @@ +#!/bin/bash +#------------------------------------------------------------ +# Author : John Bender and Mitchell Hashimoto +# Description : Runs the `unison` folder synchronization +# utility for shared folders. +#------------------------------------------------------------ + +#------------------------------------------------------------ +# Argument verification +#------------------------------------------------------------ +if [ $# -ne 3 ]; then + echo "Usage: `basename $0` from_folder to_folder options" + exit 1 +fi + +#------------------------------------------------------------ +# "Configuration" +#------------------------------------------------------------ +# TODO Change lockfile to depend on the from/to folder to +# allow multiple syncs of diff folders to happen at once. +LOCK_FILE=`basename $0`.lck + +#------------------------------------------------------------ +# Am I Running? +#------------------------------------------------------------ +if [ -f "${LOCK_FILE}" ]; then + # The file exists, verify its running and if so exit. + OUR_PID=`head -n 1 "${LOCK_FILE}"` + TEST_RUNNING=`ps -p ${OUR_PID} | grep ${OUR_PID}` + + if [ "${TEST_RUNNING}" ]; then + # The process is running, echo and exit. + echo "Unison sync already running. [PID: ${OUR_PID}]" + exit 0 + fi +fi + +# We're not running if we reached this point, so lock +# it up. +echo $$ > "${LOCK_FILE}" + +#------------------------------------------------------------ +# The Meat +#------------------------------------------------------------ +while [ 1 ]; do + echo 'Syncing...' + # TODO check result and output log data... somewhere! + unison $1 $2 $3 + sleep 1 +done + +#------------------------------------------------------------ +# Cleanup and Exit +#------------------------------------------------------------ +rm -f "${LOCK_FILE}" +exit 0 \ No newline at end of file