What have you found for these years?

2009-09-17

remote_install.sh

2009-09-17 12:08
gist 是爛了喔!?永遠貼不完全是怎樣 O_o
只好把成果貼在這了。總之成果就是用三個 shell script
包裝的 rake task 跑安裝和啟動的 script, 分別是:

start.sh
install.sh
remote_install.sh

這樣就能在 local.start (rc.local in Arch?)
寫 sudo -i -u photo start.sh
因為這邊只吃 shell script, 所以才多包裝一層。
另一方面,多包這一層的好處是其他語言實作的東西,
不一定需要用 rake. 比方說 c 可能用 make,
java 可能用 ant, nginx 可能用 /usr/sbin/nginx
apache 可能用 apachectl. shell script 最中立了。
(當然,windows 完全是另外一個世界的東西,不考慮。)

裡面的內容大概是:

godfat ~/p/g/r/cas> cat start.sh 
#!/bin/sh

rake app:deploy
godfat ~/p/g/r/cas> cat install.sh
#!/bin/sh

gem install rake
rake app:install
./start.sh
godfat ~/p/g/r/cas> cat remote_install.sh
#!/bin/sh

rake app:install:remote host=10.0.0.124 \
git=git@github.com:scrazy/cas.git \
cd=~ \
branch=origin/stable \
script=./install.sh
godfat ~/p/g/r/cas>

最後一個 remote_install.sh 包括了全部,
他會 ssh 登入後,git clone, 放到 cd 的地方,
git checkout branch, 最後跑一個 shell command,
這邊跑上面設好的 install.sh, 在裡面跑 rake app:install,
安裝完之後跑 start.sh 啟動 server.

這些 app 開頭的 rake task, 則全部定義在 app-deploy 裡。
這裡面大部份的事情都是直接寫好的,除了其中一個:
rake app:server:restart
這一個在 app-deploy 裡是空的,要自己定義 server 重啟方式。
例如在相簿裡這邊就很複雜,大概長這樣:
desc 'restart all servers'
task :restart => ['my:daemon:restart',
'my:web_server:restart',
'my:img_server:restart'] do

pid = 'tmp/pids/nginx.pid'
# exists nginx process
if File.exist?(Roodo.expand(pid)) &&
`ps -p #{Roodo.file_read(pid).strip} -o comm=` =~ /nginx/

# TODO: passenger has a bug when sending -HUP to nginx
# Rake::Task['my:nginx:reload'].invoke

# restart if no exists nginx process
else
Rake::Task['my:nginx:restart'].invoke
end
end

