Capistrano 3 sudo task

前端 未结 5 1675
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 15:48

I want to write a recipe with Capistrano 3 executing a task on the remote server with sudo.

With Capistrano 2 this could be done for example:

default_run         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 15:57

    To resolve this issue I needed to add set :pty, true to my deploy.rb file.

    I can now run the following:

    # config valid only for Capistrano 3.1
    lock '3.1.0'
    
    set :application, 'APP_NAME'
    set :pty, true
    set :ssh_options, {:forward_agent => true}
    
    namespace :deploy do
    
      desc 'Restart NGINX'
      task :restart do
        on roles(:app), in: :sequence, wait: 1 do
           execute :sudo, "./restart.sh"
        end
      end
    
    end
    

    This task basically runs a shell script called restart.sh that has a command within sudo service nginx restart.

提交回复
热议问题