Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
grifork v0.2 example and log

※この例では、ローカルで echo するだけで ssh も rsync もしない。

% cat tmp/Griforkfile
branches 2
hosts 1.upto(14).map { |i| "app%03d" % [i] }

local do
  sh :echo, %W(LOCAL: #{src} => #{dst})
end

remote do
  sh :echo, %W(REMOTE: #{src} => #{dst})
end
% ./bin/grifork
Load settings from tmp/Griforkfile
# デバッグで生成される木構造をプリントしている
<0:0.0>
  <1:0.0-1.0>
    <3:0.0-1.0-2.0>
      <7:0.0-1.0-2.0-3.0>
      <8:0.0-1.0-2.0-3.1>
    <4:0.0-1.0-2.1>
      <9:0.0-1.0-2.1-3.0>
      <10:0.0-1.0-2.1-3.1>
  <2:0.0-1.1>
    <5:0.0-1.1-2.0>
      <11:0.0-1.1-2.0-3.0>
      <12:0.0-1.1-2.0-3.1>
    <6:0.0-1.1-2.1>
      <13:0.0-1.1-2.1-3.0>
      <14:0.0-1.1-2.1-3.1>
I, [2016-09-28T08:52:42.712148 #11746]  INFO -- : Run locally. localhost => app001
I, [2016-09-28T08:52:42.712567 #11746]  INFO -- : #sh start - echo ["LOCAL:", "localhost", "=>", "app001"]
I, [2016-09-28T08:52:42.713655 #11746]  INFO -- : Run locally. localhost => app002
I, [2016-09-28T08:52:42.713796 #11746]  INFO -- : #sh start - echo ["LOCAL:", "localhost", "=>", "app002"]
I, [2016-09-28T08:52:42.714283 #11746]  INFO -- : #sh [out] LOCAL: localhost => app001
I, [2016-09-28T08:52:42.714967 #11746]  INFO -- : #sh [out] LOCAL: localhost => app002
I, [2016-09-28T08:52:42.715415 #11746]  INFO -- : Run remote [1]. app001 => app003
I, [2016-09-28T08:52:42.715551 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app001", "=>", "app003"]
I, [2016-09-28T08:52:42.716494 #11746]  INFO -- : Run remote [1]. app001 => app004
I, [2016-09-28T08:52:42.716770 #11746]  INFO -- : #sh [out] REMOTE: app001 => app003
I, [2016-09-28T08:52:42.716885 #11746]  INFO -- : Run remote [1]. app002 => app005
I, [2016-09-28T08:52:42.717012 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app001", "=>", "app004"]
I, [2016-09-28T08:52:42.717141 #11746]  INFO -- : Run remote [1]. app002 => app006
I, [2016-09-28T08:52:42.717418 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app002", "=>", "app005"]
I, [2016-09-28T08:52:42.718370 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app002", "=>", "app006"]
I, [2016-09-28T08:52:42.719265 #11746]  INFO -- : #sh [out] REMOTE: app001 => app004
I, [2016-09-28T08:52:42.719567 #11746]  INFO -- : #sh [out] REMOTE: app002 => app005
I, [2016-09-28T08:52:42.719846 #11746]  INFO -- : #sh [out] REMOTE: app002 => app006
I, [2016-09-28T08:52:42.720590 #11746]  INFO -- : Run remote [2]. app003 => app007
I, [2016-09-28T08:52:42.720699 #11746]  INFO -- : Run remote [2]. app003 => app008
I, [2016-09-28T08:52:42.720804 #11746]  INFO -- : Run remote [2]. app004 => app009
I, [2016-09-28T08:52:42.720907 #11746]  INFO -- : Run remote [2]. app004 => app010
I, [2016-09-28T08:52:42.721009 #11746]  INFO -- : Run remote [2]. app005 => app011
I, [2016-09-28T08:52:42.721092 #11746]  INFO -- : Run remote [2]. app005 => app012
I, [2016-09-28T08:52:42.721217 #11746]  INFO -- : Run remote [2]. app006 => app013
I, [2016-09-28T08:52:42.721310 #11746]  INFO -- : Run remote [2]. app006 => app014
I, [2016-09-28T08:52:42.721410 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app003", "=>", "app007"]
I, [2016-09-28T08:52:42.721621 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app003", "=>", "app008"]
I, [2016-09-28T08:52:42.721767 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app004", "=>", "app009"]
I, [2016-09-28T08:52:42.720907 #11746]  INFO -- : Run remote [2]. app004 => app010
I, [2016-09-28T08:52:42.721009 #11746]  INFO -- : Run remote [2]. app005 => app011
I, [2016-09-28T08:52:42.721092 #11746]  INFO -- : Run remote [2]. app005 => app012
I, [2016-09-28T08:52:42.721217 #11746]  INFO -- : Run remote [2]. app006 => app013
I, [2016-09-28T08:52:42.721310 #11746]  INFO -- : Run remote [2]. app006 => app014
I, [2016-09-28T08:52:42.721410 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app003", "=>", "app007"]
I, [2016-09-28T08:52:42.721621 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app003", "=>", "app008"]
I, [2016-09-28T08:52:42.721767 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app004", "=>", "app009"]
I, [2016-09-28T08:52:42.721920 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app004", "=>", "app010"]
I, [2016-09-28T08:52:42.721980 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app005", "=>", "app011"]
I, [2016-09-28T08:52:42.722049 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app005", "=>", "app012"]
I, [2016-09-28T08:52:42.722111 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app006", "=>", "app013"]
I, [2016-09-28T08:52:42.722192 #11746]  INFO -- : #sh start - echo ["REMOTE:", "app006", "=>", "app014"]
I, [2016-09-28T08:52:42.723285 #11746]  INFO -- : #sh [out] REMOTE: app003 => app007
I, [2016-09-28T08:52:42.724364 #11746]  INFO -- : #sh [out] REMOTE: app003 => app008
I, [2016-09-28T08:52:42.724535 #11746]  INFO -- : #sh [out] REMOTE: app004 => app009
I, [2016-09-28T08:52:42.724888 #11746]  INFO -- : #sh [out] REMOTE: app004 => app010
I, [2016-09-28T08:52:42.725252 #11746]  INFO -- : #sh [out] REMOTE: app005 => app011
I, [2016-09-28T08:52:42.725673 #11746]  INFO -- : #sh [out] REMOTE: app005 => app012
I, [2016-09-28T08:52:42.726170 #11746]  INFO -- : #sh [out] REMOTE: app006 => app013
I, [2016-09-28T08:52:42.726435 #11746]  INFO -- : #sh [out] REMOTE: app006 => app014
I, [2016-09-28T08:52:42.727001 #11746]  INFO -- : Reached bottom of the tree. Nothing to do.
[app@step1 grifork]$ cat tmp/Griforkfile.grifork 
branches 2
log file: 'tmp/grifork.log', level: 'info'

hosts (1..14).to_a.map { |i| "app#{i}" }

grifork do
  user 'app'
  chdir '/home/app/grifork'
  tmpdir '/home/app/tmp'
  exec './run.sh'
end

local do
  rsync '/home/app/foo/', '/home/app/foo/'
end

remote do
  rsync '/home/app/foo/', '/home/app/foo/'
end

rbenv ruby で起動するコマンドを↑の DSL で記述するのが面倒だったので、grifork を実行するためのちょっとしたラッパースクリプト書いた:

[app@step1 grifork]$ cat run.sh 
#!/usr/bin/env bash

PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"

exec bundle exec ./bin/grifork "$@"
[app@step1 grifork]$ ./bin/grifork -f tmp/Griforkfile.grifork 
Load settings from tmp/Griforkfile.grifork
I, [2016-10-01T16:28:29.689417 #11120]  INFO -- : Run locally. localhost => app1
I, [2016-10-01T16:28:29.689922 #11120]  INFO -- : #sh start - rsync ["-avzc", "--delete", "/home/app/foo/", "app1:/home/app/foo/"]
I, [2016-10-01T16:28:29.691386 #11123]  INFO -- : Run locally. localhost => app2
I, [2016-10-01T16:28:29.691813 #11123]  INFO -- : #sh start - rsync ["-avzc", "--delete", "/home/app/foo/", "app2:/home/app/foo/"]
I, [2016-10-01T16:28:29.933663 #11123]  INFO -- : #sh [out] sending incremental file list
I, [2016-10-01T16:28:29.944708 #11120]  INFO -- : #sh [out] sending incremental file list
I, [2016-10-01T16:28:30.070348 #11120]  INFO -- : #sh [out] 
I, [2016-10-01T16:28:30.070564 #11120]  INFO -- : #sh [out] sent 27186 bytes  received 13 bytes  18132.67 bytes/sec
I, [2016-10-01T16:28:30.070597 #11120]  INFO -- : #sh [out] total size is 10240000  speedup is 376.48
I, [2016-10-01T16:28:30.071351 #11120]  INFO -- : #ssh start - to: app1, command: test -d "/home/app/tmp" || mkdir -p "/home/app/tmp" []
I, [2016-10-01T16:28:30.073730 #11123]  INFO -- : #sh [out] 
I, [2016-10-01T16:28:30.073801 #11123]  INFO -- : #sh [out] sent 27186 bytes  received 13 bytes  18132.67 bytes/sec
I, [2016-10-01T16:28:30.073830 #11123]  INFO -- : #sh [out] total size is 10240000  speedup is 376.48
I, [2016-10-01T16:28:30.074080 #11123]  INFO -- : #ssh start - to: app2, command: test -d "/home/app/tmp" || mkdir -p "/home/app/tmp" []
I, [2016-10-01T16:28:30.292727 #11123]  INFO -- : #sh start - rsync ["-avzc", "tmp/Griforkfile.grifork", "app2:/home/app/tmp/Griforkfile"]
I, [2016-10-01T16:28:30.295635 #11120]  INFO -- : #sh start - rsync ["-avzc", "tmp/Griforkfile.grifork", "app1:/home/app/tmp/Griforkfile"]
I, [2016-10-01T16:28:30.512850 #11123]  INFO -- : #sh [out] sending incremental file list
I, [2016-10-01T16:28:30.514993 #11123]  INFO -- : #sh [out] Griforkfile.grifork
I, [2016-10-01T16:28:30.516346 #11120]  INFO -- : #sh [out] sending incremental file list
I, [2016-10-01T16:28:30.518314 #11120]  INFO -- : #sh [out] Griforkfile.grifork
I, [2016-10-01T16:28:30.558429 #11123]  INFO -- : #sh [out] 
I, [2016-10-01T16:28:30.558609 #11123]  INFO -- : #sh [out] sent 360 bytes  received 37 bytes  794.00 bytes/sec
I, [2016-10-01T16:28:30.558699 #11123]  INFO -- : #sh [out] total size is 531  speedup is 1.34
I, [2016-10-01T16:28:30.559932 #11123]  INFO -- : #sh start - rsync ["-avzc", "/tmp/Griforkfile.hosts20161001-11123-15xz8u7", "app2:/home/app/tmp/Griforkfile.hosts"]
I, [2016-10-01T16:28:30.560668 #11120]  INFO -- : #sh [out] 
I, [2016-10-01T16:28:30.560757 #11120]  INFO -- : #sh [out] sent 360 bytes  received 37 bytes  794.00 bytes/sec
I, [2016-10-01T16:28:30.560853 #11120]  INFO -- : #sh [out] total size is 531  speedup is 1.34
I, [2016-10-01T16:28:30.561216 #11120]  INFO -- : #sh start - rsync ["-avzc", "/tmp/Griforkfile.hosts20161001-11120-1udrsr9", "app1:/home/app/tmp/Griforkfile.hosts"]
I, [2016-10-01T16:28:30.768222 #11123]  INFO -- : #sh [out] sending incremental file list
I, [2016-10-01T16:28:30.771027 #11120]  INFO -- : #sh [out] sending incremental file list
I, [2016-10-01T16:28:30.813599 #11123]  INFO -- : #sh [out] 
I, [2016-10-01T16:28:30.813755 #11123]  INFO -- : #sh [out] sent 94 bytes  received 15 bytes  218.00 bytes/sec
I, [2016-10-01T16:28:30.813783 #11123]  INFO -- : #sh [out] total size is 65  speedup is 0.60
I, [2016-10-01T16:28:30.814478 #11123]  INFO -- : #ssh start - to: app2, command: cd /home/app/grifork && ./run.sh --file /home/app/tmp/Griforkfile --override-by /home/app/tmp/Griforkfile.hosts --on-remote []
I, [2016-10-01T16:28:30.815685 #11120]  INFO -- : #sh [out] 
I, [2016-10-01T16:28:30.815761 #11120]  INFO -- : #sh [out] sent 94 bytes  received 15 bytes  218.00 bytes/sec
I, [2016-10-01T16:28:30.815788 #11120]  INFO -- : #sh [out] total size is 62  speedup is 0.57
I, [2016-10-01T16:28:30.815905 #11120]  INFO -- : #ssh start - to: app1, command: cd /home/app/grifork && ./run.sh --file /home/app/tmp/Griforkfile --override-by /home/app/tmp/Griforkfile.hosts --on-remote []
I, [2016-10-01T16:28:31.438087 #11120]  INFO -- : #ssh @app1 [out] Load settings from /home/app/tmp/Griforkfile
I, [2016-10-01T16:28:31.438247 #11120]  INFO -- : #ssh @app1 [out] Start on remote. Hosts: ["app3", "app4", "app7", "app8", "app9", "app10"]
I, [2016-10-01T16:28:31.473605 #11123]  INFO -- : #ssh @app2 [out] Load settings from /home/app/tmp/Griforkfile
I, [2016-10-01T16:28:31.473761 #11123]  INFO -- : #ssh @app2 [out] Start on remote. Hosts: ["app5", "app6", "app11", "app12", "app13", "app14"]
I, [2016-10-01T16:28:35.036487 #11123]  INFO -- : #ssh @app2 [out] End on remote.
I, [2016-10-01T16:28:35.103096 #11120]  INFO -- : #ssh @app1 [out] End on remote.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment