public
Description: master respository for deprec - deployment recipes for capistrano
Homepage: http://www.deprec.org/
Clone URL: git://github.com/mbailey/deprec.git
Restricted tasks to roles.

I like restricting tasks to roles, partly out of laziness. I don't need
to specify HOSTS or ROLES on the command line as long as I've defined
the relevant roles somewhere. It also provides a safety net. Without
specifying HOSTS or ROLES on the command line, a task will get run on
*all* defined hosts. This can be avoided by restricting the tasks
themselves in deprec.

A problem with restricting tasks to roles in deprec was that Capistrano
complained when I ran a task in an ad-hoc manner without any hosts being
defined for the roles it was restricted to.

Sometimes I want to run a task on hosts but don't want to add them to
a deploy.rb. Editing a file just to use a command line is extra work!

e.g. cap deprec:mysql:install HOSTS=foo,bar

This problem caused me to remove a lot of role restrictions from deprec
over the last year or so.

My Capistrano patch (included in capistrano-2.5.0) causes Capistrano
to not complain about an undefined role if HOSTS or ROLES are specified
on the command line.

http://github.com/jamis/capistrano/commit/8badb0c522b38fae9cbe973451472afbddef61
cb

So, I'm putting the roles back in.

- Mike
mbailey (author)
Thu Sep 04 00:09:30 -0700 2008
commit  d103dda7ee3f7696007d230c76c7739dd57115ec
tree    a374e78d6debd6115c99d6f4f919363e4f170d8b
parent  4551d7db8b9fbc34f2fbf14e5fb7239adb69aefa
...
21
22
23
24
 
25
26
27
...
32
33
34
35
 
36
37
38
39
 
40
41
42
...
21
22
23
 
24
25
26
27
...
32
33
34
 
35
36
37
38
 
39
40
41
42
0
@@ -21,7 +21,7 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       # Install 
0
       
0
       desc "Install mongrel"
0
-      task :install do
0
+      task :install, :roles => :app do
0
         gem2.install 'mongrel'
0
         gem2.install 'mongrel_cluster'
0
         gem2.install 'swiftiply'
0
@@ -32,11 +32,11 @@ Capistrano::Configuration.instance(:must_exist).load do
0
         activate_system
0
       end
0
       
0
-      task :symlink_mongrel_rails do
0
+      task :symlink_mongrel_rails, :roles => :app do
0
         sudo "ln -sf /usr/local/bin/mongrel_rails /usr/bin/mongrel_rails"
0
       end
0
       
0
-      task :symlink_logrotate_config do
0
+      task :symlink_logrotate_config, :roles => :app do
0
         sudo "ln -sf #{deploy_to}/mongrel/logrotate.conf /etc/logrotate.d/mongrel-#{application}"
0
       end
0
     
...
6
7
8
9
 
10
11
12
13
14
15
 
16
17
18
...
6
7
8
 
9
10
11
12
13
14
 
15
16
17
18
0
@@ -6,13 +6,13 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       # Installation
0
       
0
       desc "Install mysql"
0
-      task :install do
0
+      task :install, :roles => :db do
0
         install_deps
0
         # symlink_mysql_sockfile # XXX still needed?
0
       end
0
       
0
       # Install dependencies for Mysql
0
-      task :install_deps do
0
+      task :install_deps, :roles => :db do
0
         apt.install( {:base => %w(mysql-server mysql-client)}, :stable )
0
       end
0
       
...
17
18
19
20
 
21
22
23
...
30
31
32
33
 
34
35
36
37
38
 
39
40
41
...
84
85
86
87
 
88
89
90
91
 
92
93
94
...
96
97
98
99
 
100
101
102
...
17
18
19
 
20
21
22
23
...
30
31
32
 
33
34
35
36
37
 
38
39
40
41
...
84
85
86
 
87
88
89
90
 
91
92
93
94
...
96
97
98
 
99
100
101
102
0
@@ -17,7 +17,7 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       }
0
 
0
       desc "Install nginx"
0
-      task :install do
0
+      task :install, :roles => :web do
0
         install_deps
0
         deprec2.download_src(SRC_PACKAGES[:nginx], src_dir)
0
         deprec2.install_from_src(SRC_PACKAGES[:nginx], src_dir)
0
@@ -30,12 +30,12 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       end
0
 
