Better, more unified logging for unison

This commit is contained in:
Mitchell Hashimoto 2010-06-22 23:33:20 -07:00
parent f3c6c7320b
commit 97f82d7140
8 changed files with 27 additions and 8 deletions

View File

@ -31,6 +31,7 @@ Vagrant::Config.run do |config|
config.unison.script = "/tmp/vagrant-unison"
config.unison.options = "-terse -owner -group -batch"
config.unison.crontab_entry_file = "/tmp/vagrant-unison-crontab"
config.unison.log_file = "/tmp/v-unison-log-%s"
# TODO fix these
# config.vm.sync_opts = "-terse -group -owner -batch -silent"

View File

@ -82,6 +82,7 @@ module Vagrant
attr_accessor :script
attr_accessor :options
attr_accessor :crontab_entry_file
attr_accessor :log_file
end
class VMConfig < Base

View File

@ -62,11 +62,13 @@ module Vagrant
end
def create_unison(ssh, opts)
sanitized_string = opts[:original][:guestpath].gsub(/[^a-zA-Z0-9_-]/, '-')
crontab_entry = TemplateRenderer.render('/unison/crontab_entry',
:from => opts[:guestpath],
:to => opts[:original][:guestpath],
:options => config.unison.options,
:script => config.unison.script)
:script => config.unison.script,
:log_file => (config.unison.log_file % sanitized_string))
ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.unison.crontab_entry_file}")
ssh.exec!("crontab #{config.unison.crontab_entry_file}")
end

View File

@ -1 +1 @@
* * * * * <%= script %> '<%= from %>' '<%= to %>' '<%= options %>'
* * * * * <%= script %> '<%= from %>' '<%= to %>' '<%= options %>' > <%= log_file %> 2>&1

View File

@ -30,7 +30,6 @@ FROM=$1
TO=$2
OPTIONS=$3
LOCK_FILE=`basename $0`-$(sanitize ${TO}).lck
LOG_FILE=unison-$(sanitize ${TO}).log
#------------------------------------------------------------
# Am I Running?
@ -54,10 +53,14 @@ echo $$ > "${LOCK_FILE}"
#------------------------------------------------------------
# The Meat
#------------------------------------------------------------
echo "Beginning Sync:"
echo " -- From: ${FROM}"
echo " -- To: ${TO}"
echo " -- Options: ${OPTIONS}"
while [ 1 ]; do
echo 'Syncing...'
echo "Syncing: $(date)"
# TODO check result and output log data... somewhere!
sudo unison ${FROM} ${TO} ${OPTIONS} > ${LOG_FILE} 2>&1
sudo unison ${FROM} ${TO} ${OPTIONS}
sleep 1
done

View File

@ -50,6 +50,7 @@ class Test::Unit::TestCase
# Unison
config.unison.folder_suffix = ".sync"
config.unison.log_file = "foo-%s"
# Chef
config.chef.chef_server_url = "http://localhost:4000"

View File

@ -75,11 +75,22 @@ class LinuxSystemTest < Test::Unit::TestCase
@ssh.stubs(:exec!)
@options = {
:guestpath => "foo",
:original => { :guestpath => "bar" }
:original => { :guestpath => "bar!" }
}
end
# TODO Test crontab entry
should "render the crontab entry with proper variables" do
variables = {
:from => @options[:guestpath],
:to => @options[:original][:guestpath],
:options => @mock_env.config.unison.options,
:script => @mock_env.config.unison.script,
:log_file => @mock_env.config.unison.log_file % "bar-"
}
Vagrant::Util::TemplateRenderer.expects(:render).with('/unison/crontab_entry',
variables).once
@instance.create_unison(@ssh, @options)
end
should "enable the crontab file" do
@ssh.expects(:exec!).with("crontab #{@mock_env.config.unison.crontab_entry_file}")

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-06-20}
s.date = %q{2010-06-22}
s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]