這邊提到的 passenger 的 bug 印象中修好了,
不過既然這個 task 能動,短時間內也懶得調整。
以下是跑另一個 service 的 remote_install.sh 的輸出:
這裡的動作就非常複雜,要先安裝 bones,
然後 git clone app-deploy (如果原本就灌好,這步驟會跳過)
接著安裝好 app-deploy 後,就依照裡面的 task,
開始安裝各種 dependency... 這包括一般的 gem,
還有放在 github 上的 fork, 其中要注意的是,
gem 在安裝 local gem 時,不會自動抓 dependency,
所以要自己把 dependency 寫出來,必須事先安裝。
(唔,其實寫套件管理滿好玩的 @@")
godfat ~/p/g/r/cas> ./remote_install.sh
(in /Users/godfat/projects/gits/roodo/cas)
ssh 10.0.0.124 "cd ~; git clone git@github.com:scrazy/cas.git app-deploy-1253158871; find app-deploy-1253158871 -maxdepth 1 '!' -name app-deploy-1253158871 -exec mv '{}' . ';'; rmdir app-deploy-1253158871; git checkout origin/stable; ./install.sh"
Password:
Initialized empty Git repository in /home/godfat/app-deploy-1253158871/.git/
Initialized empty Git repository in /home/godfat/app-deploy-1253158871/.git/
Note: moving to "origin/stable" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b
HEAD is now at 8028cad... Merge branch 'master' into stable
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed rake-0.8.7
1 gem installed
/usr/bin/ruby18 /usr/bin/gem install --user-install --no-ri --no-rdoc bones
(in /home/godfat)
app-deploy not found, automaticly downloading and installing...
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
--------------------------
Keep rattlin' dem bones!
--------------------------
Successfully installed bones-2.5.1
1 gem installed
git clone git://github.com/godfat/app-deploy.git app-deploy
Initialized empty Git repository in /home/godfat/app-deploy/.git/
Initialized empty Git repository in /home/godfat/app-deploy/.git/
rake clobber
(in /home/godfat/app-deploy)
rm -r pkg
rm -r doc
rm -r ri
rm -r ann-app-deploy-0.5.0
rake gem:package
(in /home/godfat/app-deploy)
mkdir -p pkg
mkdir -p pkg/app-deploy-0.5.0
rm -f pkg/app-deploy-0.5.0/CHANGES
ln CHANGES pkg/app-deploy-0.5.0/CHANGES
rm -f pkg/app-deploy-0.5.0/README
ln README pkg/app-deploy-0.5.0/README
rm -f pkg/app-deploy-0.5.0/Rakefile
ln Rakefile pkg/app-deploy-0.5.0/Rakefile
rm -f pkg/app-deploy-0.5.0/TODO
ln TODO pkg/app-deploy-0.5.0/TODO
rm -f pkg/app-deploy-0.5.0/app-deploy.gemspec
ln app-deploy.gemspec pkg/app-deploy-0.5.0/app-deploy.gemspec
mkdir -p pkg/app-deploy-0.5.0/example
rm -f pkg/app-deploy-0.5.0/example/Rakefile
ln example/Rakefile pkg/app-deploy-0.5.0/example/Rakefile
rm -f pkg/app-deploy-0.5.0/example/daemon_cluster.yaml
ln example/daemon_cluster.yaml pkg/app-deploy-0.5.0/example/daemon_cluster.yaml
rm -f pkg/app-deploy-0.5.0/example/install.sh
ln example/install.sh pkg/app-deploy-0.5.0/example/install.sh
rm -f pkg/app-deploy-0.5.0/example/rack_cluster.yaml
ln example/rack_cluster.yaml pkg/app-deploy-0.5.0/example/rack_cluster.yaml
rm -f pkg/app-deploy-0.5.0/example/start.sh
ln example/start.sh pkg/app-deploy-0.5.0/example/start.sh
mkdir -p pkg/app-deploy-0.5.0/lib
rm -f pkg/app-deploy-0.5.0/lib/app-deploy.rb
ln lib/app-deploy.rb pkg/app-deploy-0.5.0/lib/app-deploy.rb
mkdir -p pkg/app-deploy-0.5.0/lib/app-deploy
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/daemon.rake
ln lib/app-deploy/daemon.rake pkg/app-deploy-0.5.0/lib/app-deploy/daemon.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/daemon.rb
ln lib/app-deploy/daemon.rb pkg/app-deploy-0.5.0/lib/app-deploy/daemon.rb
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/daemon_cluster.rb
ln lib/app-deploy/daemon_cluster.rb pkg/app-deploy-0.5.0/lib/app-deploy/daemon_cluster.rb
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/deploy.rake
ln lib/app-deploy/deploy.rake pkg/app-deploy-0.5.0/lib/app-deploy/deploy.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/gem.rake
ln lib/app-deploy/gem.rake pkg/app-deploy-0.5.0/lib/app-deploy/gem.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/git.rake
ln lib/app-deploy/git.rake pkg/app-deploy-0.5.0/lib/app-deploy/git.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/install.rake
ln lib/app-deploy/install.rake pkg/app-deploy-0.5.0/lib/app-deploy/install.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/merb.rake
ln lib/app-deploy/merb.rake pkg/app-deploy-0.5.0/lib/app-deploy/merb.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/mongrel.rake
ln lib/app-deploy/mongrel.rake pkg/app-deploy-0.5.0/lib/app-deploy/mongrel.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/nginx.rake
ln lib/app-deploy/nginx.rake pkg/app-deploy-0.5.0/lib/app-deploy/nginx.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/rack.rake
ln lib/app-deploy/rack.rake pkg/app-deploy-0.5.0/lib/app-deploy/rack.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/rack_cluster.rb
ln lib/app-deploy/rack_cluster.rb pkg/app-deploy-0.5.0/lib/app-deploy/rack_cluster.rb
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/server.rake
ln lib/app-deploy/server.rake pkg/app-deploy-0.5.0/lib/app-deploy/server.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/thin.rake
ln lib/app-deploy/thin.rake pkg/app-deploy-0.5.0/lib/app-deploy/thin.rake
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/utils.rb
ln lib/app-deploy/utils.rb pkg/app-deploy-0.5.0/lib/app-deploy/utils.rb
rm -f pkg/app-deploy-0.5.0/lib/app-deploy/version.rb
ln lib/app-deploy/version.rb pkg/app-deploy-0.5.0/lib/app-deploy/version.rb
mkdir -p pkg
mkdir -p pkg/app-deploy-0.5.0/tasks
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/ann.rake pkg/app-deploy-0.5.0/tasks/ann.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/svn.rake pkg/app-deploy-0.5.0/tasks/svn.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/gem.rake pkg/app-deploy-0.5.0/tasks/gem.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/zentest.rake pkg/app-deploy-0.5.0/tasks/zentest.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/bones.rake pkg/app-deploy-0.5.0/tasks/bones.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/setup.rb pkg/app-deploy-0.5.0/tasks/setup.rb
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/test.rake pkg/app-deploy-0.5.0/tasks/test.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/notes.rake pkg/app-deploy-0.5.0/tasks/notes.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/rdoc.rake pkg/app-deploy-0.5.0/tasks/rdoc.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/post_load.rake pkg/app-deploy-0.5.0/tasks/post_load.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/git.rake pkg/app-deploy-0.5.0/tasks/git.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/rubyforge.rake pkg/app-deploy-0.5.0/tasks/rubyforge.rake
ln /home/godfat/.gem/ruby/1.8/gems/bones-2.5.1/lib/bones/tasks/spec.rake pkg/app-deploy-0.5.0/tasks/spec.rake
cd pkg
app-deploy-0.5.0/
app-deploy-0.5.0/CHANGES
app-deploy-0.5.0/app-deploy.gemspec
app-deploy-0.5.0/TODO
app-deploy-0.5.0/tasks/
app-deploy-0.5.0/tasks/ann.rake
app-deploy-0.5.0/tasks/svn.rake
app-deploy-0.5.0/tasks/gem.rake
app-deploy-0.5.0/tasks/zentest.rake
app-deploy-0.5.0/tasks/bones.rake
app-deploy-0.5.0/tasks/setup.rb
app-deploy-0.5.0/tasks/test.rake
app-deploy-0.5.0/tasks/notes.rake
app-deploy-0.5.0/tasks/rdoc.rake
app-deploy-0.5.0/tasks/post_load.rake
app-deploy-0.5.0/tasks/git.rake
tar zcvf app-deploy-0.5.0.tgz app-deploy-0.5.0
app-deploy-0.5.0/tasks/rubyforge.rake
app-deploy-0.5.0/tasks/spec.rake
app-deploy-0.5.0/README
app-deploy-0.5.0/lib/
app-deploy-0.5.0/lib/app-deploy.rb
app-deploy-0.5.0/lib/app-deploy/
app-deploy-0.5.0/lib/app-deploy/rack_cluster.rb
app-deploy-0.5.0/lib/app-deploy/utils.rb
app-deploy-0.5.0/lib/app-deploy/mongrel.rake
app-deploy-0.5.0/lib/app-deploy/gem.rake
app-deploy-0.5.0/lib/app-deploy/daemon.rb
app-deploy-0.5.0/lib/app-deploy/daemon.rake
app-deploy-0.5.0/lib/app-deploy/merb.rake
app-deploy-0.5.0/lib/app-deploy/install.rake
app-deploy-0.5.0/lib/app-deploy/server.rake
app-deploy-0.5.0/lib/app-deploy/version.rb
app-deploy-0.5.0/lib/app-deploy/daemon_cluster.rb
app-deploy-0.5.0/lib/app-deploy/deploy.rake
app-deploy-0.5.0/lib/app-deploy/nginx.rake
app-deploy-0.5.0/lib/app-deploy/git.rake
app-deploy-0.5.0/lib/app-deploy/rack.rake
app-deploy-0.5.0/lib/app-deploy/thin.rake
app-deploy-0.5.0/Rakefile
app-deploy-0.5.0/example/
app-deploy-0.5.0/example/rack_cluster.yaml
app-deploy-0.5.0/example/daemon_cluster.yaml
app-deploy-0.5.0/example/start.sh
app-deploy-0.5.0/example/Rakefile
app-deploy-0.5.0/example/install.sh
Successfully built RubyGem
Name: app-deploy
Version: 0.5.0
File: app-deploy-0.5.0.gem
cd -
cd pkg/app-deploy-0.5.0
mv app-deploy-0.5.0.gem ../app-deploy-0.5.0.gem
cd -
Successfully installed app-deploy-0.5.0
1 gem installed
/usr/bin/ruby18 /usr/bin/gem install --user-install --no-ri --no-rdoc --local pkg/app-deploy-*.gem
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
/usr/bin/ruby18 /usr/bin/gem install hoe
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed rubyforge-1.0.5
Successfully installed hoe-2.3.3
2 gems installed
/usr/bin/ruby18 /usr/bin/gem install rack
Successfully installed rack-1.0.0
1 gem installed
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
/usr/bin/ruby18 /usr/bin/gem install markaby
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed builder-2.1.2
Successfully installed markaby-0.5
2 gems installed
/usr/bin/ruby18 /usr/bin/gem install activesupport
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed activesupport-2.3.4
1 gem installed
/usr/bin/ruby18 /usr/bin/gem install activerecord
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed activerecord-2.3.4
1 gem installed
/usr/bin/ruby18 /usr/bin/gem install gettext
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed locale-2.0.4
Successfully installed gettext-2.0.4
2 gems installed
/usr/bin/ruby18 /usr/bin/gem install newgem
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Building native extensions. This could take a while...
PostInstall.txt
Successfully installed rubigen-1.5.2
Successfully installed RedCloth-4.2.2
Successfully installed syntax-1.0.0
Successfully installed newgem-1.5.2
4 gems installed
git submodule init
git submodule update
Cloning picnic...
git clone git://github.com/godfat/picnic.git picnic
Initialized empty Git repository in /home/godfat/app-deploy/picnic/.git/
Initialized empty Git repository in /home/godfat/app-deploy/picnic/.git/
git --git-dir picnic/.git gc
git clone git://github.com/godfat/rubycas-server.git rubycas-server
Cloning rubycas-server...
Initialized empty Git repository in /home/godfat/app-deploy/rubycas-server/.git/
Initialized empty Git repository in /home/godfat/app-deploy/rubycas-server/.git/
git --git-dir rubycas-server/.git gc
/usr/bin/ruby18 /usr/bin/gem install mongrel

Installing mongrel...
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Building native extensions. This could take a while...
Building native extensions. This could take a while...
Successfully installed gem_plugin-0.2.3
Successfully installed daemons-1.0.10
Successfully installed fastthread-1.0.7
Successfully installed cgi_multipart_eof_fix-2.5.0
Successfully installed mongrel-1.1.5
5 gems installed
/usr/bin/ruby18 /usr/bin/gem install mysqlplus

Installing mysqlplus...
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Building native extensions. This could take a while...
Successfully installed mysqlplus-0.1.1
1 gem installed
rake gem

Installing picnic...
/home/godfat/app-deploy/picnic/Rakefile:25: warning: already initialized constant REV
Hoe.new {...} deprecated. Switch to Hoe.spec.
(in /home/godfat/app-deploy/picnic)
** README.txt is missing or in the wrong format for auto-intuiting.
run `sow blah` and look at its text files
WARNING: HOE DEPRECATION: Add '>= 0' to the 'rack' dependency.
WARNING: HOE DEPRECATION: Add '>= 0' to the 'markaby' dependency.
WARNING: HOE DEPRECATION: Add '>= 0' to the 'activesupport' dependency.
mkdir -p pkg
WARNING: description and summary are identical
mv picnic-0.8.1.200909171145.gem pkg/picnic-0.8.1.200909171145.gem
Successfully built RubyGem
Name: picnic
Version: 0.8.1.200909171145
File: picnic-0.8.1.200909171145.gem
/usr/bin/ruby18 /usr/bin/gem install --local pkg/picnic-*.gem --no-ri --no-rdoc
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Successfully installed picnic-0.8.1.200909171145
1 gem installed

Installing rubycas-server...
rake gem
Hoe.new {...} deprecated. Switch to Hoe.spec.
(in /home/godfat/app-deploy/rubycas-server)
** README.txt is missing or in the wrong format for auto-intuiting.
run `sow blah` and look at its text files
WARNING: HOE DEPRECATION: Add '>= 0' to the 'activesupport' dependency.
WARNING: HOE DEPRECATION: Add '>= 0' to the 'activerecord' dependency.
WARNING: HOE DEPRECATION: Add '>= 0' to the 'locale' dependency.
WARNING: HOE DEPRECATION: Add '>= 0' to the 'gettext' dependency.
mkdir -p pkg
WARNING: description and summary are identical
mv rubycas-server-0.7.99999.200909171145.gem pkg/rubycas-server-0.7.99999.200909171145.gem
Successfully built RubyGem
Name: rubycas-server
Version: 0.7.99999.200909171145
File: rubycas-server-0.7.99999.200909171145.gem
/usr/bin/ruby18 /usr/bin/gem install --local pkg/rubycas-server-*.gem --no-ri --no-rdoc
WARNING: You don't have /home/godfat/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.

For more information on RubyCAS-Server, see http://code.google.com/p/rubycas-server

Successfully installed rubycas-server-0.7.99999.200909171145
1 gem installed
git stash
(in /home/godfat)
Stashing...
No local changes to save
rubycas-server-ctl restart --config /home/godfat/config.yml --pid_file /home/godfat/casserver.pid
/home/godfat/casserver.pid not found. Is rubycas-server running?
Loading picnic from rubygems...
Restarting rubycas-server...
rubycas-server-ctl start --config /home/godfat/config.yml --pid_file /home/godfat/casserver.pid
Loading picnic from rubygems...
Starting rubycas-server...
godfat ~/p/g/r/cas>

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0