Skip to content
Browse files

All SCM commands now use sudo if user provided, directories updated t…

…o support user/group other than root.
  • Loading branch information...
1 parent bd695c3 commit adc8a1af65e9e87475d0cdca2c5a089ae920f4b0 @zpinter zpinter committed
Showing with 34 additions and 9 deletions.
  1. +10 −0 lib/chef-deploy.rb
  2. +14 −7 lib/chef-deploy/cached_deploy.rb
  3. +3 −1 lib/chef-deploy/git.rb
  4. +7 −1 lib/chef-deploy/subversion.rb
View
10 lib/chef-deploy.rb
@@ -80,6 +80,14 @@ def user(arg=nil)
)
end
+ def group(arg=nil)
+ set_or_return(
+ :group,
+ arg,
+ :kind_of => [ String ]
+ )
+ end
+
def enable_submodules(arg=false)
set_or_return(
:enable_submodules,
@@ -154,6 +162,7 @@ def load_current_resource
FileUtils.mkdir_p "#{@new_resource.name}/shared"
FileUtils.mkdir_p "#{@new_resource.name}/releases"
@dep = CachedDeploy.new :user => @new_resource.user,
+ :group => @new_resource.group,
:role => @new_resource.role,
:branch => (@new_resource.branch || 'HEAD'),
:restart_command => (@new_resource.restart_command || ""),
@@ -185,6 +194,7 @@ def action_rollback
@dep.rollback
Chef::Log.level(Chef::Config[:log_level])
end
+
end
end
end
View
21 lib/chef-deploy/cached_deploy.rb
@@ -17,6 +17,9 @@ def deploy
return
end
+ Chef::Log.info "ensuring proper ownership"
+ chef_run("chown -R #{user}:#{group} #{@configuration[:deploy_to]}")
+
Chef::Log.info "deploying branch: #{@configuration[:branch]} rev: #{@configuration[:revision]}"
Chef::Log.info "updating the cached checkout"
chef_run(update_repository_cache)
@@ -90,7 +93,7 @@ def migrate
if @configuration[:migrate]
chef_run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
Chef::Log.info "Migrating: cd #{latest_release} && sudo -u #{user} RAILS_ENV=#{@configuration[:environment]} RACK_ENV=#{@configuration[:environment]} MERB_ENV=#{@configuration[:environment]} #{@configuration[:migration_command]}"
- chef_run("chown -R #{user}:#{user} #{latest_release}")
+ chef_run("chown -R #{user}:#{group} #{latest_release}")
chef_run("cd #{latest_release} && sudo -u #{user} RAILS_ENV=#{@configuration[:environment]} RACK_ENV=#{@configuration[:environment]} MERB_ENV=#{@configuration[:environment]} #{@configuration[:migration_command]}")
end
end
@@ -99,6 +102,10 @@ def user
@configuration[:user] || 'nobody'
end
+ def group
+ @configuration[:group] || user
+ end
+
def current_path
"#{@configuration[:deploy_to]}/current"
end
@@ -124,13 +131,13 @@ def symlink(release_to_link=latest_release)
"ln -nfs #{shared_path}/system #{release_to_link}/public/system",
"ln -nfs #{shared_path}/pids #{release_to_link}/tmp/pids",
"ln -nfs #{shared_path}/config/database.yml #{release_to_link}/config/database.yml",
- "chown -R #{user}:#{user} #{release_to_link}"
+ "chown -R #{user}:#{group} #{release_to_link}"
].join(" && ")
symlink = true
- chef_run "rm -f #{current_path} && ln -nfs #{release_to_link} #{current_path} && chown -R #{user}:#{user} #{current_path}"
+ chef_run "rm -f #{current_path} && ln -nfs #{release_to_link} #{current_path} && chown -R #{user}:#{group} #{current_path}"
rescue => e
- chef_run "rm -f #{current_path} && ln -nfs #{previous_release(release_to_link)} #{current_path} && chown -R #{user}:#{user} #{current_path}" if symlink
+ chef_run "rm -f #{current_path} && ln -nfs #{previous_release(release_to_link)} #{current_path} && chown -R #{user}:#{group} #{current_path}" if symlink
chef_run "rm -rf #{release_to_link}"
raise e
end
@@ -219,8 +226,8 @@ def repository_cache
def update_repository_cache
command = "if [ -d #{repository_cache} ]; then " +
- "sudo -u #{user} #{source.sync(revision, repository_cache)}; " +
- "else sudo -u #{user} #{source.checkout(revision, repository_cache)}; fi"
+ "#{source.sync(revision, repository_cache)}; " +
+ "else #{source.checkout(revision, repository_cache)}; fi"
command
end
@@ -244,4 +251,4 @@ def mark
def copy_exclude
@copy_exclude ||= Array(configuration.fetch(:copy_exclude, []))
end
-end
+end
View
4 lib/chef-deploy/git.rb
@@ -13,7 +13,9 @@ def configuration
end
def git
- configuration[:git_ssh_wrapper] ? "GIT_SSH=#{configuration[:git_ssh_wrapper]} git" : 'git'
+ res = configuration[:git_ssh_wrapper] ? "GIT_SSH=#{configuration[:git_ssh_wrapper]} git" : 'git'
+ res = "sudo -u #{configuration[:user]} #{res}" if configuration[:user]
+ res
end
def respository
View
8 lib/chef-deploy/subversion.rb
@@ -85,8 +85,14 @@ def verbose
"-q"
end
+ def svn
+ res = "svn"
+ res = "sudo -u #{config[:user]} #{res}" if config[:user]
+ res
+ end
+
def scm(*args)
- ['svn', *args].compact.join(" ")
+ [svn, *args].compact.join(" ")
end
def svn_password_prompt

0 comments on commit adc8a1a

Please sign in to comment.
Something went wrong with that request. Please try again.