public
Description: Capistrano recipes, plugins and templates.
Homepage: http://capitate.rubyforge.org
Clone URL: git://github.com/gabriel/capitate.git
100644 197 lines (158 sloc) 5.216 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#
# Install recipe for Centos 5.1 x86_64 (@base install)
#
# To use this script:
#
# cap HOSTS=10.0.6.118:2023 -s user=root -f install.rb install
#
# Centos 5.1 x86_64 with packages, including:
# * Ruby
# * Nginx
# * Mysql
# * Sphinx
# * Monit
# * ImageMagick
# * Memcached
# * Gems: rake, mysql, raspell, rmagick, mongrel, mongrel_cluster, json, mime-types, hpricot
#
 
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
 
require 'erb'
 
# Load capitate
gem 'capitate', '>= 0.2.9'
require 'capitate'
require 'capitate/recipes'
 
# Load more recipes
Dir[File.dirname(__FILE__) + "/recipes/*.rb"].each { |recipe| load recipe }
 
namespace :install do
 
  task :default do
  
    set :user, "root"
    set :run_method, :run
    check_role
      
    # NTP Setup
    yum.install([ "ntp" ])
    script.run_all <<-CMDS
chkconfig --levels 235 ntpd on
ntpdate 0.pool.ntp.org
/sbin/service ntpd start
CMDS
  
    # Setup for web
    # * Add admin group
    # * Change inittab to runlevel 3
    # * Create web apps directory
    # * Add admin group to suders ALL=(ALL) ALL
    script.run_all <<-CMDS
egrep "^admin" /etc/group || /usr/sbin/groupadd admin
mkdir -p /var/www/apps
egrep "^%admin" /etc/sudoers || echo "%admin ALL=(ALL) ALL" >> /etc/sudoers
CMDS
    
    # Package installs
    yum.update
    yum.install [ "gcc", "kernel-devel", "libevent-devel", "libxml2-devel", "openssl", "openssl-devel",
       "aspell", "aspell-devel", "aspell-en", "aspell-es" ]
    
    yum.clean
      
    #
    # App installs
    #
      
    ruby.centos.install
    nginx.centos.install
    mysql.centos.install
    sphinx.centos.install
    
    monit.centos.install
    # Install firewall rule manually
    #monit.centos.iptables
    
    sshd.monit.install
    
    imagemagick.centos.install
    memcached.centos.install
      
    #
    # Install monit hooks
    #
    nginx.monit.install
    mysql.monit.install
    memcached.monit.install
      
    # Install gems
    gems_only
    
    # Cleanup
    yum.clean
    
    # Log rotate tasks
    monit.logrotate.install
    nginx.logrotate.install
    
  end
  
  desc "Install gems only"
  task :gems_only do
    gems.install(fetch(:gems_to_install))
  end
end
 
# Prompt for server if host not given
task :check_role do
  # Can use cap HOSTS=192.168.1.111 install
  # Otherwise prompt for the service
  role :install, prompt.ask("Server: ") if find_servers_for_task(current_task).blank?
end
 
# For for ruby install
after "ruby:centos:install" do
  # Fix ruby install openssl
  script.sh("ruby/fix_openssl.sh")
end
 
 
#
# Install options
#
 
set :gems_to_install, [ "rake", "mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --with-mysql-config",
  "raspell", "rmagick", "mongrel", "mongrel_cluster", "json", "mime-types", "hpricot" ]
 
 
# Ruby install
set :ruby_build_options, {
  :url => "http://capitate.s3.amazonaws.com/ruby-1.8.6-p110.tar.gz",
  :build_dest => "/usr/src",
  :configure_options => "--prefix=/usr",
  :clean => false
}
 
set :rubygems_build_options, {
  :url => "http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz"
}
 
# Memcached install
set :memcached_pid_path, "/var/run/memcached.pid"
set :memcached_memory, 64
set :memcached_port, 11211
set :memcached_build_options, {
  :url => "http://www.danga.com/memcached/dist/memcached-1.2.4.tar.gz",
  :configure_options => "--prefix=/usr/local"
}
 
# Monit install
set :monit_conf_dir, "/etc/monit"
set :monit_pid_path, "/var/run/monit.pid"
set :monit_port, 2812
set :monit_build_options, {
  :url => "http://www.tildeslash.com/monit/dist/monit-4.10.1.tar.gz"
}
 
# Nginx install
set :nginx_bin_path, "/sbin/nginx"
set :nginx_conf_path, "/etc/nginx/nginx.conf"
set :nginx_pid_path, "/var/run/nginx.pid"
set :nginx_prefix_path, "/var/nginx"
set :nginx_build_options, {
  :url => "http://sysoev.ru/nginx/nginx-0.5.35.tar.gz",
  :configure_options => "--sbin-path=#{nginx_bin_path} --conf-path=#{nginx_conf_path} \
--pid-path=#{nginx_pid_path} --error-log-path=/var/log/nginx_master_error.log --lock-path=/var/lock/nginx \
--prefix=#{nginx_prefix_path} --with-md5=auto/lib/md5 --with-sha1=auto/lib/sha1 --with-http_ssl_module \
--with-http_flv_module"
}
 
# Sphinx install
set :sphinx_prefix, "/usr/local/sphinx-0.9.8-rc1"
set :sphinx_build_options, {
  :url => "http://www.sphinxsearch.com/downloads/sphinx-0.9.8-rc1.tar.gz",
  :configure_options => "--with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib64/mysql --prefix=#{sphinx_prefix}",
  :symlink => { sphinx_prefix => "/usr/local/sphinx" }
}
# Other possible sphinx_build_options
# :url => "http://www.sphinxsearch.com/downloads/sphinx-0.9.7.tar.gz",
# :configure_options => "--with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib/mysql --prefix=#{sphinx_prefix}",
 
 
# For mysql:install
set :mysql_pid_path, "/var/run/mysqld/mysqld.pid"
set :mysql_port, 3306
 
# Imagemagick install
set :imagemagick_build_options, {
  :url => "http://capitate.s3.amazonaws.com/ImageMagick.tar.gz",
  :unpack_dir => "ImageMagick-*"
}
 
# For sshd:monit:install
set :sshd_pid_path, "/var/run/sshd.pid"
set :sshd_port, 2023