Class: DockerSync::SyncManager
- Inherits:
-
Object
- Object
- DockerSync::SyncManager
- Includes:
- Thor::Shell
- Defined in:
- lib/docker-sync/sync_manager.rb
Instance Method Summary collapse
- #clean(sync_name = nil) ⇒ Object
- #create_sync(sync_name, sync_configuration) ⇒ Object
- #get_sync_points ⇒ Object
- #global_options ⇒ Object
- #init_sync_processes(sync_name = nil) ⇒ Object
-
#initialize(options) ⇒ SyncManager
constructor
A new instance of SyncManager.
- #join_threads ⇒ Object
- #run(sync_name = nil) ⇒ Object
- #start_container(sync_name = nil) ⇒ Object
- #stop ⇒ Object
- #sync(sync_name = nil) ⇒ Object
- #upgrade_syncs_config ⇒ Object
- #watch_start ⇒ Object
- #watch_stop ⇒ Object
Constructor Details
#initialize(options) ⇒ SyncManager
Returns a new instance of SyncManager.
15 16 17 18 19 |
# File 'lib/docker-sync/sync_manager.rb', line 15 def initialize() @sync_processes = [] load_configuration() end |
Instance Method Details
#clean(sync_name = nil) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/docker-sync/sync_manager.rb', line 86 def clean(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.clean } end |
#create_sync(sync_name, sync_configuration) ⇒ Object
138 139 140 141 |
# File 'lib/docker-sync/sync_manager.rb', line 138 def create_sync(sync_name, sync_configuration) sync_process = DockerSync::SyncProcess.new(sync_name, sync_configuration) return sync_process end |
#get_sync_points ⇒ Object
25 26 27 |
# File 'lib/docker-sync/sync_manager.rb', line 25 def get_sync_points return @config_syncs end |
#global_options ⇒ Object
21 22 23 |
# File 'lib/docker-sync/sync_manager.rb', line 21 def return @config_global end |
#init_sync_processes(sync_name = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/docker-sync/sync_manager.rb', line 71 def init_sync_processes(sync_name = nil) return if @sync_processes.size != 0 if sync_name.nil? @config_syncs.each { |name, sync_configuration| @sync_processes.push(create_sync(name, sync_configuration)) } else unless @config_syncs.key?(sync_name) raise("Could not find sync configuration with name #{sync_name}") end @sync_processes.push(create_sync(sync_name, @config_syncs[sync_name])) end end |
#join_threads ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/docker-sync/sync_manager.rb', line 115 def join_threads begin @sync_processes.each do |sync_process| if sync_process.watch_thread sync_process.watch_thread.join end if sync_process.watch_fork Process.wait(sync_process.watch_fork) end end rescue SystemExit, Interrupt say_status 'shutdown', 'Shutting down...', :blue @sync_processes.each do |sync_process| sync_process.stop end rescue StandardError => e puts "EXCEPTION: #{e.inspect}" puts "MESSAGE: #{e.}" end end |
#run(sync_name = nil) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/docker-sync/sync_manager.rb', line 107 def run(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.run } end |
#start_container(sync_name = nil) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/docker-sync/sync_manager.rb', line 100 def start_container(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.start_container } end |
#stop ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/docker-sync/sync_manager.rb', line 143 def stop init_sync_processes @sync_processes.each { |sync_process| sync_process.stop unless sync_process.watch_thread.nil? sync_process.watch_thread.kill unless sync_process.watch_thread.nil? end } end |
#sync(sync_name = nil) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/docker-sync/sync_manager.rb', line 93 def sync(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.sync } end |
#upgrade_syncs_config ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/docker-sync/sync_manager.rb', line 29 def upgrade_syncs_config @config_syncs.each do |name, config| @config_syncs[name]['config_path'] = @config_path @config_syncs[name]['cli_mode'] = @config_global['cli_mode'] || 'auto' # set the global verbose setting, if the sync-endpoint does not define a own one unless config.key?('verbose') @config_syncs[name]['verbose'] = false if @config_global.key?('verbose') @config_syncs[name]['verbose'] = @config_global['verbose'] end end # set the global max_attempt setting, if the sync-endpoint does not define a own one unless config.key?('max_attempt') if @config_global.key?('max_attempt') @config_syncs[name]['max_attempt'] = @config_global['max_attempt'] end end if @config_syncs[name].key?('dest') puts 'Please do no longer use "dest" in your docker-sync.yml configuration - also see https://docker-sync.readthedocs.io/en/latest/getting-started/upgrade.html#id4' exit 1 else @config_syncs[name]['dest'] = '/app_sync' end # for each strategy check if a custom image has been defined and inject that into the sync-endpoints # which do fit for this strategy %w(rsync unison native_osx native).each do |strategy| if @config_global.key?("#{strategy}_image") @config_syncs[name]['image'] = @config_global["#{strategy}_image"] end if config.key?("#{strategy}_image") && @config_syncs[name]['sync_strategy'] == strategy @config_syncs[name]['image'] = config["#{strategy}_image"] end end end end |
#watch_start ⇒ Object
159 160 161 162 163 |
# File 'lib/docker-sync/sync_manager.rb', line 159 def watch_start @sync_processes.each { |sync_process| sync_process.watch } end |
#watch_stop ⇒ Object
153 154 155 156 157 |
# File 'lib/docker-sync/sync_manager.rb', line 153 def watch_stop @sync_processes.each { |sync_process| sync_process.watch_thread.kill unless sync_process.watch_thread.nil? } end |