I’m a newbie with capistrano, and have been banging my head against this problem for a couple of days so would really appreciate some help.
We have an annoying security setup, which means that i cannot run capistrano tasks on the remote server as the ssh user. It’s a simpler version of This problem – which doesn’t seem to have a working answer.
Edit:
Delving further into this, I find that i can do something like:
run "su - newuser" do |channel, stream, data|
channel.send_data("#{password}\n")
channel.send_data("rm -rf #{release_path}\n")
end }
I can use this to overwrite the default deploy methods, and do most of what I need to do. I can create the required directories on the server and so on, and pull from git as the ssh user using ssh forwarding. Which creates my next problem. I now have directories owned by newuser which contain files and directories owned by ssh_user. I do have sudo privileges as newuser, but can’t work out how to chmod the files. I’ve tried stuff like:
run "su - newuser" do |channel, stream, data
channel.send_data("#{password}\n")
channel.send_data("sudo chmod 775 #{cache_path}\n")
end }
but everything just hangs, and it seems as if the block is executed in an infinite loop. Obviously there is a lot i don’t understand here and some pointers would be much appreciated – even if just to a good relevant read.
https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Invocation-Run
shows you the :shell option for run which you can set to:
if you use predefined tasks, you better redefine run and su to merge the shell option.
this assumes your ssh user can su without password. if not use a block to send the password: