deploify 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +36 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +2 -0
  6. data/Rakefile +1 -0
  7. data/deploify.gemspec +29 -0
  8. data/lib/deploify/capistrano_extensions.rb +189 -0
  9. data/lib/deploify/recipes/deploify.rb +171 -0
  10. data/lib/deploify/recipes/mongodb.rb +15 -0
  11. data/lib/deploify/recipes/monit.rb +84 -0
  12. data/lib/deploify/recipes/mysql.rb +85 -0
  13. data/lib/deploify/recipes/nginx.rb +122 -0
  14. data/lib/deploify/recipes/passenger.rb +130 -0
  15. data/lib/deploify/recipes/puma.rb +15 -0
  16. data/lib/deploify/recipes/rails.rb +221 -0
  17. data/lib/deploify/recipes/thin.rb +104 -0
  18. data/lib/deploify/recipes.rb +13 -0
  19. data/lib/deploify/templates/monit/monit.conf.erb +5 -0
  20. data/lib/deploify/templates/nginx/logrotate.conf.erb +12 -0
  21. data/lib/deploify/templates/nginx/vhost_http_force_ssl.conf.erb +79 -0
  22. data/lib/deploify/templates/nginx/vhost_http_only.conf.erb +66 -0
  23. data/lib/deploify/templates/nginx/vhost_http_with_ssl.conf.erb +131 -0
  24. data/lib/deploify/templates/passenger/logrotate.conf.erb +12 -0
  25. data/lib/deploify/templates/passenger/passengerctl-lib.erb +68 -0
  26. data/lib/deploify/templates/passenger/passengerctl.erb +10 -0
  27. data/lib/deploify/templates/thin/logrotate.conf.erb +0 -0
  28. data/lib/deploify/templates/thin/thinctl-lib.erb +84 -0
  29. data/lib/deploify/templates/thin/thinctl.erb +9 -0
  30. data/lib/deploify/version.rb +12 -0
  31. data/lib/deploify.rb +7 -0
  32. data/lib/plugins/all.rb +20 -0
  33. data/lib/plugins/apt.rb +94 -0
  34. data/lib/plugins/std.rb +203 -0
  35. metadata +196 -0
