Rip out unison syncing. It never got to see the light of day. Just didn't work out. (NFS replaced it)
This commit is contained in:
parent
7ddff513f0
commit
21e4477c39
|
@ -30,12 +30,6 @@ Vagrant::Config.run do |config|
|
|||
# other Vagrantfiles, if they wish.
|
||||
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"
|
||||
config.unison.log_file = "/tmp/v-unison-log-%s"
|
||||
|
||||
config.nfs.map_uid = :auto
|
||||
config.nfs.map_gid = :auto
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ module Vagrant
|
|||
# Only mount and setup shared folders in the absense of an
|
||||
# error
|
||||
mount_shared_folders
|
||||
setup_unison
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -36,29 +35,11 @@ module Vagrant
|
|||
|
||||
# This to prevent overwriting the actual shared folders data
|
||||
value = value.dup
|
||||
|
||||
if value[:sync]
|
||||
# Syncing this folder. Change the guestpath to reflect
|
||||
# what we're actually mounting.
|
||||
value[:original] = value.dup
|
||||
value[:guestpath] = "#{value[:guestpath]}#{@env.env.config.unison.folder_suffix}"
|
||||
end
|
||||
|
||||
acc[key] = value
|
||||
acc
|
||||
end
|
||||
end
|
||||
|
||||
# This method returns the list of shared folders which are to
|
||||
# be synced via unison.
|
||||
def unison_folders
|
||||
shared_folders.inject({}) do |acc, data|
|
||||
key, value = data
|
||||
acc[key] = value if !!value[:sync]
|
||||
acc
|
||||
end
|
||||
end
|
||||
|
||||
def create_metadata
|
||||
@env.ui.info "vagrant.actions.vm.share_folders.creating"
|
||||
|
||||
|
@ -84,19 +65,6 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup_unison
|
||||
return if unison_folders.empty?
|
||||
|
||||
@env["vm"].ssh.execute do |ssh|
|
||||
@env["vm"].system.prepare_unison(ssh)
|
||||
|
||||
@env.ui.info "vagrant.actions.vm.share_folders.setup_unison"
|
||||
unison_folders.each do |name, data|
|
||||
@env["vm"].system.create_unison(ssh, data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,14 +78,6 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
class UnisonConfig < Base
|
||||
attr_accessor :folder_suffix
|
||||
attr_accessor :script
|
||||
attr_accessor :options
|
||||
attr_accessor :crontab_entry_file
|
||||
attr_accessor :log_file
|
||||
end
|
||||
|
||||
class NFSConfig < Base
|
||||
attr_accessor :map_uid
|
||||
attr_accessor :map_gid
|
||||
|
@ -227,7 +219,6 @@ module Vagrant
|
|||
configures :package, PackageConfig
|
||||
configures :nfs, NFSConfig
|
||||
configures :ssh, SSHConfig
|
||||
configures :unison, UnisonConfig
|
||||
configures :vm, VMConfig
|
||||
configures :vagrant, VagrantConfig
|
||||
|
||||
|
|
|
@ -53,13 +53,6 @@ module Vagrant
|
|||
# via the host are already done.
|
||||
def mount_nfs(ip, folders); end
|
||||
|
||||
# Prepares the system for unison folder syncing. This is called
|
||||
# once once prior to any `create_unison` calls.
|
||||
def prepare_unison(ssh); end
|
||||
|
||||
# Creates an entry for folder syncing via unison.
|
||||
def create_unison(ssh, options); end
|
||||
|
||||
# Prepares the system for host only networks. This is called
|
||||
# once prior to any `enable_host_only_network` calls.
|
||||
def prepare_host_only_network; end
|
||||
|
|
|
@ -63,30 +63,6 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
def prepare_unison(ssh)
|
||||
ssh.exec!("which unison", :error_key => :unison_not_found)
|
||||
|
||||
vm.env.ui.info "Preparing system for unison sync..."
|
||||
vm.ssh.upload!(StringIO.new(TemplateRenderer.render('/unison/script')), config.unison.script)
|
||||
ssh.exec!("sudo chmod +x #{config.unison.script}")
|
||||
ssh.exec!("sudo rm #{config.unison.crontab_entry_file}", :error_check => false)
|
||||
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,
|
||||
:log_file => (config.unison.log_file % sanitized_string))
|
||||
|
||||
ssh.exec!("sudo rm -rf ~/.unison")
|
||||
ssh.exec!("sudo rm -rf #{opts[:original][:guestpath]}")
|
||||
ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.unison.crontab_entry_file}")
|
||||
ssh.exec!("crontab #{config.unison.crontab_entry_file}")
|
||||
end
|
||||
|
||||
def prepare_host_only_network
|
||||
# Remove any previous host only network additions to the
|
||||
# interface file.
|
||||
|
|
|
@ -168,7 +168,6 @@ en:
|
|||
creating: Creating shared folders metadata...
|
||||
mounting: Mounting shared folders...
|
||||
mounting_entry: "-- %{name}: %{guest_path}"
|
||||
setup_unison: Creating unison crontab entries...
|
||||
suspend:
|
||||
suspending: Saving VM state and suspending execution...
|
||||
|
||||
|
|
|
@ -137,11 +137,6 @@
|
|||
:system_unspecified: |-
|
||||
A VM system type must be specified! This is done via the `config.vm.system`
|
||||
configuration value. Please read the documentation online for more information.
|
||||
:unison_not_found: |-
|
||||
The `unison` binary was not found on the guest machine. This is required
|
||||
for folder syncing via unison. Please install unison on your system to
|
||||
use folder syncing. You may also disable folder syncing, install unison,
|
||||
re-enable syncing, then call a `vagrant reload` to enable syncing.
|
||||
:virtualbox_import_failure: |-
|
||||
The VM import failed! Try running `VBoxManage import` on the box file
|
||||
manually for more verbose error output.
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
* * * * * <%= script %> '<%= from %>' '<%= to %>' '<%= options %>' >> <%= log_file %> 2>&1
|
|
@ -1,71 +0,0 @@
|
|||
#!/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
|
||||
|
||||
# Sanitization function which turns any non-alphanumeric char
|
||||
# into a dash '-' and returns it by echoing the result.
|
||||
function sanitize() {
|
||||
local DATA=$1
|
||||
DATA=${DATA//[^a-zA-Z0-9_-]/-}
|
||||
echo ${DATA}
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# "Configuration"
|
||||
#------------------------------------------------------------
|
||||
# TODO Change lockfile to depend on the from/to folder to
|
||||
# allow multiple syncs of diff folders to happen at once.
|
||||
FROM=$1
|
||||
TO=$2
|
||||
OPTIONS=$3
|
||||
LOCK_FILE=`basename $0`-$(sanitize ${TO}).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
|
||||
#------------------------------------------------------------
|
||||
echo "Beginning Sync:"
|
||||
echo " -- From: ${FROM}"
|
||||
echo " -- To: ${TO}"
|
||||
echo " -- Options: ${OPTIONS}"
|
||||
while [ 1 ]; do
|
||||
echo "Syncing: $(date)"
|
||||
# TODO check result and output log data... somewhere!
|
||||
sudo unison ${FROM} ${TO} ${OPTIONS}
|
||||
sleep 1
|
||||
done
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Cleanup and Exit
|
||||
#------------------------------------------------------------
|
||||
rm -f "${LOCK_FILE}"
|
||||
exit 0
|
|
@ -47,10 +47,6 @@ class Test::Unit::TestCase
|
|||
|
||||
config.package.name = 'package'
|
||||
|
||||
# Unison
|
||||
config.unison.folder_suffix = ".sync"
|
||||
config.unison.log_file = "foo-%s"
|
||||
|
||||
# Chef
|
||||
config.chef.chef_server_url = "http://localhost:4000"
|
||||
config.chef.validation_key_path = "validation.pem"
|
||||
|
|
|
@ -41,7 +41,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
|||
@instance.expects(:create_metadata).once.in_sequence(before_seq)
|
||||
@app.expects(:call).with(@env).in_sequence(before_seq)
|
||||
@instance.expects(:mount_shared_folders).once.in_sequence(before_seq)
|
||||
@instance.expects(:setup_unison).once.in_sequence(before_seq)
|
||||
|
||||
@instance.call(@env)
|
||||
end
|
||||
|
@ -53,7 +52,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
|||
@instance.expects(:create_metadata).once.in_sequence(before_seq)
|
||||
@app.expects(:call).with(@env).in_sequence(before_seq)
|
||||
@instance.expects(:mount_shared_folders).never
|
||||
@instance.expects(:setup_unison).never
|
||||
|
||||
@instance.call(@env)
|
||||
end
|
||||
|
@ -96,20 +94,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
|||
assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort
|
||||
end
|
||||
|
||||
should "append sync suffix if sync enabled to a folder" do
|
||||
name = "foo"
|
||||
guest = "bar"
|
||||
host = "baz"
|
||||
|
||||
stub_shared_folders do |config|
|
||||
config.vm.share_folder(name, guest, host, :sync => true)
|
||||
end
|
||||
|
||||
result = @instance.shared_folders
|
||||
assert_equal "#{guest}#{@env.env.config.unison.folder_suffix}", result[name][:guestpath]
|
||||
assert_equal guest, result[name][:original][:guestpath]
|
||||
end
|
||||
|
||||
should "not destroy original hash" do
|
||||
@folders = stub_shared_folders do |config|
|
||||
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
||||
|
@ -122,22 +106,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "unison shared folders" do
|
||||
setup do
|
||||
@folders = stub_shared_folders do |config|
|
||||
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
||||
config.vm.share_folder("bar", "foo", "baz")
|
||||
end
|
||||
end
|
||||
|
||||
should "only return the folders marked for syncing" do
|
||||
result = @instance.unison_folders
|
||||
assert_equal 1, result.length
|
||||
assert result.has_key?("foo")
|
||||
assert !result.has_key?("bar")
|
||||
end
|
||||
end
|
||||
|
||||
context "setting up shared folder metadata" do
|
||||
setup do
|
||||
stub_shared_folders
|
||||
|
@ -177,39 +145,4 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
|||
@instance.mount_shared_folders
|
||||
end
|
||||
end
|
||||
|
||||
context "setting up unison" do
|
||||
setup do
|
||||
@ssh = mock("ssh")
|
||||
@vm.ssh.stubs(:execute).yields(@ssh)
|
||||
|
||||
@folders = stub_shared_folders do |config|
|
||||
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
||||
config.vm.share_folder("bar", "foo", "baz")
|
||||
end
|
||||
end
|
||||
|
||||
should "do nothing if unison folders is empty" do
|
||||
@instance.stubs(:unison_folders).returns({})
|
||||
@vm.ssh.expects(:execute).never
|
||||
@instance.setup_unison
|
||||
end
|
||||
|
||||
should "prepare unison then create for each folder" do
|
||||
seq = sequence("unison seq")
|
||||
@vm.system.expects(:prepare_unison).with(@ssh).once.in_sequence(seq)
|
||||
@instance.unison_folders.each do |name, data|
|
||||
if data[:sync]
|
||||
@vm.system.expects(:create_unison).with do |ssh, opts|
|
||||
assert_equal @ssh, ssh
|
||||
assert_equal data, opts
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@instance.setup_unison
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,71 +43,6 @@ class LinuxSystemTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "preparing unison" do
|
||||
setup do
|
||||
@ssh.stubs(:exec!)
|
||||
@ssh.stubs(:upload!)
|
||||
@vm.stubs(:ssh).returns(@ssh)
|
||||
end
|
||||
|
||||
should "upload the script" do
|
||||
@vm.ssh.expects(:upload!).with do |script, path|
|
||||
assert_equal @mock_env.config.unison.script, path
|
||||
true
|
||||
end
|
||||
|
||||
@instance.prepare_unison(@ssh)
|
||||
end
|
||||
|
||||
should "make the script executable" do
|
||||
@ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.unison.script}").once
|
||||
@instance.prepare_unison(@ssh)
|
||||
end
|
||||
|
||||
should "remove old crontab entry file" do
|
||||
@ssh.expects(:exec!).with("sudo rm #{@mock_env.config.unison.crontab_entry_file}", :error_check => false).once
|
||||
@instance.prepare_unison(@ssh)
|
||||
end
|
||||
end
|
||||
|
||||
context "creating unison entry" do
|
||||
setup do
|
||||
@ssh.stubs(:exec!)
|
||||
@options = {
|
||||
:guestpath => "foo",
|
||||
:original => { :guestpath => "bar!" }
|
||||
}
|
||||
end
|
||||
|
||||
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 "remove the .unison directory" do
|
||||
@ssh.expects(:exec!).with("sudo rm -rf ~/.unison")
|
||||
@instance.create_unison(@ssh, @options)
|
||||
end
|
||||
|
||||
should "remove the original guestpath" do
|
||||
@ssh.expects(:exec!).with("sudo rm -rf #{@options[:original][:guestpath]}")
|
||||
@instance.create_unison(@ssh, @options)
|
||||
end
|
||||
|
||||
should "enable the crontab file" do
|
||||
@ssh.expects(:exec!).with("crontab #{@mock_env.config.unison.crontab_entry_file}")
|
||||
@instance.create_unison(@ssh, @options)
|
||||
end
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# "Private" methods tests
|
||||
#-------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue