Skip to content

Commit

Permalink
adding restart_command to deploy resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezra Zygmuntowicz committed Apr 14, 2009
1 parent 0f4836d commit 77d74ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
18 changes: 11 additions & 7 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ A gem that provides resources and providers for deploying ruby web apps from che
Uses the same directory layout as capistrano and steals the git remote cached deploy strategy
from cap and adapts it to work without cap and under chef

deploy "/data/myapp" do
repo "git://github.com/engineyard/rack-app.git"
branch "HEAD"
enable_submodules true
shallow_clone true
action :manage
end
deploy "/data/#{app}" do
repo "git://github.com/engineyard/rack-app.git"
branch "HEAD"
user "ez"
enable_submodules true
migrate true
migration_command "rake db:migrate"
environment "production"
shallow_clone true
action :manage
end


Currently only supports doing the cached git checkout, rsyncing it into place and doing the symlink dance.
Expand Down
12 changes: 12 additions & 0 deletions lib/chef-deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# branch "HEAD"
# user "ez"
# enable_submodules true
# migrate true
# migration_command "rake db:migrate"
# environment "production"
# shallow_clone true
# action :manage
# end
Expand Down Expand Up @@ -34,6 +37,14 @@ def repo(arg=nil)
)
end

def restart_command(arg=nil)
set_or_return(
:restart_command,
arg,
:kind_of => [ String ]
)
end

def migrate(arg=nil)
set_or_return(
:migrate,
Expand Down Expand Up @@ -129,6 +140,7 @@ def action_manage
Chef::Log.level(:debug)
Chef::Log.info "Running a new deploy\nto: #{@new_resource.name}\nrepo: #{@new_resource.repo}"
dep = CachedDeploy.new :user => @new_resource.user,
:restart_command => @new_resource.restart_command,
:repository => @new_resource.repo,
:environment => @new_resource.environment,
:migration_command => @new_resource.migration_command,
Expand Down
15 changes: 12 additions & 3 deletions lib/chef-deploy/cached_deploy.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# stolen wholesale from capistrano, thanks Jamis!

class ChefDeployFailure < StandardError
end

class CachedDeploy
# Executes the SCM command for this strategy and writes the REVISION
# mark file to each host.
def deploy
@buffer = []
@configuration[:release_path] = "#{@configuration[:deploy_to]}/releases/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}"
@configuration[:revision] ||= source.query_revision('HEAD') {|cmd| run cmd}
Chef::Log.info "updating the cached checkout"
Expand All @@ -16,7 +18,14 @@ def deploy
callback(:before_symlink)
symlink
callback(:before_restart)
@buffer
restart
end

def restart
unless @configuration[:restart_command].empty?
Chef::Log.info "restarting app: #{latest_release}"
Chef::Log.info run(@configuration[:restart_command])
end
end

# before_symlink
Expand Down Expand Up @@ -101,7 +110,7 @@ def symlink

def run(cmd)
res = `#{cmd}`
@buffer << res
raise ChefDeployFailure unless $? == 0
res
end

Expand Down

0 comments on commit 77d74ba

Please sign in to comment.