@@ -0,0 +1,79 @@
1
+ upstream <%= nginx_upstream_name %> {
2
+ <% nginx_upstream_servers.each do |srv| -%>
3
+ server <%= srv %>;
4
+ <% end -%>
5
+ }
6
+
7
+ server {
8
+ listen <%= nginx_vhost_listen_ip %>:80;
9
+ server_name <%= domain %> <%= Array(web_server_aliases).join(' ') %>;
10
+
11
+ location / {
12
+ rewrite ^ https://<%= domain %>$request_uri? permanent;
13
+ }
14
+ }
15
+
16
+ server {
17
+ listen <%= nginx_vhost_listen_ip %>:443;
18
+ server_name <%= domain %> <%= Array(web_server_aliases).join(' ') %>;
19
+ root <%= deploy_to %>/current/public;
20
+ client_max_body_size <%= nginx_client_max_body_size %>;
21
+ access_log <%= shared_path %>/log/access.log;
22
+ error_log <%= shared_path %>/log/error.log;
23
+
24
+ ssl on;
25
+ ssl_certificate <%= deploy_to %>/nginx/<%= rails_env %>.crt;
26
+ ssl_certificate_key <%= deploy_to %>/nginx/<%= rails_env %>.key;
27
+
28
+ <% if force_domain_with_www -%>
29
+ if ($host !~* ^www.<%= domain %>$) {
30
+ rewrite ^(.*) https://www.<%= domain %>$1 permanent;
31
+ }
32
+ <% end -%>
33
+
34
+ location / {
35
+ <% if nginx_secured_site -%>
36
+ auth_basic "Limited access";
37
+ auth_basic_user_file <%= "#{deploy_to}/nginx/.htaccess" %>;
38
+ <% end -%>
39
+ proxy_pass http://<%= nginx_upstream_name %>;
40
+ proxy_redirect off;
41
+ proxy_set_header Host $host;
42
+ proxy_set_header X-Real-IP $remote_addr;
43
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
44
+ proxy_set_header X-Forwarded-Proto https;
45
+ }
46
+
47
+ # This allows people to use images and css in their maintenance.html file
48
+ if ($request_filename ~* \.(css|jpg|gif|png)$) {
49
+ break;
50
+ }
51
+
52
+ # Rewrite all the requests to the maintenance.html page if it exists.
53
+ if (-f $document_root/system/maintenance.html) {
54
+ return 503;
55
+ }
56
+
57
+ # set Expire header on assets: see http://developer.yahoo.com/performance/rules.html#expires
58
+ location ~ ^/(images|javascripts|stylesheets)/ {
59
+ expires max;
60
+ error_page 404 = @fallback;
61
+ }
62
+
63
+ location @fallback {
64
+ proxy_pass http://<%= nginx_upstream_name %>;
65
+ proxy_redirect off;
66
+ proxy_set_header Host $host;
67
+ proxy_set_header X-Real-IP $remote_addr;
68
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
69
+ proxy_set_header X-Forwarded-Proto https;
70
+ }
71
+
72
+ error_page 404 /404.html;
73
+ error_page 500 502 504 /500.html;
74
+
75
+ error_page 503 @503;
76
+ location @503 {
77
+ rewrite ^(.*)$ /system/maintenance.html break;
78
+ }
79
+ }
@@ -0,0 +1,66 @@
1
+ upstream <%= nginx_upstream_name %> {
2
+ <% nginx_upstream_servers.each do |srv| -%>
3
+ server <%= srv %>;
4
+ <% end -%>
5
+ }
6
+
7
+ server {
8
+ listen <%= nginx_vhost_listen_ip %>:80;
9
+ server_name <%= domain %> <%= Array(web_server_aliases).join(' ') %>;
10
+ root <%= deploy_to %>/current/public;
11
+ client_max_body_size <%= nginx_client_max_body_size %>;
12
+ access_log <%= shared_path %>/log/access.log;
13
+ error_log <%= shared_path %>/log/error.log;
14
+
15
+ <% if force_domain_with_www -%>
16
+ if ($host !~* ^www.<%= domain %>$) {
17
+ rewrite ^(.*) http://www.<%= domain %>$1 permanent;
18
+ }
19
+ <% end -%>
20
+
21
+ location / {
22
+ <% if nginx_secured_site -%>
23
+ auth_basic "Limited access";
24
+ auth_basic_user_file <%= "#{deploy_to}/nginx/.htaccess" %>;
25
+ <% end -%>
26
+ proxy_pass http://<%= nginx_upstream_name %>;
27
+ proxy_redirect off;
28
+ proxy_set_header Host $host;
29
+ proxy_set_header X-Real-IP $remote_addr;
30
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31
+ proxy_set_header X-Forwarded-Proto http;
32
+ }
33
+
34
+ # This allows people to use images and css in their maintenance.html file
35
+ if ($request_filename ~* \.(css|jpg|gif|png)$) {
36
+ break;
37
+ }
38
+
39
+ # Rewrite all the requests to the maintenance.html page if it exists.
40
+ if (-f $document_root/system/maintenance.html) {
41
+ return 503;
42
+ }
43
+
44
+ # set Expire header on assets: see http://developer.yahoo.com/performance/rules.html#expires
45
+ location ~ ^/(images|javascripts|stylesheets)/ {
46
+ expires max;
47
+ error_page 404 = @fallback;
48
+ }
49
+
50
+ location @fallback {
51
+ proxy_pass http://<%= nginx_upstream_name %>;
52
+ proxy_redirect off;
53
+ proxy_set_header Host $host;
54
+ proxy_set_header X-Real-IP $remote_addr;
55
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
56
+ proxy_set_header X-Forwarded-Proto http;
57
+ }
58
+
59
+ error_page 404 /404.html;
60
+ error_page 500 502 504 /500.html;
61
+
62
+ error_page 503 @503;
63
+ location @503 {
64
+ rewrite ^(.*)$ /system/maintenance.html break;
65
+ }
66
+ }
@@ -0,0 +1,131 @@
1
+ upstream <%= nginx_upstream_name %> {
2
+ <% nginx_upstream_servers.each do |srv| -%>
3
+ server <%= srv %>;
4
+ <% end -%>
5
+ }
6
+
7
+ server {
8
+ listen <%= nginx_vhost_listen_ip %>:80;
9
+ server_name <%= domain %> <%= Array(web_server_aliases).join(' ') %>;
10
+ root <%= deploy_to %>/current/public;
11
+ client_max_body_size <%= nginx_client_max_body_size %>;
12
+ access_log <%= shared_path %>/log/access.log;
13
+ error_log <%= shared_path %>/log/error.log;
14
+
15
+ <% if force_domain_with_www -%>
16
+ if ($host !~* ^www.<%= domain %>$) {
17
+ rewrite ^(.*) http://www.<%= domain %>$1 permanent;
18
+ }
19
+ <% end -%>
20
+
21
+ location / {
22
+ <% if nginx_secured_site -%>
23
+ auth_basic "Limited access";
24
+ auth_basic_user_file <%= "#{deploy_to}/nginx/.htaccess" %>;
25
+ <% end -%>
26
+ proxy_pass http://<%= nginx_upstream_name %>;
27
+ proxy_redirect off;
28
+ proxy_set_header Host $host;
29
+ proxy_set_header X-Real-IP $remote_addr;
30
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31
+ proxy_set_header X-Forwarded-Proto http;
32
+ }
33
+
34
+ # This allows people to use images and css in their maintenance.html file
35
+ if ($request_filename ~* \.(css|jpg|gif|png)$) {
36
+ break;
37
+ }
38
+
39
+ # Rewrite all the requests to the maintenance.html page if it exists.
40
+ if (-f $document_root/system/maintenance.html) {
41
+ return 503;
42
+ }
43
+
44
+ # set Expire header on assets: see http://developer.yahoo.com/performance/rules.html#expires
45
+ location ~ ^/(images|javascripts|stylesheets)/ {
46
+ expires max;
47
+ error_page 404 = @fallback;
48
+ }
49
+
50
+ location @fallback {
51
+ proxy_pass http://<%= nginx_upstream_name %>;
52
+ proxy_redirect off;
53
+ proxy_set_header Host $host;
54
+ proxy_set_header X-Real-IP $remote_addr;
55
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
56
+ proxy_set_header X-Forwarded-Proto http;
57
+ }
58
+
59
+ error_page 404 /404.html;
60
+ error_page 500 502 504 /500.html;
61
+
62
+ error_page 503 @503;
63
+ location @503 {
64
+ rewrite ^(.*)$ /system/maintenance.html break;
65
+ }
66
+ }
67
+
68
+ server {
69
+ listen <%= nginx_vhost_listen_ip %>:443;
70
+ server_name <%= domain %> <%= Array(web_server_aliases).join(' ') %>;
71
+ root <%= deploy_to %>/current/public;
72
+ client_max_body_size <%= nginx_client_max_body_size %>;
73
+ access_log <%= shared_path %>/log/access.log;
74
+ error_log <%= shared_path %>/log/error.log;
75
+
76
+ ssl on;
77
+ ssl_certificate <%= deploy_to %>/nginx/<%= rails_env %>.crt;
78
+ ssl_certificate_key <%= deploy_to %>/nginx/<%= rails_env %>.key;
79
+
80
+ <% if force_domain_with_www -%>
81
+ if ($host !~* ^www.<%= domain %>$) {
82
+ rewrite ^(.*) https://www.<%= domain %>$1 permanent;
83
+ }
84
+ <% end -%>
85
+
86
+ location / {
87
+ <% if nginx_secured_site -%>
88
+ auth_basic "Limited access";
89
+ auth_basic_user_file <%= "#{deploy_to}/nginx/.htaccess" %>;
90
+ <% end -%>
91
+ proxy_pass http://<%= nginx_upstream_name %>;
92
+ proxy_redirect off;
93
+ proxy_set_header Host $host;
94
+ proxy_set_header X-Real-IP $remote_addr;
95
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
96
+ proxy_set_header X-Forwarded-Proto https;
97
+ }
98
+
99
+ # This allows people to use images and css in their maintenance.html file
100
+ if ($request_filename ~* \.(css|jpg|gif|png)$) {
101
+ break;
102
+ }
103
+
104
+ # Rewrite all the requests to the maintenance.html page if it exists.
105
+ if (-f $document_root/system/maintenance.html) {
106
+ return 503;
107
+ }
108
+
109
+ # set Expire header on assets: see http://developer.yahoo.com/performance/rules.html#expires
110
+ location ~ ^/(images|javascripts|stylesheets)/ {
111
+ expires max;
112
+ error_page 404 = @fallback;
113
+ }
114
+
115
+ location @fallback {
116
+ proxy_pass http://<%= nginx_upstream_name %>;
117
+ proxy_redirect off;
118
+ proxy_set_header Host $host;
119
+ proxy_set_header X-Real-IP $remote_addr;
120
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
121
+ proxy_set_header X-Forwarded-Proto https;
122
+ }
123
+
124
+ error_page 404 /404.html;
125
+ error_page 500 502 504 /500.html;
126
+
127
+ error_page 503 @503;
128
+ location @503 {
129
+ rewrite ^(.*)$ /system/maintenance.html break;
130
+ }
131
+ }
@@ -0,0 +1,12 @@
1
+ <%= shared_path %>/log/<%= rails_env %>.log, <%= shared_path %>/log/passenger.log {
2
+ daily
3
+ missingok
4
+ rotate 30
5
+ compress
6
+ delaycompress
7
+ sharedscripts
8
+ dateext
9
+ postrotate
10
+ touch <%= deploy_to %>/current/tmp/restart.txt
11
+ endscript
12
+ }
@@ -0,0 +1,68 @@
1
+ USER=app_${APPLICATION}
2
+ APP_DIR=/var/www/${APPLICATION}/current
3
+ PIDFILE=${APP_DIR}/tmp/pids/passenger.pid
4
+ LOGFILE=${APP_DIR}/log/passenger.log
5
+
6
+ if [ "$APP_PORT" = "" ]; then
7
+ CMD_START="cd $APP_DIR; rvm use $RVM_RUBY; passenger start $APP_DIR --socket ${APP_DIR}/tmp/pids/passenger.sock -e $ENVIRONMENT --min-instances=$INSTANCES_MIN --max-pool-size=$INSTANCES_MAX --pid-file $PIDFILE --log-file $LOGFILE -d"
8
+ CMD_STOP="cd $APP_DIR; rvm use $RVM_RUBY; passenger stop $APP_DIR --pid-file $PIDFILE"
9
+ else
10
+ CMD_START="cd $APP_DIR; rvm use $RVM_RUBY; passenger start $APP_DIR --port $APP_PORT -e $ENVIRONMENT --min-instances=$INSTANCES_MIN --max-pool-size=$INSTANCES_MAX --pid-file $PIDFILE --log-file $LOGFILE -d"
11
+ CMD_STOP="cd $APP_DIR; rvm use $RVM_RUBY; passenger stop $APP_DIR --pid-file $PIDFILE"
12
+ fi
13
+
14
+ function start() {
15
+ echo "Starting passenger for application '${APPLICATION}'"
16
+ if [ -f ${PIDFILE} ]; then
17
+ kill -0 `cat ${PIDFILE}`
18
+ if [ "$?" == "1" ]; then
19
+ rm ${APP_DIR}/tmp/pids/passenger.*
20
+ else
21
+ echo "Passenger already running with PID "`cat ${PIDFILE}`
22
+ return 1
23
+ fi
24
+ fi
25
+ su - $USER -c "$CMD_START"
26
+ }
27
+
28
+ function stop() {
29
+ echo "Stopping passenger for application '${APPLICATION}'"
30
+ su - $USER -c "$CMD_STOP"
31
+ }
32
+
33
+ function graceful() {
34
+ echo "Graceful (if possible) restart for application '${APPLICATION}'"
35
+ if [ -f ${PIDFILE} ]; then
36
+ kill -0 `cat ${PIDFILE}`
37
+ if [ "$?" == "0" ]; then
38
+ echo "Graceful restart for application '${APPLICATION}'"
39
+ touch ${APP_DIR}/tmp/restart.txt
40
+ return 0
41
+ else
42
+ echo "Oops! Pid File exists, but not workers. Restarting."
43
+ start
44
+ fi
45
+ else
46
+ start
47
+ fi
48
+ }
49
+
50
+ case "$1" in
51
+ "start")
52
+ start
53
+ ;;
54
+ "stop")
55
+ stop
56
+ ;;
57
+ "restart")
58
+ stop
59
+ start
60
+ ;;
61
+ "graceful")
62
+ graceful
63
+ ;;
64
+ *)
65
+ echo "Usage: $0 start|stop|restart|graceful" >&2
66
+ exit 3
67
+ ;;
68
+ esac
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ APPLICATION=<%= application %>
4
+ APP_PORT=<%= passenger_port %>
5
+ RVM_RUBY=<%= rvm_ruby_string %>
6
+ ENVIRONMENT=<%= rails_env %>
7
+ INSTANCES_MIN=<%= passenger_min_instances %>
8
+ INSTANCES_MAX=<%= passenger_max_pool_size %>
9
+
10
+ source /usr/local/lib/passengerctl $1
File without changes
@@ -0,0 +1,84 @@
1
+ USER=app_${APPLICATION}
2
+ APP_DIR=<%= thin_applications_dir %>/${APPLICATION}/current
3
+
4
+ if [ "${APP_PORT}" = "" ]; then
5
+ CMD_START="cd ${APP_DIR}; rvm use ${RVM_RUBY}; NOEXEC_DISABLE=1 thin start -s ${THIN_SERVERS} -S tmp/pids/thin.sock -e ${ENVIRONMENT} --stats /thin-status -d"
6
+ CMD_RESTART="cd ${APP_DIR}; rvm use ${RVM_RUBY}; NOEXEC_DISABLE=1 thin restart -s ${THIN_SERVERS} -S tmp/pids/thin.sock -e ${ENVIRONMENT} --stats /thin-status -d"
7
+ else
8
+ CMD_START="cd ${APP_DIR}; rvm use ${RVM_RUBY}; NOEXEC_DISABLE=1 thin start -s ${THIN_SERVERS} -p ${APP_PORT} -e ${ENVIRONMENT} --stats /thin-status -d"
9
+ CMD_RESTART="cd ${APP_DIR}; rvm use ${RVM_RUBY}; NOEXEC_DISABLE=1 thin restart -s ${THIN_SERVERS} -p ${APP_PORT} -e ${ENVIRONMENT} --stats /thin-status -d"
10
+ fi
11
+
12
+ function running_servers() {
13
+ return `ls -1 ${APP_DIR}/tmp/pids/thin.*.pid | wc -l`
14
+ }
15
+
16
+ function start() {
17
+ echo "Starting thin cluster for application '${APPLICATION}'"
18
+ # if [ -f ${PIDFILE} ]; then
19
+ # kill -0 `cat ${PIDFILE}`
20
+ # if [ "$?" == "1" ]; then
21
+ # rm ${APP_DIR}/tmp/pids/thin.*
22
+ # else
23
+ # echo "Thin cluster already running with PID "`cat ${PIDFILE}`
24
+ # return 1
25
+ # fi
26
+ # fi
27
+ su - $USER -c "${CMD_START}"
28
+ }
29
+
30
+ function stop() {
31
+ echo "Stopping thin cluster for application '${APPLICATION}'"
32
+ if [ "${APP_PORT}" == '' ]; then
33
+ running_servers
34
+ CMD_STOP="cd ${APP_DIR}; rvm use ${RVM_RUBY}; NOEXEC_DISABLE=1 thin stop -s $? -S tmp/pids/thin.sock"
35
+ else
36
+ running_servers
37
+ CMD_STOP="cd ${APP_DIR}; rvm use ${RVM_RUBY}; NOEXEC_DISABLE=1 thin stop -s $? -p ${APP_PORT}"
38
+ fi
39
+ su - $USER -c "${CMD_STOP}"
40
+ }
41
+
42
+ function restart() {
43
+ echo "Restarting thin cluster for application '${APPLICATION}'"
44
+ running_servers
45
+ if [ ${THIN_SERVERS} -eq $? ]; then
46
+ echo "RESTART"
47
+ echo ${CMD_RESTART}
48
+ su - $USER -c "${CMD_RESTART}"
49
+ else
50
+ echo "STOP/START"
51
+ stop
52
+ start
53
+ fi
54
+ }
55
+
56
+ function graceful() {
57
+ echo "Restarting thin cluster for application '${APPLICATION}' with one-by-one option"
58
+ running_servers
59
+ if [ ${THIN_SERVERS} -eq $? ]; then
60
+ su - $USER -c "${CMD_RESTART} -O -w 20"
61
+ else
62
+ stop
63
+ start
64
+ fi
65
+ }
66
+
67
+ case "$1" in
68
+ "start")
69
+ start
70
+ ;;
71
+ "stop")
72
+ stop
73
+ ;;
74
+ "restart")
75
+ restart
76
+ ;;
77
+ "graceful")
78
+ graceful
79
+ ;;
80
+ *)
81
+ echo "Usage: $0 start|stop|restart|graceful" >&2
82
+ exit 3
83
+ ;;
84
+ esac
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+
3
+ APPLICATION=<%= application %>
4
+ APP_PORT=<%= thin_port %>
5
+ RVM_RUBY=<%= rvm_ruby_string %>
6
+ ENVIRONMENT=<%= rails_env %>
7
+ THIN_SERVERS=<%= thin_servers %>
8
+
9
+ source /usr/local/lib/thinctl $1
@@ -0,0 +1,12 @@
1
+ module Deploify
2
+ MAJOR = 0
3
+ MINOR = 2
4
+ PATCH = 5
5
+ BUILD = nil
6
+
7
+ if BUILD.nil?
8
+ VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
9
+ else
10
+ VERSION = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
11
+ end
12
+ end
data/lib/deploify.rb ADDED
@@ -0,0 +1,7 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "Deploify requires Capistrano ~> 2.13.3"
3
+ end
4
+
5
+ require "#{File.dirname(__FILE__)}/deploify/capistrano_extensions"
6
+ require "#{File.dirname(__FILE__)}/plugins/all"
7
+ require "#{File.dirname(__FILE__)}/deploify/recipes"
@@ -0,0 +1,20 @@
1
+ # =all.rb: Load all the Capistrano Plugins in the directory.
2
+ #
3
+ # Require all other ruby files in the directory.
4
+ #
5
+ # ----
6
+ # Copyright (c) 2007 Neil Wilson, Aldur Systems Ltd
7
+ #
8
+ # Licensed under the GNU Public License v2. No warranty is provided.
9
+ # ----
10
+ # = Usage
11
+ #
12
+ # require 'vmbuilder_plugins/all'
13
+
14
+ # Splitting and joining __FILE__ deals with the current directory case
15
+ # properly
16
+ Dir[File.join( File.dirname(__FILE__), '*.rb')].each do |plugin_name|
17
+ unless plugin_name == File.join(File.dirname(__FILE__), File.basename(__FILE__))
18
+ require plugin_name
19
+ end
20
+ end
@@ -0,0 +1,94 @@
1
+ # =apt.rb: Debian 'apt' Installer library
2
+ # Capistrano plugin module to install and manage apt packages
3
+ #
4
+ # ----
5
+ # Copyright (c) 2007 Neil Wilson, Aldur Systems Ltd
6
+ #
7
+ # Licensed under the GNU Public License v2. No warranty is provided.
8
+
9
+ require 'capistrano'
10
+
11
+ # = Purpose
12
+ # Apt is a Capistrano plugin module providing a set of methods
13
+ # that invoke the *apt* package manager (as used in Debian and Ubuntu)
14
+ #
15
+ # Installs within Capistrano as the plugin _apt_.
16
+ #
17
+ # =Usage
18
+ #
19
+ # require 'vmbuilder_plugins/apt'
20
+ #
21
+ # Prefix all calls to the library with <tt>apt.</tt>
22
+ #
23
+ module Apt
24
+
25
+ # Default apt-get command - reduces any interactivity to the minimum.
26
+ APT_GET="DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get"
27
+
28
+ # Run the apt install program across the package list in 'packages'.
29
+ # Select those packages referenced by <tt>:base</tt> and the +version+
30
+ # of the distribution you want to use.
31
+ def install(packages, version, options={})
32
+ update
33
+ special_options="--allow-unauthenticated" if version != :stable
34
+ send(run_method, %{
35
+ sh -c "#{APT_GET} -qyu --force-yes #{special_options.to_s} install #{package_list(packages, version)}"
36
+ }, options)
37
+ end
38
+
39
+ # Run an apt clean
40
+ def clean(options={})
41
+ send(run_method, %{sh -c "#{APT_GET} -qy clean"}, options)
42
+ end
43
+
44
+ # Run an apt autoclean
45
+ def autoclean(options={})
46
+ send(run_method, %{sh -c "#{APT_GET} -qy autoclean"}, options)
47
+ end
48
+
49
+ # Run an apt distribution upgrade
50
+ def dist_upgrade(options={})
51
+ update
52
+ send(run_method, %{sh -c "#{APT_GET} -qy dist-upgrade"}, options)
53
+ end
54
+
55
+ # Run an apt upgrade. Use dist_upgrade instead if you want to upgrade
56
+ # the critical base packages.
57
+ def upgrade(options={})
58
+ update
59
+ send(run_method, %{sh -c "#{APT_GET} -qy upgrade"}, options)
60
+ end
61
+
62
+ # Run an apt update.
63
+ def update(options={})
64
+ send(run_method, %{sh -c "#{APT_GET} -qy update"}, options)
65
+ end
66
+
67
+ # RPM package install via alien
68
+ def rpm_install(packages, options={})
69
+ install({:base => %w(wget alien) }, :base)
70
+ send(run_method, "wget -Ncq #{packages.join(' ')}", options)
71
+ files=packages.collect { |package| File.basename(package) }
72
+ send(run_method, "alien -i #{files.join(' ')}", options)
73
+ end
74
+
75
+ # Clear the source list and package cache
76
+ def clear_cache(options={})
77
+ clean
78
+ cmd="rm -f /var/cache/apt/*.bin /var/lib/apt/lists/*_* /var/lib/apt/lists/partial/*"
79
+ send(run_method, cmd, options)
80
+ end
81
+
82
+ private
83
+
84
+ # Provides a string containing all the package names in the base
85
+ #list plus those in +version+.
86
+ def package_list(packages, version)
87
+ Array(packages[:base]).join(' ') + ' ' + Array(packages[version]).join(' ')
88
+ end
89
+
90
+ end
91
+
92
+ Capistrano.plugin :apt, Apt
93
+
94
+ # vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby: