From dd018bece086bfa008d2f184b33818a87383d555 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 19:07:51 +0900 Subject: [PATCH 01/17] updated .gitignore to ignore pre-compiled caches of python --- .gitignore | 2 ++ commands.pyc | Bin 1750 -> 0 bytes 2 files changed, 2 insertions(+) delete mode 100644 commands.pyc diff --git a/.gitignore b/.gitignore index 694da6c..1a85cff 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ lib .project .classpath dist +*.pyc +*.pyo diff --git a/commands.pyc b/commands.pyc deleted file mode 100644 index 44f06cebf6255f98e19db69041e0f24fdfb0efb5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1750 zcmcIkPjBNy6o2C+ZktWEyTE}9(uh;E(%J+hkQRitYF8{`o36Zzkb*e4o@p{o;xV2v ztwnn(cRm(p?tBUkT;aWECoOE?hLah;_vZcmy*K{#_hJ9rKYp2H&^~>9KgH#K#7*H} zzye^pp#@CES{~e?J2366d!FWvN%z>t!upF4J0G7(bV{4&Bbi;S+|0cv@fKa=&2?SC|!}awFhctl0pF z4c2Uj+0L5nGTVhKuJ$|t`?C;OkO{z`67B(Ea1+3F4=%kR3EBW0eRnFZLjvY1g!2&W zi4bZRzIg6?U_!#Ab%8p2WPdAZoU#z*LiM*>-2*j%o6Z}CYdP7rPItB`4apd5FP>tI z`~Mn))&7|r#%RnjMjoR5KH94X+nqezRvrsE#W(SIYnuTJ8IQLy%=bA6T;JpZg9Fao zJJ{uk=NYi8Rhlc`K}lK^zDw_N=2)QfACdqCthutP!eL8jKHYn`9onKc`Ai;e#*|2! z$S8`~q-EXv+qHQxOP!fQJ2Iizna$7KJ`x2^?c?=fdFu91)=YPV+~_|%Hd>NAnHl=! z8*?W~4*NGHnJ!D6s#@wxyl_rBD<>zf(L+<9@#JNECuEyBT`+l?W{X*At6a%tTIJbX zm(pdWDcFiGF5bq-&H2hXZwsQy*~DJRnUz`@FKb(s?Tu{{chclc#+$17Q^AdyY452q z)-h;B>gP}c!xNf-gj$f0ETP0X#_EiX zn)Va!z?=ILsd#QzI;H`tPEDG}7q(o))H&WBkE0KxkK%T4;%qY~c<@0qj^Hw)DBcxA2*ptJ#2D8n!3g(HaS=ZjqkE{$$hg`i%usa}T@y4k zJ5;^Ni^?bWNten)6m8-8Q%gBVgqGuz Date: Fri, 3 Feb 2012 19:09:23 +0900 Subject: [PATCH 02/17] added play:setup task to download & install play via HTTP --- conf/play-recipes.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 76b947d..7f9ce95 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -43,6 +43,47 @@ end namespace :play do + _cset :play_version, '1.2.4' + _cset :play_zip_url do + "http://download.playframework.org/releases/#{File.basename(play_zip_file)}" + end + _cset :play_zip_file do + File.join('/tmp', "play-#{play_version}.zip") + end + _cset :play_path do +# File.join(shared_path, "play-#{play_version}") + abort "you must specify install path for play" + end + _cset :play_cmd do + File.join(play_path, 'play') + end + _cset :play_preserve_zip, true + + namespace :setup do + desc "install play if needed" + task :default do + transaction { + install_play + } + end + + task :install_play do + on_rollback { + files = [ play_path ] + files << play_zip_file unless play_preserve_zip + run "rm -rf #{files.join(' ')}" + } + run "rm -f #{play_zip_file}" unless play_preserve_zip + run <<-E + if ! test -d #{play_path}; then + (test -f #{play_zip_file} || wget --no-verbose -o #{play_zip_file} #{play_zip_url}; true) && + unzip #{play_zip_file} -d #{File.dirname(play_path)} && test -x #{play_path}/play; + fi + E + run "rm -f #{play_zip_file}" unless play_preserve_zip + end + end + desc "view play pid" task :pid do run "cd #{app_path}; #{play_path}/play pid --pid_file=#{app_pid}" From e1c28fd57343b7cb0ebe0dea7559406c99e1b624 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 21:25:26 +0900 Subject: [PATCH 03/17] created play:daemonize to switch service configuration --- conf/play-recipes.rb | 68 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 7f9ce95..ddf61ad 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -29,16 +29,15 @@ namespace :deploy do task :start do - run "rm -f #{app_pid}; cd #{app_path}; chmod u+x run.sh; PLAY_PATH=#{play_path} PLAY_CMD=start nohup ./run.sh -Xss2048k --deps --pid_file=#{app_pid} --%prod 2>&1 >/dev/null" + play.start end task :restart do - stop - start + play.restart end task :stop do - run "cd #{app_path}; PLAY_PATH=#{play_path} PLAY_PID=#{app_pid} PLAY_APP=#{app_path} . ./stop.sh" + play.stop end end @@ -58,12 +57,17 @@ File.join(play_path, 'play') end _cset :play_preserve_zip, true + _cset :play_daemonize_method, :play + _cset :play_daemon do + daemonize.__send__(play_daemonize_method) + end namespace :setup do desc "install play if needed" task :default do transaction { install_play + play_daemon.setup } end @@ -84,19 +88,65 @@ end end - desc "view play pid" - task :pid do - run "cd #{app_path}; #{play_path}/play pid --pid_file=#{app_pid}" + namespace :daemonize do + namespace :play do + task :setup do + # nop + end + + task :start do + run "rm -f #{app_pid}" # FIXME: should check if the pid is active + run "cd #{current_path} && nohup #{play_cmd} start -Xss2048k --deps --pid_file=#{app_pid} --%prod" + end + + task :stop do + run "cd #{current_path} && #{play_cmd} stop --pid_file=#{app_pid}" + end + + task :restart do + stop + start + end + + desc "view play status" + task :status do + run "cd #{app_path} && #{play_cmd} status --pid_file=#{app_pid}" + end + end + + namespace :upstart do + # not implemented yet + end + end + + desc "start play service" + task :start do + play_daemon.start + end + + desc "stop play service" + task :stop do + play_daemon.stop + end + + desc "restart play service" + task :restart do + play_daemon.restart end desc "view play status" task :status do - run "cd #{app_path}; #{play_path}/play status --pid_file=#{app_pid}" + play_daemon.status end + desc "view play pid" + task :pid do + run "cd #{current_path} && #{play_cmd} pid --pid_file=#{app_pid}" + end + desc "view play version" task :version do - run "cd #{app_path}; #{play_path}/play version --pid_file=#{app_pid}" + run "cd #{current_path} && #{play_cmd} version --pid_file=#{app_pid}" end desc "view running play apps" From c41a2c0694820d5ff4d7d38f9a3c002c37237ca4 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 22:03:05 +0900 Subject: [PATCH 04/17] implemented play:daemonize:upstart --- commands.py | 1 + conf/play-recipes.rb | 48 ++++++++++++++++++++++++++++++++++++-- conf/templates/upstart.erb | 9 +++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 conf/templates/upstart.erb diff --git a/commands.py b/commands.py index 4748f5d..680d755 100644 --- a/commands.py +++ b/commands.py @@ -43,6 +43,7 @@ def execute(**kargs): shutil.copyfile(os.path.join(module, "Capfile"), os.path.join(app.path, "Capfile")) print "Copying Capistrano Play recipes..." shutil.copyfile(os.path.join(module, "conf", "play-recipes.rb"), os.path.join(app.path, "conf", "play-recipes.rb")) + shutil.copytree(os.path.join(module, "conf", "templates"), os.path.join(app.path, "conf", "templates")) if(not os.path.exists(os.path.join(app.path, "conf", "deploy.rb"))): print "Copying Capistrano Play deploy config..." diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index ddf61ad..b573dcc 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -57,6 +57,7 @@ File.join(play_path, 'play') end _cset :play_preserve_zip, true + _cset :play_modules, [] _cset :play_daemonize_method, :play _cset :play_daemon do daemonize.__send__(play_daemonize_method) @@ -67,6 +68,9 @@ task :default do transaction { install_play + install_modules + } + transaction { play_daemon.setup } end @@ -86,6 +90,12 @@ E run "rm -f #{play_zip_file}" unless play_preserve_zip end + + task :install_modules do + if 0 < play_modules.length + run "#{play_cmd} install #{play_modules.join(' ')}" + end + end end namespace :daemonize do @@ -108,14 +118,48 @@ start end - desc "view play status" task :status do run "cd #{app_path} && #{play_cmd} status --pid_file=#{app_pid}" end end namespace :upstart do - # not implemented yet + _cset :play_upstart_service do + application + end + _cset :play_upstart_config do + File.join('/etc', 'init', "#{play_upstart_service}.cfg") + end + _cset :play_upstart_config_template, File.join(File.dirname(__FILE__), 'templates', 'upstart.erb') + _cset :play_upstart_options, %w(--deps) + _cset :play_upstart_runner do + user + end + + task :setup do + template = File.read(play_upstart_config_template) + result = ERB.new(template).result(binding) + + tempfile = File.join('/tmp', File.basename(play_upstart_config)) + put result, tempfile + run "diff #{tempfile} #{play_upstart_config} || #{sudo} mv -f #{tempfile} #{play_upstart_config}" + end + + task :start do + run "#{sudo} service #{play_upstart_service} start" + end + + task :stop do + run "#{sudo} service #{play_upstart_service} stop" + end + + task :restart do + run "#{sudo} service #{play_upstart_service} restart || #{sudo} service #{play_upstart_service} start" + end + + task :status do + run "#{sudo} service #{play_upstart_service} status" + end end end diff --git a/conf/templates/upstart.erb b/conf/templates/upstart.erb new file mode 100644 index 0000000..1708085 --- /dev/null +++ b/conf/templates/upstart.erb @@ -0,0 +1,9 @@ +description <%= play_upstart_service.dump %> + +start on runlevel [2345] +stop on [016] + +respawn + +chdir <%= current_path %> +exec su <%= play_upstart_runner.dump %> -c '<%= play_cmd %> run <%= play_upstart_options.join(" ") %>' From cddfaf0d56fd3430c2366129e48cbcc184250022 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 22:10:12 +0900 Subject: [PATCH 05/17] defined targets for tasks explicitly. they all should work only for app. --- conf/play-recipes.rb | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index b573dcc..6850dc6 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -28,15 +28,15 @@ default_run_options[:pty] = true namespace :deploy do - task :start do + task :start, :roles => :app, :except => { :no_release => true } do play.start end - task :restart do + task :restart, :roles => :app, :except => { :no_release => true } do play.restart end - task :stop do + task :stop, :roles => :app, :except => { :no_release => true } do play.stop end end @@ -65,7 +65,7 @@ namespace :setup do desc "install play if needed" - task :default do + task :default, :except => { :no_release => true } do transaction { install_play install_modules @@ -75,7 +75,7 @@ } end - task :install_play do + task :install_play, :roles => :app, :except => { :no_release => true } do on_rollback { files = [ play_path ] files << play_zip_file unless play_preserve_zip @@ -91,7 +91,7 @@ run "rm -f #{play_zip_file}" unless play_preserve_zip end - task :install_modules do + task :install_modules, :roles => :app, :except => { :no_release => true } do if 0 < play_modules.length run "#{play_cmd} install #{play_modules.join(' ')}" end @@ -100,25 +100,25 @@ namespace :daemonize do namespace :play do - task :setup do + task :setup, :roles => :app, :except => { :no_release => true } do # nop end - task :start do + task :start, :roles => :app, :except => { :no_release => true } do run "rm -f #{app_pid}" # FIXME: should check if the pid is active run "cd #{current_path} && nohup #{play_cmd} start -Xss2048k --deps --pid_file=#{app_pid} --%prod" end - task :stop do + task :stop, :roles => :app, :except => { :no_release => true } do run "cd #{current_path} && #{play_cmd} stop --pid_file=#{app_pid}" end - task :restart do + task :restart, :roles => :app, :except => { :no_release => true } do stop start end - task :status do + task :status, :roles => :app, :except => { :no_release => true } do run "cd #{app_path} && #{play_cmd} status --pid_file=#{app_pid}" end end @@ -136,7 +136,7 @@ user end - task :setup do + task :setup, :roles => :app, :except => { :no_release => true } do template = File.read(play_upstart_config_template) result = ERB.new(template).result(binding) @@ -145,66 +145,66 @@ run "diff #{tempfile} #{play_upstart_config} || #{sudo} mv -f #{tempfile} #{play_upstart_config}" end - task :start do + task :start, :roles => :app, :except => { :no_release => true } do run "#{sudo} service #{play_upstart_service} start" end - task :stop do + task :stop, :roles => :app, :except => { :no_release => true } do run "#{sudo} service #{play_upstart_service} stop" end - task :restart do + task :restart, :roles => :app, :except => { :no_release => true } do run "#{sudo} service #{play_upstart_service} restart || #{sudo} service #{play_upstart_service} start" end - task :status do + task :status, :roles => :app, :except => { :no_release => true } do run "#{sudo} service #{play_upstart_service} status" end end end desc "start play service" - task :start do + task :start, :roles => :app, :except => { :no_release => true } do play_daemon.start end desc "stop play service" - task :stop do + task :stop, :roles => :app, :except => { :no_release => true } do play_daemon.stop end desc "restart play service" - task :restart do + task :restart, :roles => :app, :except => { :no_release => true } do play_daemon.restart end desc "view play status" - task :status do + task :status, :roles => :app, :except => { :no_release => true } do play_daemon.status end desc "view play pid" - task :pid do + task :pid, :roles => :app, :except => { :no_release => true } do run "cd #{current_path} && #{play_cmd} pid --pid_file=#{app_pid}" end desc "view play version" - task :version do + task :version, :roles => :app, :except => { :no_release => true } do run "cd #{current_path} && #{play_cmd} version --pid_file=#{app_pid}" end desc "view running play apps" - task :ps do + task :ps, :roles => :app, :except => { :no_release => true } do run "ps -eaf | grep 'play'" end desc "kill play processes" - task :kill do + task :kill, :roles => :app, :except => { :no_release => true } do run "ps -ef | grep 'play' | grep -v 'grep' | awk '{print $2}'| xargs -i kill {} ; echo ''" end desc "view logfiles" - task :logs, :roles => :app do + task :logs, :roles => :app, :except => { :no_release => true } do run "tail -f #{shared_path}/log/#{application}.log" do |channel, stream, data| puts # for an extra line break before the host name puts "#{channel[:host]}: #{data}" From 0b93c29158c1f76946b3c8cf264a1be2dc805097 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 22:35:45 +0900 Subject: [PATCH 06/17] added play:setup:setup_ivy to apply custom ivy configuration --- conf/play-recipes.rb | 17 +++++++++++++++++ conf/templates/ivysettings.erb | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 conf/templates/ivysettings.erb diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 6850dc6..788b090 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -67,6 +67,7 @@ desc "install play if needed" task :default, :except => { :no_release => true } do transaction { + setup_ivy install_play install_modules } @@ -75,6 +76,22 @@ } end + _cset :play_setup_ivy, false # true if you want to setup custom ivy configuration for play + _cset :play_ivy_settings do + File.join(capture('echo $HOME').chomp, '.ivy2', 'ivysettings.xml') + end + _cset :play_ivy_settings_template, File.join(File.dirname(__FILE__), 'templates', 'ivysettings.erb') + task :setup_ivy, :roles => :app, :except => { :no_release => true } do + if play_setup_ivy + template = File.read(play_ivy_settings_template) + result = ERB.new(template).result(binding) + tempfile = File.join('/tmp', File.basename(play_ivy_settings)) + run "test -d #{File.dirname(play_ivy_settings)} || mkdir -p #{File.dirname(play_ivy_settings)}" + put result, tempfile + run "diff #{tempfile} #{play_ivy_settings} || mv -f #{tempfile} #{play_ivy_settings}" + end + end + task :install_play, :roles => :app, :except => { :no_release => true } do on_rollback { files = [ play_path ] diff --git a/conf/templates/ivysettings.erb b/conf/templates/ivysettings.erb new file mode 100644 index 0000000..2db4a3a --- /dev/null +++ b/conf/templates/ivysettings.erb @@ -0,0 +1,2 @@ + + From 11a1dc0d3c0612b55bead437004ecdba5983a639 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 23:10:31 +0900 Subject: [PATCH 07/17] fixed problems on use_sudo==true --- conf/play-recipes.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 788b090..4bcc973 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -47,7 +47,7 @@ "http://download.playframework.org/releases/#{File.basename(play_zip_file)}" end _cset :play_zip_file do - File.join('/tmp', "play-#{play_version}.zip") + File.join(shared_path, "play-#{play_version}.zip") end _cset :play_path do # File.join(shared_path, "play-#{play_version}") @@ -96,16 +96,20 @@ on_rollback { files = [ play_path ] files << play_zip_file unless play_preserve_zip - run "rm -rf #{files.join(' ')}" + run "#{try_sudo} rm -rf #{files.join(' ')}" } - run "rm -f #{play_zip_file}" unless play_preserve_zip + run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip + + temp_zip = File.join('/tmp', File.basename(play_zip_file)) + temp_dir = File.join('/tmp', File.basename(play_zip_file, '.zip')) run <<-E if ! test -d #{play_path}; then - (test -f #{play_zip_file} || wget --no-verbose -o #{play_zip_file} #{play_zip_url}; true) && - unzip #{play_zip_file} -d #{File.dirname(play_path)} && test -x #{play_path}/play; + (test -f #{play_zip_file} || wget --no-verbose -O #{temp_zip} #{play_zip_url}; true) && + unzip #{temp_zip} -d /tmp && #{try_sudo} mv -f #{temp_dir} #{play_path} && + test -x #{play_path}/play; fi E - run "rm -f #{play_zip_file}" unless play_preserve_zip + run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip end task :install_modules, :roles => :app, :except => { :no_release => true } do From 00035205cbe8f98a88b60853932a06c3b7eb2453 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Feb 2012 23:16:55 +0900 Subject: [PATCH 08/17] * fixed wrong filename for upstart config * invoke play:setup after deploy:setup automaticaly --- conf/play-recipes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 4bcc973..2236362 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -41,6 +41,8 @@ end end +after 'deploy:setup', 'play:setup' + namespace :play do _cset :play_version, '1.2.4' _cset :play_zip_url do @@ -149,7 +151,7 @@ application end _cset :play_upstart_config do - File.join('/etc', 'init', "#{play_upstart_service}.cfg") + File.join('/etc', 'init', "#{play_upstart_service}.conf") end _cset :play_upstart_config_template, File.join(File.dirname(__FILE__), 'templates', 'upstart.erb') _cset :play_upstart_options, %w(--deps) From 444425c55d06305834ac8f40c2b2b3fc4a4339fe Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Sat, 4 Feb 2012 00:06:47 +0900 Subject: [PATCH 09/17] * fixed to save play_zip_file to specified file * defined default play_path --- conf/play-recipes.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 2236362..f144c03 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -52,8 +52,7 @@ File.join(shared_path, "play-#{play_version}.zip") end _cset :play_path do -# File.join(shared_path, "play-#{play_version}") - abort "you must specify install path for play" + File.join(shared_path, "play-#{play_version}") end _cset :play_cmd do File.join(play_path, 'play') @@ -101,15 +100,15 @@ run "#{try_sudo} rm -rf #{files.join(' ')}" } run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip - + temp_zip = File.join('/tmp', File.basename(play_zip_file)) temp_dir = File.join('/tmp', File.basename(play_zip_file, '.zip')) run <<-E - if ! test -d #{play_path}; then - (test -f #{play_zip_file} || wget --no-verbose -O #{temp_zip} #{play_zip_url}; true) && - unzip #{temp_zip} -d /tmp && #{try_sudo} mv -f #{temp_dir} #{play_path} && - test -x #{play_path}/play; - fi + ( test -f #{play_zip_file} || + ( wget --no-verbose -O #{temp_zip} #{play_zip_url} && #{try_sudo} mv -f #{temp_zip} #{play_zip_file}; true ) ) && + ( test -d #{play_path} || + ( unzip #{play_zip_file} -d /tmp && #{try_sudo} mv -f #{temp_dir} #{play_path}; true ) ) && + test -x #{play_path}/play; E run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip end From 95b2686e1ae0fb68168a91f46bf3fa7dcb43cc4d Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Sat, 4 Feb 2012 00:10:39 +0900 Subject: [PATCH 10/17] renamed variables with start with 'app_' to 'play_' to avoid name collision --- conf/play-recipes.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index f144c03..5a69629 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -63,6 +63,9 @@ _cset :play_daemon do daemonize.__send__(play_daemonize_method) end + _cset :play_pid_file do + fetch(:app_pid, File.join(shared_path, 'pids', 'server.pid')) # for backward compatibility + end namespace :setup do desc "install play if needed" @@ -127,12 +130,12 @@ end task :start, :roles => :app, :except => { :no_release => true } do - run "rm -f #{app_pid}" # FIXME: should check if the pid is active - run "cd #{current_path} && nohup #{play_cmd} start -Xss2048k --deps --pid_file=#{app_pid} --%prod" + run "rm -f #{play_pid_file}" # FIXME: should check if the pid is active + run "cd #{current_path} && nohup #{play_cmd} start -Xss2048k --deps --pid_file=#{play_pid_file} --%prod" end task :stop, :roles => :app, :except => { :no_release => true } do - run "cd #{current_path} && #{play_cmd} stop --pid_file=#{app_pid}" + run "cd #{current_path} && #{play_cmd} stop --pid_file=#{play_pid_file}" end task :restart, :roles => :app, :except => { :no_release => true } do @@ -141,7 +144,7 @@ end task :status, :roles => :app, :except => { :no_release => true } do - run "cd #{app_path} && #{play_cmd} status --pid_file=#{app_pid}" + run "cd #{current_path} && #{play_cmd} status --pid_file=#{play_pid_file}" end end @@ -207,12 +210,12 @@ desc "view play pid" task :pid, :roles => :app, :except => { :no_release => true } do - run "cd #{current_path} && #{play_cmd} pid --pid_file=#{app_pid}" + run "cd #{current_path} && #{play_cmd} pid --pid_file=#{play_pid_file}" end desc "view play version" task :version, :roles => :app, :except => { :no_release => true } do - run "cd #{current_path} && #{play_cmd} version --pid_file=#{app_pid}" + run "cd #{current_path} && #{play_cmd} version --pid_file=#{play_pid_file}" end desc "view running play apps" From 82aecee37d3192a77d389b09192486b3c4205155 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 9 Feb 2012 02:55:35 +0900 Subject: [PATCH 11/17] invoke `play deps' before start running. deployment and runtime users may be different. --- conf/play-recipes.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 5a69629..70594c1 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -42,6 +42,7 @@ end after 'deploy:setup', 'play:setup' +after 'deploy:update', 'play:update' namespace :play do _cset :play_version, '1.2.4' @@ -131,11 +132,11 @@ task :start, :roles => :app, :except => { :no_release => true } do run "rm -f #{play_pid_file}" # FIXME: should check if the pid is active - run "cd #{current_path} && nohup #{play_cmd} start -Xss2048k --deps --pid_file=#{play_pid_file} --%prod" + run "cd #{release_path} && nohup #{play_cmd} start -Xss2048k --pid_file=#{play_pid_file} --%prod" end task :stop, :roles => :app, :except => { :no_release => true } do - run "cd #{current_path} && #{play_cmd} stop --pid_file=#{play_pid_file}" + run "cd #{release_path} && #{play_cmd} stop --pid_file=#{play_pid_file}" end task :restart, :roles => :app, :except => { :no_release => true } do @@ -144,7 +145,7 @@ end task :status, :roles => :app, :except => { :no_release => true } do - run "cd #{current_path} && #{play_cmd} status --pid_file=#{play_pid_file}" + run "cd #{release_path} && #{play_cmd} status --pid_file=#{play_pid_file}" end end @@ -156,7 +157,7 @@ File.join('/etc', 'init', "#{play_upstart_service}.conf") end _cset :play_upstart_config_template, File.join(File.dirname(__FILE__), 'templates', 'upstart.erb') - _cset :play_upstart_options, %w(--deps) + _cset :play_upstart_options, [] _cset :play_upstart_runner do user end @@ -188,6 +189,17 @@ end end + desc "update play runtime environment" + task :update, :roles => :app, :except => { :no_release => true } do + transaction { + dependencies + } + end + + task :dependencies, :roles => :app, :except => { :no_release => true } do + run "cd #{release_path} && #{play_cmd} dependencies --forProd" + end + desc "start play service" task :start, :roles => :app, :except => { :no_release => true } do play_daemon.start From a514071da27f86d2ceee64fdd7258523a092c614 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 9 Feb 2012 15:55:50 +0900 Subject: [PATCH 12/17] made tmp/ group writable since deploy:finalize_update creates non-group-writable tmp/ --- conf/play-recipes.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 70594c1..9e74d9d 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -191,6 +191,9 @@ desc "update play runtime environment" task :update, :roles => :app, :except => { :no_release => true } do + # FIXME: made tmp/ group writable since deploy:finalize_update creates non-group-writable tmp/ + run "#{try_sudo} chmod g+w #{release_path}/tmp" if fetch(:group_writable, true) + transaction { dependencies } From 4e8592a31115cf4202cc82f7be5e690b98d8c0c1 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 9 Feb 2012 16:38:00 +0900 Subject: [PATCH 13/17] refactored --- conf/play-recipes.rb | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 9e74d9d..8f47cd7 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -24,6 +24,8 @@ # end # end +require 'erb' + # without this, there are problems with sudo on remote server default_run_options[:pty] = true @@ -72,7 +74,7 @@ desc "install play if needed" task :default, :except => { :no_release => true } do transaction { - setup_ivy + setup_ivy if fetch(:play_setup_ivy, false) install_play install_modules } @@ -81,20 +83,20 @@ } end - _cset :play_setup_ivy, false # true if you want to setup custom ivy configuration for play _cset :play_ivy_settings do File.join(capture('echo $HOME').chomp, '.ivy2', 'ivysettings.xml') end _cset :play_ivy_settings_template, File.join(File.dirname(__FILE__), 'templates', 'ivysettings.erb') task :setup_ivy, :roles => :app, :except => { :no_release => true } do - if play_setup_ivy - template = File.read(play_ivy_settings_template) - result = ERB.new(template).result(binding) - tempfile = File.join('/tmp', File.basename(play_ivy_settings)) - run "test -d #{File.dirname(play_ivy_settings)} || mkdir -p #{File.dirname(play_ivy_settings)}" - put result, tempfile - run "diff #{tempfile} #{play_ivy_settings} || mv -f #{tempfile} #{play_ivy_settings}" - end + tempfile = File.join('/tmp', File.basename(play_ivy_settings)) + on_rollback { + run "rm -f #{tempfile}" + } + template = File.read(play_ivy_settings_template) + result = ERB.new(template).result(binding) + run "test -d #{File.dirname(play_ivy_settings)} || mkdir -p #{File.dirname(play_ivy_settings)}" + put result, tempfile + run "diff #{tempfile} #{play_ivy_settings} || mv -f #{tempfile} #{play_ivy_settings}" end task :install_play, :roles => :app, :except => { :no_release => true } do @@ -112,7 +114,7 @@ ( wget --no-verbose -O #{temp_zip} #{play_zip_url} && #{try_sudo} mv -f #{temp_zip} #{play_zip_file}; true ) ) && ( test -d #{play_path} || ( unzip #{play_zip_file} -d /tmp && #{try_sudo} mv -f #{temp_dir} #{play_path}; true ) ) && - test -x #{play_path}/play; + test -x #{play_cmd}; E run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip end @@ -163,10 +165,12 @@ end task :setup, :roles => :app, :except => { :no_release => true } do + tempfile = File.join('/tmp', File.basename(play_upstart_config)) + on_rollback { + run "rm -f #{tempfile}" + } template = File.read(play_upstart_config_template) result = ERB.new(template).result(binding) - - tempfile = File.join('/tmp', File.basename(play_upstart_config)) put result, tempfile run "diff #{tempfile} #{play_upstart_config} || #{sudo} mv -f #{tempfile} #{play_upstart_config}" end From 9e0b8cd2e425b0e332dceea35e2399c328993687 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 9 Feb 2012 17:46:36 +0900 Subject: [PATCH 14/17] added play:precompile to build application before deploy:restart --- conf/play-recipes.rb | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 8f47cd7..690b300 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -51,6 +51,7 @@ _cset :play_zip_url do "http://download.playframework.org/releases/#{File.basename(play_zip_file)}" end + _cset :play_preserve_zip, true _cset :play_zip_file do File.join(shared_path, "play-#{play_version}.zip") end @@ -60,8 +61,6 @@ _cset :play_cmd do File.join(play_path, 'play') end - _cset :play_preserve_zip, true - _cset :play_modules, [] _cset :play_daemonize_method, :play _cset :play_daemon do daemonize.__send__(play_daemonize_method) @@ -76,17 +75,16 @@ transaction { setup_ivy if fetch(:play_setup_ivy, false) install_play - install_modules } transaction { play_daemon.setup } end + _cset :play_ivy_settings_template, File.join(File.dirname(__FILE__), 'templates', 'ivysettings.erb') _cset :play_ivy_settings do File.join(capture('echo $HOME').chomp, '.ivy2', 'ivysettings.xml') end - _cset :play_ivy_settings_template, File.join(File.dirname(__FILE__), 'templates', 'ivysettings.erb') task :setup_ivy, :roles => :app, :except => { :no_release => true } do tempfile = File.join('/tmp', File.basename(play_ivy_settings)) on_rollback { @@ -100,15 +98,15 @@ end task :install_play, :roles => :app, :except => { :no_release => true } do + temp_zip = File.join('/tmp', File.basename(play_zip_file)) + temp_dir = File.join('/tmp', File.basename(play_zip_file, '.zip')) on_rollback { - files = [ play_path ] + files = [ play_path, temp_zip, temp_dir ] files << play_zip_file unless play_preserve_zip run "#{try_sudo} rm -rf #{files.join(' ')}" } run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip - temp_zip = File.join('/tmp', File.basename(play_zip_file)) - temp_dir = File.join('/tmp', File.basename(play_zip_file, '.zip')) run <<-E ( test -f #{play_zip_file} || ( wget --no-verbose -O #{temp_zip} #{play_zip_url} && #{try_sudo} mv -f #{temp_zip} #{play_zip_file}; true ) ) && @@ -118,12 +116,6 @@ E run "#{try_sudo} rm -f #{play_zip_file}" unless play_preserve_zip end - - task :install_modules, :roles => :app, :except => { :no_release => true } do - if 0 < play_modules.length - run "#{play_cmd} install #{play_modules.join(' ')}" - end - end end namespace :daemonize do @@ -200,6 +192,7 @@ transaction { dependencies + precompile if fetch(:play_use_precompile, true) } end @@ -207,6 +200,10 @@ run "cd #{release_path} && #{play_cmd} dependencies --forProd" end + task :precompile, :roles => :app, :except => { :no_release => true } do + run "cd #{release_path} && #{play_cmd} precompile" + end + desc "start play service" task :start, :roles => :app, :except => { :no_release => true } do play_daemon.start From b94cf4c45c1233e5f14e7c571056fb3e5df3bb28 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 9 Feb 2012 19:40:12 +0900 Subject: [PATCH 15/17] specify '-Dprecompiled=true' to `play run|start` to use precompiled classes --- conf/play-recipes.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 690b300..10b3f4a 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -68,6 +68,7 @@ _cset :play_pid_file do fetch(:app_pid, File.join(shared_path, 'pids', 'server.pid')) # for backward compatibility end + _cset :play_use_precompile, true # performe precompilation before restarting service if true namespace :setup do desc "install play if needed" @@ -124,9 +125,16 @@ # nop end + _cset :play_start_options do + options = [] + options << "-Xss2048k" + options << "--%prod" + options << "-Dprecompiled=true" if play_use_precompile + options + end task :start, :roles => :app, :except => { :no_release => true } do run "rm -f #{play_pid_file}" # FIXME: should check if the pid is active - run "cd #{release_path} && nohup #{play_cmd} start -Xss2048k --pid_file=#{play_pid_file} --%prod" + run "cd #{release_path} && nohup #{play_cmd} start --pid_file=#{play_pid_file} #{play_start_options.join(' ')}" end task :stop, :roles => :app, :except => { :no_release => true } do @@ -151,7 +159,11 @@ File.join('/etc', 'init', "#{play_upstart_service}.conf") end _cset :play_upstart_config_template, File.join(File.dirname(__FILE__), 'templates', 'upstart.erb') - _cset :play_upstart_options, [] + _cset :play_upstart_options do + options = [] + options << "-Dprecompiled=true" if play_use_precompile + options + end _cset :play_upstart_runner do user end @@ -192,7 +204,7 @@ transaction { dependencies - precompile if fetch(:play_use_precompile, true) + precompile if play_use_precompile } end From 1d9ac91b2984e4eb8136862e694076d2f5db5a30 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Thu, 9 Feb 2012 21:26:52 +0900 Subject: [PATCH 16/17] add "-Dprecompiled=true" even if play_*_options is overridden --- conf/play-recipes.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index 10b3f4a..fee3732 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -129,11 +129,11 @@ options = [] options << "-Xss2048k" options << "--%prod" - options << "-Dprecompiled=true" if play_use_precompile options end task :start, :roles => :app, :except => { :no_release => true } do run "rm -f #{play_pid_file}" # FIXME: should check if the pid is active + play_start_options << "-Dprecompiled=true" if play_use_precompile run "cd #{release_path} && nohup #{play_cmd} start --pid_file=#{play_pid_file} #{play_start_options.join(' ')}" end @@ -161,7 +161,8 @@ _cset :play_upstart_config_template, File.join(File.dirname(__FILE__), 'templates', 'upstart.erb') _cset :play_upstart_options do options = [] - options << "-Dprecompiled=true" if play_use_precompile + options << "-Xss2048k" + options << "--%prod" options end _cset :play_upstart_runner do @@ -173,6 +174,7 @@ on_rollback { run "rm -f #{tempfile}" } + play_upstart_options << "-Dprecompiled=true" if play_use_precompile template = File.read(play_upstart_config_template) result = ERB.new(template).result(binding) put result, tempfile From 0c5d808a9e567d7022b9c1617e24f42efe8b872d Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 14 Feb 2012 13:11:00 +0900 Subject: [PATCH 17/17] invoke play:update before finishing deploy:update to enable rollback on failures of `play deps` or `play precompile`. --- conf/play-recipes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/play-recipes.rb b/conf/play-recipes.rb index fee3732..65071bd 100644 --- a/conf/play-recipes.rb +++ b/conf/play-recipes.rb @@ -44,7 +44,7 @@ end after 'deploy:setup', 'play:setup' -after 'deploy:update', 'play:update' +after 'deploy:finalize_update', 'play:update' namespace :play do _cset :play_version, '1.2.4'