Class: Docker_Sync::SyncStrategy::Rsync
- Inherits:
-
Object
- Object
- Docker_Sync::SyncStrategy::Rsync
- Includes:
- Thor::Shell
- Defined in:
- lib/docker_sync/sync_strategy/rsync.rb
Instance Method Summary collapse
- #clean ⇒ Object
-
#initialize(sync_name, options) ⇒ Rsync
constructor
A new instance of Rsync.
- #reset_container ⇒ Object
- #run ⇒ Object
- #start_container ⇒ Object
- #stop ⇒ Object
- #stop_container ⇒ Object
- #sync ⇒ Object
- #sync_options ⇒ Object
Constructor Details
#initialize(sync_name, options) ⇒ Rsync
Returns a new instance of Rsync.
11 12 13 14 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 11 def initialize(sync_name, ) @sync_name = sync_name = end |
Instance Method Details
#clean ⇒ Object
85 86 87 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 85 def clean reset_container end |
#reset_container ⇒ Object
79 80 81 82 83 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 79 def reset_container stop_container `docker rm #{@sync_name}` `docker volume rm #{@sync_name}` end |
#run ⇒ Object
16 17 18 19 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 16 def run start_container sync end |
#start_container ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 51 def start_container say_status 'ok', 'Starting rsync', :white running = `docker ps --filter 'status=running' --filter 'name=#{@sync_name}' | grep #{@sync_name}` if running == '' say_status 'ok', "#{@sync_name} container not running", :white exists = `docker ps --filter "status=exited" --filter "name=filesync_dw" | grep filesync_dw` if exists == '' say_status 'ok', "creating #{@sync_name} container", :white cmd = "docker run -p '#{@options['sync_host_port']}:873' -v #{@sync_name}:#{@options['dest']} -e VOLUME=#{@options['dest']} --name #{@sync_name} -d eugenmayer/rsync" else say_status 'success', "starting #{@sync_name} container", :green cmd = "docker start #{@sync_name}" end say_status 'command', cmd, :white `#{cmd}` || raise('Start failed') else say_status 'ok', "#{@sync_name} container still running", :blue end say_status 'success', "starting initial #{@sync_name} of src", :green # this sleep is needed since the container could be not started sleep 1 sync end |
#stop ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 89 def stop say_status 'ok', "Stopping sync container #{@sync_name}" begin stop_container rescue Exception => e say_status 'error', "Stopping failed of #{@sync_name}:", :red puts e. end end |
#stop_container ⇒ Object
75 76 77 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 75 def stop_container `docker stop #{@sync_name}` end |
#sync ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 21 def sync args = cmd = 'rsync ' + args.join(' ') say_status 'command', cmd, :white if ['verbose'] out = `#{cmd}` if $?.exitstatus > 0 say_status 'error', "Error starting sync, exit code #{$?.exitstatus}", :red say_status 'message', out else say_status 'success', "Synced #{@options['src']}", :green if ['verbose'] say_status 'output', out end end end |
#sync_options ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/docker_sync/sync_strategy/rsync.rb', line 39 def args = [] unless ['sync_excludes'].nil? args = ['sync_excludes'].map { |pattern| "--exclude='#{pattern}'" } + args end args.push('-ap') args.push(['sync_args']) if .key?('sync_args') args.push("#{@options['src']}/") # add a trailing slash args.push("rsync://#{@options['sync_host_ip']}:#{@options['sync_host_port']}/volume") end |