0
       # install dependencies for nginx
0
-      task :install_deps do
0
+      task :install_deps, :roles => :web do
0
         apt.install( {:base => %w(libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev)}, :stable )
0
         # do we need libgcrypt11-dev?
0
       end
0
 
0
-      task :create_nginx_user do
0
+      task :create_nginx_user, :roles => :web do
0
         deprec2.groupadd(nginx_group)
0
         deprec2.useradd(nginx_user, :group => nginx_group, :homedir => false)
0
       end
0
@@ -84,11 +84,11 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       Activate nginx start scripts on server.
0
       Setup server to start nginx on boot.
0
       DESC
0
-      task :activate do
0
+      task :activate, :roles => :web do
0
         activate_system
0
       end
0
 
0
-      task :activate_system do
0
+      task :activate_system, :roles => :web do
0
         send(run_method, "update-rc.d nginx defaults")
0
       end
0
 
0
@@ -96,7 +96,7 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       Dectivate nginx start scripts on server.
0
       Setup server to start nginx on boot.
0
       DESC
0
-      task :deactivate do
0
+      task :deactivate, :roles => :web do
0
         send(run_method, "update-rc.d -f nginx remove")
0
       end
0
 
...
90
91
92
93
 
94
95
96
...
122
123
124
125
 
126
127
128
129
130
131
132
 
133
134
135
136
 
137
138
139
140
141
 
142
143
144
...
160
161
162
163
 
164
165
166
...
285
286
287
288
289
 
...
90
91
92
 
93
94
95
96
...
122
123
124
 
125
126
127
128
129
130
131
 
132
133
134
135
 
136
137
138
139
140
 
141
142
143
144
...
160
161
162
 
163
164
165
166
...
285
286
287
 
288
289
0
@@ -90,7 +90,7 @@ Capistrano::Configuration.instance(:must_exist).load do
0
         install_stack
0
       end
0
       
0
-      task :install_gems_for_project do
0
+      task :install_gems_for_project, :roles => :app do
0
           if gems_for_project
0
             gems_for_project.each { |gem| gem2.install(gem) }
0
           end
0
@@ -122,23 +122,23 @@ Capistrano::Configuration.instance(:must_exist).load do
0
         deprec2.push_configs(:nginx, PROJECT_CONFIG_FILES[:nginx])
0
         top.deprec.mongrel.config_project
0
         symlink_nginx_vhost
0
-        symlink_logrotate_config
0
+        symlink_nginx_logrotate_config
0
       end
0
 
0
       task :symlink_nginx_vhost, :roles => :web do
0
         sudo "ln -sf #{deploy_to}/nginx/rails_nginx_vhost.conf #{nginx_vhost_dir}/#{application}.conf"
0
       end
0
       
0
-      task :symlink_logrotate_config, :roles => :web do
0
+      task :symlink_nginx_logrotate_config, :roles => :web do
0
         sudo "ln -sf #{deploy_to}/nginx/logrotate.conf /etc/logrotate.d/nginx-#{application}"
0
       end
0
 
0
-      task :create_config_dir do
0
+      task :create_config_dir, :roles => :app do
0
         deprec2.mkdir("#{shared_path}/config", :group => group, :mode => 0775, :via => :sudo)
0
       end
0
       
0
       desc "Create deployment group and add current user to it"
0
-      task :setup_user_perms do
0
+      task :setup_user_perms, :roles => [:app, :web] do
0
         deprec2.groupadd(group)
0
         deprec2.add_user_to_group(user, group)
0
         deprec2.groupadd(mongrel_group)
0
@@ -160,7 +160,7 @@ Capistrano::Configuration.instance(:must_exist).load do
0
       end
0
 
0
       # setup extra paths required for deployment
0
-      task :setup_paths, :roles => :app do
0
+      task :setup_paths, :roles => [:app, :web] do
0
         deprec2.mkdir(deploy_to, :mode => 0775, :group => group, :via => :sudo)
0
         deprec2.mkdir(shared_path, :mode => 0775, :group => group, :via => :sudo)
0
       end
0
@@ -285,4 +285,4 @@ Capistrano::Configuration.instance(:must_exist).load do
0
 
0
   end
0
   
0
-end
0
\ No newline at end of file
0
+end

Comments