Questions for Capistrano

Questions for Capistrano

www.YoYoBrain.com - Accelerators for Memory and Learning Questions for Capistrano Category: Basics - (21 questions) Command for installing capistrano when gem install capistrano RubyGems package management is installed Capistrano's expectations about your servers that must be met to use Capistrano accessed via SSH have a POSIX-compatible shell installed called "sh" that resides in the default system path. If using passwords to access your servers, all must have the same password. (Because this is not generally a good idea, the preferred way of accessing your servers is with a public key. Make sure you've got a good passphrase on your key.) Does Capistrano support telnet and ftp no Capistrano prerequites skills Comfort with command line enough to navigate directories and excute commands Familiar/comfortable with Ruby Files that provide Capistrano with its capfile - similar to makefile or rakefile instructions concept Where do you tell Capistrano about the capfile servers you want to connect to and what tasks you want to perform on your servers What is a capfile in terms of programming It is a custom Domain Specific Language on instructions/language top of Ruby put more simply, its a Ruby script augmented with helper syntax that makes it easy to define server roles and tasks. Editor that must be used to write capfiles any capfile file extension none. just capfile What's happening in this example? defines a single task, called "search_libs", that task runs the linux shell command in task :search_libs, :hosts => "www.capify.org" quotes do run "ls -x1 /usr/lib | grep -i xml"end says that it should be executed only on the "www.capify.org" host. When executed, it will display all files and subdirectories in /usr/lib that include the text "xml" in their name. Where does "run" display all output by the console default how do you specify that a task should run on pass an array of role names to the :roles servers in multiple roles option What is the lmit to the number of tasks you none can define in a capfile Purpose of "roles" allows you to drop the :hosts=> option in your tasks and define groups of servers to run tasks on By default, what roles are tasks run on all servers/all roles defined with role Capistrano's default log in is Whatever user you are as currently logged in to your local machine How do you tell capistrano about a gateway server you may be using to get behind a set :gateway, "www.capify.org"role :libs, firewall "crimson.capify.org" Syntax for adding multiple servers to a role role :libs, "crimson.capify.org", "magenta.capify.org" What happens with tasks when run on a role command will be executed in parallel on both with multiple servers servers, with the output aggregated into a single stream and displayed on your console. How do you specifiy the server roles on add :roles constraints to each task, which a task should run specifying which role each is associated with. task :count_libs, :roles => :libs do run "ls -x1 /usr/lib | wc -l"end Preferred way of accessing your with a public key with a good good servers...and why passphrase ...otherwise all servers need the same username and password installed Category: Syntax - (63 questions) Do transactions track and revert your no, you have to register on_rollback handlers changes? appropriately, that take the necessary steps to undo the changes that the task has made. What is going on this code block in terms of the transaction first task, "deploy" wraps a transaction around its invocations of "update_code" and task :deploy do transaction do "symlink". update_code symlink endendtask If error happens within that transaction, the :update_code do on_rollback { run "rm -rf "on_rollback" handlers that have been #{release_path}" } declared are all executed, in reverse order. source.checkout(release_path)endtask :symlink do on_rollback { run "rm #{current_path}; ln -s #{previous_release} #{current_path}" } run "rm #{current_path}; ln -s #{release_path} #{current_path}"end purpose of on_rollback handlers run if a transaction fails command to load files load "files" how do you add a directory to capistrano's load path load_paths << "config/stages" how do you specify files load from the -f switch command line cap -f libs libs:search purpose of -F switch loads default capfile syntax to execute a task defined in a capfile cap search_libs (assuming you are in the directory where the capfile is located) command to get a list of tasks cap -T syntax for adding a description that show in cap -t desc "Search /usr/lib for files named xml." which tasks are shown in cap -t those with "desc" defined desc "Search /usr/lib for files named xml."task :search_libs, :roles => :libs do run "ls -x1 /usr/lib | grep -i xml"end syntax to declare a role role :libs, "www.capify.org" What part of desc is shown by cap -T description shown is all text up to the first "." character (or up to the first 30 characters, whichever comes first Command to show all of description cap -t -e (its the -e switch "explain") and pass the name of the tasks you want to describe 2 ways How do you log in as a different user encode that username in the server definition, "[email protected]".Alternatively, you can set the :user variable to the username you want to use. How do you define multiple server roles role :libs, "crimson.capify.org", "magenta.capify.org"role :files, "fuchsia.capify.org" What is the purpose of the invoke task lets you execute a single command on your remote servers, without having to write a task for it syntax for invoke specify the command you want to invoke via the COMMAND variable: cap invoke COMMAND="df -h" What does the following command do execute "df -h" on all defined servers, in all roles. cap invoke COMMAND="df -h" How do you restrict a command called from specifying the role names as a invoke to a certain set of roles comma-delimited list, using the ROLES variable: cap invoke COMMAND="df -h" ROLES=libs how do you execute commands via invoke using the HOSTS variable on servers that have not been previously defined cap invoke COMMAND="df -h" HOSTS=mauve.capify.org command to get full documentation for the cap -e invoke invoke task Main draw back of the invoke command every time you invoke a command, it has to reestablish connections to the servers purpose and benefit of cap shell interactive prompt from which you can enter adhoc commands execute tasks.... all connections that are established during the duration of the shell session are cached and reused How do you get help from within cap shell type "help" Purpose of a namespace allows you to group a set of tasks (or even other namespaces) and give them a name. Syntax for creating a namespace namespace :libs do task :search, :roles => :libs do run "ls -x1 /usr/lib | grep -i xml" end task :count, :roles => :libs do run "ls -x1 /usr/lib | wc -l" endendnamespace :disk do task :free, :roles => :files do run "df -h /" endend syntax to peform the search task defined cap libs:search below namespace :libs do task :search, :roles => :libs do run "ls -x1 /usr/lib | grep -i xml" end task :count, :roles => :libs do run "ls -x1 /usr/lib | wc -l" endend Can you have tasks with the same name in yes different namespaces? What happens with a task in a namespace it is run if you type cap name space named :default so cap libs runs the default task below namespace :libs do task :default, :roles => :libs do run "ls -x1 /usr/lib | grep -i xml" end task :count, :roles => :libs do run "ls -x1 /usr/lib | wc -l" endend how do you add variables into your tasks - #{} syntax: for example to search task :search, :roles => :libs do run "ls -x1 /usr/lib | grep -i #{term}"end How would the user set the term variable below set :term, "xml" task :search, :roles => :libs do run "ls -x1 /usr/lib | grep -i #{term}"end The helper below Capistrano::CLI.ui.ask "Gimme a search code to send a prompt to the user and grab term: " replaces what block of code he responseset(:term) do print "Gimme a search term: " STDOUT.flush STDIN.gets.chompend Syntax to introduce a transaction task :deploy do transaction do update_code symlink endendtask :update_code do on_rollback { run "rm -rf #{release_path}" } source.checkout(release_path)endtask :symlink do on_rollback { run "rm #{current_path}; ln -s #{previous_release} #{current_path}" } run "rm #{current_path}; ln -s #{release_path} #{current_path}"end helper that prompts the user to enter a variable Capistrano::CLI.ui.ask Variables that you get with ".ask" are cached Cached . user is prompted for first, answer is or prompted each time? cached fr subsequent requests purpose of :default_environment for specifying environment variables that should be set for every command purpose of :ssh_options variable for setting things like agent forwarding and specifying an alternative port number, purpose of :logger variable holds a reference to the logger instance being used by Capistrano. purpose of -s switch used to set variables from the command-line, "-s" (lower-case) switch will set the variable after all recipe files have been loaded purpose of -S switch set variables from the command-line before any recipe files hae been loaded purpose of -S switch set variables from the command-line before any recipe files hae been loaded when is it useful to set a variable after all if you need to override variables that have recipe files have loaded been set by the recipe files themselves When is it useful to set variables before a if the recipes themselves depend on a recipe file has loaded variable being set while they are loading (for instance, if they are doing conditional creation of tasks and so forth).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us