简体   繁体   中英

Rails Capistrano and Foreman

I am currently setting up a production environment and have had some issue getting foreman playing nice with capistrano.

All examples of having foreman export its tasks to upstart have required the use of root privileges and currently I am not using a root or sudo to execute my deploy.

Issue is it seems foreman requires root privileges to export. THe user that is deploying has root privileges however I do not want to run anything but the foreman related commands with sudo. Is there a way to set something like

    set :use_sudo, true

but only for foreman related tasks?

or is there a way to get foreman to export to upstart without the use of sudo?

If it helps to know the box is running Ubuntu 12.04 with foreman accessible on the server

EDIT

The configs for my Deploy.rb

    require "bundler/capistrano"
    require "rvm/capistrano"

    set :rvm_ruby_string, :local               # use the same ruby as used 
    set :rvm_autolibs_flag, "read-only"        # more info: rvm help autolibs
    before 'deploy', 'rvm:install_rvm'   # install RVM

    server "ip_to_server", :web, :app, :db, primary: true

    set :application, "app_name"
    set :user, "deploy_user"
    set :deploy_to, "/home/#{user}/apps/#{application}"
    set :deploy_via, :remote_cache
    set :use_sudo, false

    set :scm, "git"
    set :repository, "repo_path"
    set :branch, "production"

    default_run_options[:pty] = true
    ssh_options[:forward_agent] = true

My foreman namespace looks like this

    namespace :foreman do

      desc 'Export the Procfile to Ubuntu upstart scripts'
      task :export, :roles => :app do
      run "cd #{release_path} && sudo bundle exec foreman export upstart                
      /etc/init -a #{application} -u #{user} -l #{release_path}/log/foreman -f 
      #{current_path}/Procfile"
      end

      desc "Start the application services"
      task :start, :roles => :app do
        sudo "start #{application}"
      end

        desc "Stop the application services"
        task :stop, :roles => :app do
          sudo "stop #{application}"
        end

        desc "Restart the application services"
        task :restart, :roles => :app do
          run "sudo start #{application} || sudo restart #{application}"
       end
      end

The command to export fires off and leaves me with this

executing command ** [out :: server_ip] [sudo] password for deploy

wih no way to input

Disable the use_sudo and add the sudo with the command.

For example:

set :use_sudo, false 

task :foreman do
  run "sudo foreman export upstart /etc/init -f Procfile"
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM