vagrant-vaimo-unison 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a719989697e0e88a4de615042660811d231c216f
4
- data.tar.gz: 3b907f1f4483815e27f7969e985689e006c6f3aa
3
+ metadata.gz: 319e8a96dda86e57d96b6f6dbb1705074774d25b
4
+ data.tar.gz: 52c3960d155fed81eb047570804862511fb4c4de
5
5
  SHA512:
6
- metadata.gz: f9f004ed178a759e3847aa46c5d02042c15a951ddf03a1d51d9075e506b66e656f3bf5142971fd4097361cdef80bb1acb70410b2c615a03d82405fcafe474e0e
7
- data.tar.gz: 3466c2cf67c6f77e1112567e3f68205bf3fb4ff72930859ab09adfd893d9beab26d35fdee9caec68093e01b95f7d0a8b3ceedd168d9331dd4305544a0758442e
6
+ metadata.gz: 8193b9ae8c364c2d5800fb87e1ac9d1238a2bfa369d72fa6367c42408bd683c2cf1f027c4b051a638f253ed379f871e1d219a128d016b5928fbadadd2d89778f
7
+ data.tar.gz: 0ff882e69b5d70deab46614a9e0d81d18ceffbe7cedeffc4ecd7a1febac11509b0b089177ece4d51d0477e2d32f21c46e9277be4c361c1e650af1db21c26eb37
@@ -9,7 +9,7 @@ require_relative 'unison_sync'
9
9
 
10
10
  module VagrantPlugins
11
11
  module Unison
12
- class CommandSync < Vagrant.plugin("2", :command)
12
+ class CommandSync < Vagrant.plugin('2', :command)
13
13
  include UnisonSync
14
14
  attr_accessor :bg_thread
15
15
 
@@ -18,16 +18,48 @@ module VagrantPlugins
18
18
  end
19
19
 
20
20
  def execute
21
+ sync_once
22
+ sync_polling
23
+ end
24
+
25
+ def sync_once
26
+ status = nil
27
+ with_target_vms do |machine|
28
+ execute_sync_command(machine) do |command|
29
+ command.batch = true
30
+ command.terse = true
31
+ command = command.to_s
32
+
33
+ @env.ui.info 'Started main sync process'
34
+ if options[:verbose]
35
+ @env.ui.info ' Verbose mode: enabled'
36
+ @env.ui.info " Command: #{command}"
37
+ end
38
+
39
+ status = system(command)
40
+ @env.ui.info 'unison exited with a error' unless status
41
+ end
42
+ end
43
+ return 0 if status
44
+
45
+ 1
46
+ end
47
+
48
+ def sync_polling
21
49
  status = nil
22
50
  with_target_vms do |machine|
23
51
  @bg_thread = watch_vm_for_memory_leak(machine)
24
52
  execute_sync_command(machine) do |command|
25
53
  command.repeat = true
26
- command.batch = true
27
54
  command.terse = true
28
55
  command = command.to_s
29
56
 
30
- @env.ui.info "Running #{command}"
57
+ @env.ui.info 'Polling process started'
58
+ if options[:verbose]
59
+ @env.ui.info ' Verbose mode: enabled'
60
+ @env.ui.info " Memory limit: #{machine.config.unison.mem_cap_mb}MB"
61
+ @env.ui.info " Command: #{command}" if options[:verbose]
62
+ end
31
63
 
32
64
  # Re-run on a crash.
33
65
  # On a sigint, wait 2 seconds before respawning command.
@@ -54,9 +86,7 @@ module VagrantPlugins
54
86
  end
55
87
  end
56
88
  end
57
- if status
58
- return 0
59
- end
89
+ return 0 if status
60
90
 
61
91
  1
62
92
  end
@@ -66,18 +96,18 @@ module VagrantPlugins
66
96
  Thread.new(ssh_command.ssh, machine.config.unison.mem_cap_mb) do |ssh_command_text, mem_cap_mb|
67
97
  while true
68
98
  sleep 15
69
- total_mem = `#{ssh_command_text} 'free -m | egrep "^Mem:" | awk "{print \\$2}"' 2>/dev/null`
70
- _unison_proc_returnval = (
71
- `#{ssh_command_text} 'ps aux | grep "[u]nison -server" | awk "{print \\$2, \\$4}"' 2>/dev/null`
72
- )
73
- if _unison_proc_returnval == ''
99
+ total_mem = `#{ssh_command_text} 'free -m | egrep "^Mem:" | awk "{print \\$2}"' 2>/dev/null`
100
+ unison_proc_returnval = `#{ssh_command_text} 'ps aux | grep "[u]nison -server" | awk "{print \\$2, \\$4}"' 2>/dev/null`
101
+
102
+ if unison_proc_returnval == ''
74
103
  puts 'Unison not running in VM'
75
104
  next
76
105
  end
