开发者

How to copy a file to a bunch of servers with capistrano

开发者 https://www.devze.com 2023-03-12 10:56 出处:网络
I use cap invok开发者_开发问答e a lot to run commands on a bunch of servers.I would like to also use capistrano to push a single file to a bunch of servers.

I use cap invok开发者_开发问答e a lot to run commands on a bunch of servers. I would like to also use capistrano to push a single file to a bunch of servers.

At first I thought that PUT would do it, but put makes you create the data for the file. I don't want to do this, I just want to copy an existing file from the machine where I'm running the capistrano comand to the other machines.

It would be cool if I could do something like this:

host1$ cap HOSTS=f1.foo.com,f2.foo.com,f3.foo.com COPY /tmp/bar.bin 

I would expect this to copy host1:/tmp/bar.bin to f1.foo.com:/tmp/bar.bin and f2.foo.com:/tmp/bar.bin and f3.foo.com:/tmp/bar.bin

This kind of thing seems very useful so I'm sure there must be a way to do this...


upload(from, to, options={}, &block)

The upload action stores the file at the given path on all servers targeted by the current task.

If you ever used the deploy:upload task before, then you might already know how this method works. It takes the path of the resource you want to upload and the target path on the remote servers.

desc "Uploads CHANGELOG.txt to all remote servers."
task :upload_changelog do
  upload("#{RAILS_ROOT}/CHANGELOG.txt", "#{current_path}/public/CHANGELOG")
end

source


This uploads all files to the respective servers.

cap deploy:upload FILES=abc,def


Show all tasks:

cap -T
cap deploy                # Deploys your project.
cap deploy:check          # Test deployment dependencies.
cap deploy:cleanup        # Clean up old releases.
cap deploy:cold           # Deploys and starts a `cold'...
cap deploy:create_symlink # Updates the symlink to the ...
cap deploy:migrations     # Deploy and run pending migr...
cap deploy:pending        # Displays the commits since ...
cap deploy:pending:diff   # Displays the `diff' since y...
cap deploy:rollback       # Rolls back to a previous ve...
cap deploy:rollback:code  # Rolls back to the previousl...
cap deploy:setup          # Prepares one or more server...
cap deploy:symlink        # Deprecated API.
cap deploy:update         # Copies your project and upd...
cap deploy:update_code    # Copies your project to the ...
cap deploy:upload         # Copy files to the currently...
cap deploy:web:disable    # Present a maintenance page ...
cap deploy:web:enable     # Makes the application web-a...
cap integration           # Set the target stage to `in...
cap invoke                # Invoke a single command on ...
cap multistage:prepare    # Stub out the staging config...
cap production            # Set the target stage to `pr...
cap shell                 # Begin an interactive Capist...

You could use:

cap deploy:upload

See: https://github.com/capistrano/capistrano/wiki/Capistrano-Tasks#deployupload


Anyone coming here who doesn't have cap deploy:upload can try using cap invoke to pull the file instead of pushing it. For example:

cap invoke COMMAND='scp host.where.file.is:/path/to/file/there /target/path/on/remote`
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号