質問

I've got capistrano 3 running perfectly with passwordless deploy as a non root user.

What I'm trying to do now is setup a install script that install's the upstart service, the sudoers.d file and installs some dependencies on the server.

so that I could install a new server by simply entering the user and host in the production.rb file and run cap production setupserver

the problem is that the setup scripts that I've created need to be run as root.

But since it's a one time thing, I'd simply like to ask the user for the root password and run a couple of tasks on the server.

the as :root command doesn't work since it uses su -c

I could ask for the password as demonstrated here http://capistranorb.com/documentation/faq/how-can-i-get-capistrano-to-prompt-for-a-password/

any suggestions on how to override the user specified in the production.rb file?

and how to pass the asked password?

役に立ちましたか?

解決

The way I finally solved it was by adding another role for the same server.

role :app, 'theappuser@myserver'
role :install, 'root@myserver', :no_release => true

And then doing something like this

desc 'Install nginx'
task :install do
  on roles(:install) do
    require 'erb'
    template = ERB.new(File.new('deploy/templates/nginx.conf.erb').read).result(binding)
    upload! StringIO.new(template), "/etc/nginx/conf.d/#{fetch(:domain)}.conf"
  end

  on roles(:app) do
    invoke 'nginx:restart'
  end
end

他のヒント

if i understand you correctly this should solve your problem by make the user variable:

set :current_user, Proc.new { current_user = Capistrano::CLI.ui.ask "Enter deploy user" }

if current_user.present?
   set :user, "#{current_user}"
end

what it will do it will ask you before run the command for user then assign this user to production.rb :user, then you will be able to control it on the setup.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top