Ticket #84: sample-capfile

File sample-capfile, 3.8 kB (added by lburgess, 5 months ago)

capfile with custom recipes for "java" role

Line 
1load 'deploy'
2
3# ================================================================
4# ROLES
5# ================================================================
6
7
8    role :java, "vm11.internallab.com"
9 
10
11# ================================================================
12# VARIABLES
13# ================================================================
14
15# Webistrano defaults
16  set :webistrano_project, "myjavaapp"
17  set :webistrano_stage, "myjavaapp_prod"
18
19
20  set :application, "myjavaapp"
21
22  set :deploy_to, "/path/to/deployment_base"
23
24  set :deploy_via, :checkout
25
26  set :repository, "https://svn.example.com/project/trunk"
27
28  set :runner, "root"
29
30  set :scm, "subversion"
31
32  set :scm_password, "your_SVN_password"
33
34  set :scm_username, "your_SVN_user"
35
36  set :use_sudo, false
37
38  set :user, "root"
39
40
41
42  set(:password) do
43    Capistrano::CLI.ui.ask "Please enter 'password': "
44  end
45
46  set(:version) do
47    Capistrano::CLI.ui.ask "Please enter 'version': "
48  end
49
50
51# ================================================================
52# TEMPLATE TASKS
53# ================================================================
54
55        # allocate a pty by default as some systems have problems without
56        default_run_options[:pty] = true
57     
58        # set Net::SSH ssh options through normal variables
59        # at the moment only one SSH key is supported as arrays are not
60        # parsed correctly by Webistrano::Deployer.type_cast (they end up as strings)
61        [:ssh_port, :ssh_keys].each do |ssh_opt|
62          if exists? ssh_opt
63            logger.important("SSH options: setting #{ssh_opt} to: #{fetch(ssh_opt)}")
64            ssh_options[ssh_opt.to_s.gsub(/ssh_/, '').to_sym] = fetch(ssh_opt)
65          end
66        end
67     
68         namespace :deploy do
69           task :restart, :roles => :app, :except => { :no_release => true } do
70             # do nothing
71           end
72
73           task :start, :roles => :app, :except => { :no_release => true } do
74             # do nothing
75           end
76
77           task :stop, :roles => :app, :except => { :no_release => true } do
78             # do nothing
79           end
80         end
81
82
83# ================================================================
84# CUSTOM RECIPES
85# ================================================================
86
87require 'rubygems'
88
89namespace :deploy do
90 
91  WEBAPP_HOME = '/usr/local/java-apps/webapps/'
92  TOMCAT_HOME = '/usr/local/tomcat5/webapps/'
93  BASE_URL = 'http://repo.internallab.com/repository/'
94  DEPLOY_URL = 'http://localhost:8080/manager/deploy'
95  RELOAD_URL = 'http://localhost:8080/manager/reload'
96  USER = <user>
97  PASS = <password>
98 
99  task :update, :roles => [:java] do
100    @full_url = BASE_URL + group + '/' + application + '/' + version +
101      '/' + application + '-' + version + '.war'
102    @app_fullname = application + '-' + version
103    invoke_command "rm -rf #{WEBAPP_HOME}#{@app_fullname}.war; cd #{WEBAPP_HOME}; wget #{@full_url}", :via => run_method
104    invoke_command "chown tomcat:root -R #{WEBAPP_HOME}", :via => run_method
105    invoke_command "curl --user #{USER}:#{PASS} \"#{DEPLOY_URL}?path=/#{application}&war=#{WEBAPP_HOME}#{@app_fullname}.war&update=true\"",
106      :via => run_method
107    # To avoid duplicate restart
108    @restarted = true
109    # Run the rsync command manually since we don't have a dependency on deploy:update
110    invoke_command '/usr/local/bin/ruby /root/rsync-helper', :via => run_method
111  end
112 
113  task :symlink, :roles => [:java] do
114    # NOP
115  end
116 
117  task :restart, :roles => [:java] do
118    if not @restarted
119      invoke_command "curl --user #{USER}:#{PASS} \"#{RELOAD_URL}?path=/#{application}\"", :via => run_method
120    end
121  end
122
123  task :update_code, :roles => [:java] do
124    # NOP
125  end
126end
127
128
129