vagrant-unison2 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a56396d3b841677ba05e588a000d1720dc2a8bad
4
- data.tar.gz: 23822e18be0e28ad858c2fa2ff516279b3c6857b
3
+ metadata.gz: 2d1bd32bfb734ac2d670b0c1262302721eb6040f
4
+ data.tar.gz: c7b2aabc864f537bb8c2d037eff5a5906674840d
5
5
  SHA512:
6
- metadata.gz: edbcc038df62a9793359da3842eedfdee9f2d498f926e7100742ac0592c7e527f2c2ee6f74f8c71384d768203ae76b2a8ac7f38b153ea2de522380baa1a1fb0c
7
- data.tar.gz: 0d6e5322228b67d435706f55bdf3e3b92c18a9e18586983d2212f9d5e937bdd9677a5d870fe35fa5e2a20855238c63feac5f83f4a78c336b92b88102c5077673
6
+ metadata.gz: 13573bf09a741d47532d3c2bea0a453f1f99ae27abb254b26c85f11bad22719409d71e57a3a52e4bb9c570a82ce358e32f4adc33b4abca829da5fb85a1a77751
7
+ data.tar.gz: e348c59bad88fd9394e8c9b5076bed0ce63010d3e1d98e1bfa1457ae331bda2bf74f1e479f106794c6d9d59d0004b24b58bb14b714af855fbfe7f04bde02cb59
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Vagrant Unison Plugin
1
+ # Vagrant Unison 2 Plugin
2
2
 
3
3
  This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that syncs files over SSH from a local folder
4
4
  to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://www.cis.upenn.edu/~bcpierce/unison/)
@@ -7,12 +7,12 @@ to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://
7
7
 
8
8
  ## Features
9
9
 
10
- * Unisoned folder support via `unison` over `ssh` -> will work with any vagrant provider, eg Virtualbox or AWS.
10
+ * Unisoned folder support via `unison` over `ssh` -> will work with any vagrant provider, eg Virtualbox or AWS, though it's most tested on a local VM via Virtualbox.
11
11
 
12
12
  ## Usage
13
13
 
