Setup new unison scripts and set configs.

This commit is contained in:
Mitchell Hashimoto 2010-06-20 01:42:31 -07:00
parent 388662c62a
commit 5f0695f776
6 changed files with 64 additions and 23 deletions

View File

@ -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"

View File

@ -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

View File

@ -1 +0,0 @@
* * * * * <%= scriptname %> '<%= syncopts %>' '<%= guestpath %>' '<%= syncpath %>' '-prefer <%= guestpath %>'

View File

@ -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

View File

@ -0,0 +1 @@
* * * * * <%= scriptname %> '<%= from %>' '<%= to %>' '<%= options %>'

View File

@ -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