77
- pid, mem_pct_unison = _unison_proc_returnval.strip.split(' ')
78
- mem_unison = (total_mem.to_f * mem_pct_unison.to_f / 100).round(1)
79
- # Debugging: uncomment to log every loop tick
80
- # puts "Unison running as #{pid} using #{mem_unison} mb"
106
+
107
+ pid, mem_pct_unison = unison_proc_returnval.strip.split(' ')
108
+ mem_unison = (total_mem.to_f * mem_pct_unison.to_f / 100)
109
+ mem_unison = mem_unison.round(1)
110
+
81
111
  if mem_unison > mem_cap_mb
82
112
  puts "Unison using #{mem_unison}MB memory is over limit of #{mem_cap_mb}MB, restarting"
83
113
  `#{ssh_command_text} kill -HUP #{pid} 2>/dev/null`
@@ -91,20 +121,20 @@ module VagrantPlugins
91
121
  include UnisonSync
92
122
 
93
123
  def self.synopsis
94
- 'sync the unison shared folder once'
124
+ 'sync the unison shared folder once (deprecated)'
95
125
  end
96
126
 
97
127
  def execute
98
- @env.ui.info 'The command is deprecated, use vagrant unison-sync'
128
+ @env.ui.info 'The command is deprecated, use vagrant unison-sync --no-polling'
99
129
  end
100
130
  end
101
131
 
102
- class CommandPolling < Vagrant.plugin("2", :command)
132
+ class CommandPolling < Vagrant.plugin('2', :command)
103
133
  include UnisonSync
104
134
  attr_accessor :bg_thread
105
135
 
106
136
  def self.synopsis
107
- 'sync the unison shared folder forever, by polling for changes'
137
+ 'sync the unison shared folder forever, by polling for changes (deprecated)'
108
138
  end
109
139
 
110
140
  def execute
@@ -14,11 +14,14 @@ module VagrantPlugins
14
14
  guest_path = unison_paths.guest
15
15
  host_path = unison_paths.host
16
16
 
17
- @env.ui.info "Unisoning changes from {host}::#{host_path} --> {guest VM}::#{guest_path}"
17
+ ssh_user = machine.config.unison.ssh_user
18
+
19
+ @env.ui.info "Sync changes from {host}::#{host_path}"
20
+ @env.ui.info " --> {guest VM}::#{guest_path}"
18
21
 
19
22
  # Create the guest path
20
23
  machine.communicate.sudo("mkdir -p '#{guest_path}'")
21
- machine.communicate.sudo("chown #{machine.config.unison.ssh_user} '#{guest_path}'")
24
+ machine.communicate.sudo("chown #{ssh_user} '#{guest_path}'")
22
25
 
23
26
  ssh_command = SshCommand.new(machine)
24
27
  shell_command = ShellCommand.new(machine, unison_paths, ssh_command)
@@ -52,12 +55,13 @@ module VagrantPlugins
52
55
 
53
56
  def options
54
57
  @options ||= {
55
- :prefer_local => false,
56
- :prefer_remote => false,
57
- :force_local => false,
58
- :force_remote => false,
59
- :verbose => false,
60
- :project => nil,
58
+ :prefer_local => false,
59
+ :prefer_remote => false,
60
+ :force_local => false,
61
+ :force_remote => false,
62
+ :verbose => false,
63
+ :project => nil,
64
+ :no_polling => false
61
65
  }
62
66
  end
63
67
 
@@ -65,6 +69,10 @@ module VagrantPlugins
65
69
  @option_parser ||= OptionParser.new do |o|
66
70
  o.banner = "Usage: vagrant #{ARGV[0]} [options]"
67
71
 
72
+ # o.on('--no-polling', 'trigger sync without starting the polling process') do |flag|
73
+ # options[:no_polling] = flag
74
+ # end
75
+
68
76
  o.on('--push', 'prefer changes on the local machine.') do |flag|
69
77
  options[:prefer_local] = flag
70
78
  check_conflicting_options!
@@ -85,12 +93,12 @@ module VagrantPlugins
85
93
  check_conflicting_options!
86
94
  end
87
95
 
88
- o.on('--verbose', 'Print additional debug information') do |flag|
96
+ o.on('--verbose', 'print additional debug information') do |flag|
89
97
  options[:verbose] = flag
90
98
  end
91
99
 
92
- o.on('-p', '--project=project', 'Project') do |project|
93
- options[:project] = project;
100
+ o.on('-p', '--project=project', 'project folder to sync') do |project|
101
+ options[:project] = project
94
102
  end
95
103
  end
96
104
  end
@@ -99,6 +107,7 @@ module VagrantPlugins
99
107
  enabled = [:prefer_local, :prefer_remote, :force_local, :force_remote].select do |opt|
100
108
  options[opt]
101
109
  end
110
+
102
111
  raise ArgumentError.new("Conflicting options: #{enabled.inspect}") if enabled.length > 1
103
112
  end
104
113
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Unison
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vaimo-unison
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Laing
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-01-05 00:00:00.000000000 Z
14
+ date: 2018-02-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: 1.3.6
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.5.1
116
+ rubygems_version: 2.5.2.1
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Vagrant plugin to sync local files to VM over SSH using Unison