14
14
  1. You must already have [Unison](http://www.cis.upenn.edu/~bcpierce/unison/) installed and in your path.
15
- * On Mac you can install this with Homebrew: `brew install unison` (on Yosemite you will have to use https://rudix-mountainlion.googlecode.com/files/unison-2.40.102-0.pkg)
15
+ * On Mac you can install this with Homebrew: `brew install unison`
16
16
  * On Unix (Ubuntu) install using `sudo apt-get install unison`
17
17
  * On Windows, download [2.40.102](http://alan.petitepomme.net/unison/assets/Unison-2.40.102.zip), unzip, rename `Unison-2.40.102 Text.exe` to `unison.exe` and copy to somewhere in your path.
18
18
  1. Install using standard Vagrant 1.1+ plugin installation methods.
@@ -32,18 +32,20 @@ end
32
32
  ```
33
33
  1. Start up your starting your vagrant box as normal (eg: `vagrant up`)
34
34
 
35
+
35
36
  ## Start syncing Folders
36
37
 
37
38
  Run `vagrant unison-sync-once` to run a single, non-interactive sync and then exit.
38
39
 
39
- Run `vagrant unison-sync` to sync then start watching the local_folder for changes, and syncing these to your vagrang VM.
40
+ Run `vagrant unison-sync-polling` to start in bidirect monitor (repeat) mode - every second unison checks for changes on either side and syncs them.
41
+
42
+ ## (Legacy) Sync using OSX inotify events
40
43
 
41
- Under the covers this uses your system installation of [Unison](http://www.cis.upenn.edu/~bcpierce/unison/),
42
- which must be installed in your path.
44
+ Run `vagrant unison-sync` to sync then start watching the local_folder for changes, and syncing these to your vagrang VM.
43
45
 
44
- ## Start syncing Folders with polling (unison repeat mode)
46
+ This uses the `watch` ruby gem and runs a one-off unison sync when it gets change events.
45
47
 
46
- Run `vagrant unison-sync-polling` to start in bidirect monitor (repeat) mode - every second unison checks for changes on either side and syncs them.
48
+ For some reason, this does not always get all the events immediately which can be frustrating. Since the polling mode (unison repeat mode) is not too resource intensive, I recommend that instead.
47
49
 
48
50
  ## Sync in interactive mode
49
51
 
@@ -56,6 +58,12 @@ This is a useful tool when the automatic sync sees a change in a file on both
56
58
  sides and skips it.
57
59
 
58
60
  ## Cleanup unison database
61
+ Run `vagrant unison-cleanup` to clear the unison metadata from `~/Library/Application Support/Unison/` as well as all files.
62
+
63
+ ## Error states
64
+
65
+ ### Inconsistent state with unison metadata
66
+
59
67
  When you get
60
68
  ```
61
69
  Fatal error: Warning: inconsistent state.
@@ -67,9 +75,23 @@ Please delete archive files as appropriate and try again
67
75
  or invoke Unison with -ignorearchives flag.
68
76
  ```
69
77
 
70
- Run `vagrant unison-cleanup` to clear Archive from ~/Library/Application Support/Unison/ and files from host folder.
78
+ You should run a unison-cleanup
79
+
71
80
  Running Unison with -ignorearchives flag is a bad idea, since it will produce conflicts.
72
81
 
82
+ ### Skipping files changed on both sides
83
+
84
+ This is most often caused in my experience by files that get changed by different users with different permissions.
85
+
86
+ For instance, if you're running an Ubuntu VM then the unison process is running
87
+ as the vagrant user. If you have the unison synced folder loaded as a volume in
88
+ a docker container and a new file gets created in the container, the vagrant
89
+ user in the VM won't own that file and this can keep unison from being able to
90
+ sync the file. (I'm looking for a way to fix this particular error case).
91
+
92
+ Running a unison-cleanup should fix this state.
93
+
94
+
73
95
  ## Development
74
96
 
75
97
  To work on the `vagrant-unison` plugin, clone this repository out, and use
@@ -99,9 +99,12 @@ module VagrantPlugins
99
99
 
100
100
  class CommandPolling < Vagrant.plugin("2", :command)
101
101
  include UnisonSync
102
+ attr_accessor :bg_thread
102
103
 
103
104
  def execute
104
105
  with_target_vms do |machine|
106
+ @bg_thread = watch_vm_for_memory_leak(machine)
107
+
105
108
  execute_sync_command(machine) do |command|
106
109
  command.repeat = true
107
110
  command.terse = true
@@ -121,7 +124,10 @@ module VagrantPlugins
121
124
  exit_on_next_sigint = false
122
125
  system(command)
123
126
  rescue Interrupt
124
- exit 1 if exit_on_next_sigint
127
+ if exit_on_next_sigint
128
+ Thread.kill(@bg_thread) if @bg_thread
129
+ exit 1
130
+ end
125
131
  @env.ui.info '** Hit Ctrl + C again to kill. **'
126
132
  exit_on_next_sigint = true
127
133
  rescue Exception
@@ -130,9 +136,32 @@ module VagrantPlugins
130
136
  end
131
137
  end
132
138
  end
133
-
134
139
  0
135
140
  end
141
+
142
+ def watch_vm_for_memory_leak(machine)
143
+ ssh_command = SshCommand.new(machine)
144
+ unison_mem_cap_mb = 100
145
+ Thread.new(ssh_command.ssh, unison_mem_cap_mb) do |ssh_command_text, mem_cap_mb|
146
+ while true
147
+ sleep 15
148
+ total_mem = `#{ssh_command_text} 'free -m | egrep "^Mem:" | awk "{print \\$2}"' 2>/dev/null`
149
+ _unison_proc_returnval = `#{ssh_command_text} 'ps aux | grep "[u]nison -server" | awk "{print \\$2, \\$4}"' 2>/dev/null`
150
+ if _unison_proc_returnval == ''
151
+ puts "Unison not running in VM"
152
+ next
153
+ end
154
+ pid, mem_pct_unison = _unison_proc_returnval.strip.split(' ')
155
+ mem_unison = (total_mem.to_f * mem_pct_unison.to_f/100).round(1)
156
+ # Debugging: uncomment to log every loop tick
157
+ # puts "Unison running as #{pid} using #{mem_unison} mb"
158
+ if mem_unison > mem_cap_mb
159
+ puts "Unison using #{mem_unison} mb memory is over limit of #{mem_cap_mb}, restarting"
160
+ `#{ssh_command_text} kill -HUP #{pid} 2>/dev/null`
161
+ end
162
+ end
163
+ end
164
+ end
136
165
  end
137
166
 
138
167
  class CommandCleanup < Vagrant.plugin("2", :command)
@@ -1,9 +1,9 @@
1
1
  module VagrantPlugins
2
2
  module Unison
3
3
  class ShellCommand
4
- def initialize machine, paths, ssh_command
4
+ def initialize machine, unison_paths, ssh_command
5
5
  @machine = machine
6
- @paths = paths
6
+ @unison_paths = unison_paths
7
7
  @ssh_command = ssh_command
8
8
  end
9
9
 
@@ -25,13 +25,13 @@ module VagrantPlugins
25
25
  def args
26
26
  _args = [
27
27
  'unison',
28
- @paths.host,
29
- @ssh_command.uri,
28
+ @unison_paths.host,
29
+ @ssh_command.uri(@unison_paths),
30
30
  batch_arg,
31
31
  terse_arg,
32
32
  repeat_arg,
33
33
  ignore_arg,
34
- ['-sshargs', %("#{@ssh_command.command}")],
34
+ ['-sshargs', %("#{@ssh_command.ssh_args}")],
35
35
  ].flatten.compact
36
36
  _args
37
37
  end
@@ -1,14 +1,21 @@
1
1
  module VagrantPlugins
2
2
  module Unison
3
3
  class SshCommand
4
- def initialize(machine, unison_paths)
4
+ def initialize(machine)
5
5
  @machine = machine
6
- @unison_paths = unison_paths
7
6
  end
8
7
 
9
- def command
8
+ def ssh
10
9
  %W(
11
- -p #{ssh_info[:port]}
10
+ ssh
11
+ vagrant@127.0.0.1
12
+ #{ssh_args}
13
+ ).compact.join(' ')
14
+ end
15
+
16
+ def ssh_args
17
+ %W(
18
+ -p #{@machine.ssh_info[:port]}
12
19
  #{proxy_command}
13
20
  -o StrictHostKeyChecking=no
14
21
  -o UserKnownHostsFile=/dev/null
@@ -16,27 +23,23 @@ module VagrantPlugins
16
23
  ).compact.join(' ')
17
24
  end
18
25
 
19
- def uri
20
- username = ssh_info[:username]
21
- host = ssh_info[:host]
26
+ def uri(unison_paths)
27
+ username = @machine.ssh_info[:username]
28
+ host = @machine.ssh_info[:host]
22
29
 
23
- "ssh://#{username}@#{host}/#{@unison_paths.guest}"
30
+ "ssh://#{username}@#{host}/#{unison_paths.guest}"
24
31
  end
25
32
 
26
33
  private
27
34
 
28
35
  def proxy_command
29
- command = ssh_info[:proxy_command]
36
+ command = @machine.ssh_info[:proxy_command]
30
37
  return nil unless command
31
38
  "-o ProxyCommand='#{command}'"
32
39
  end
33
40
 
34
- def ssh_info
35
- @machine.ssh_info
36
- end
37
-
38
41
  def key_paths
39
- ssh_info[:private_key_path].map { |p| "-i #{p}" }.join(' ')
42
+ @machine.ssh_info[:private_key_path].map { |p| "-i #{p}" }.join(' ')
40
43
  end
41
44
  end
42
45
  end
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  machine.communicate.sudo("mkdir -p '#{guest_path}'")
13
13
  machine.communicate.sudo("chown #{machine.ssh_info[:username]} '#{guest_path}'")
14
14
 
15
- ssh_command = SshCommand.new(machine, unison_paths)
15
+ ssh_command = SshCommand.new(machine)
16
16
  shell_command = ShellCommand.new(machine, unison_paths, ssh_command)
17
17
 
18
18
  yield shell_command
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Unison
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-unison2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Laing
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-25 00:00:00.000000000 Z
13
+ date: 2016-03-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: listen