winton-ubistrano 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.markdown +116 -0
- data/Rakefile +31 -0
- data/changelog.markdown +24 -0
- data/example/deploy.rb +23 -0
- data/lib/ubistrano/apache.rb +38 -0
- data/lib/ubistrano/deploy.rb +64 -0
- data/lib/ubistrano/ec2.rb +113 -0
- data/lib/ubistrano/gems.rb +29 -0
- data/lib/ubistrano/helpers.rb +271 -0
- data/lib/ubistrano/log.rb +20 -0
- data/lib/ubistrano/mysql.rb +94 -0
- data/lib/ubistrano/rails.rb +76 -0
- data/lib/ubistrano/sinatra.rb +25 -0
- data/lib/ubistrano/ssh.rb +56 -0
- data/lib/ubistrano/stage.rb +29 -0
- data/lib/ubistrano/ubuntu.rb +275 -0
- data/lib/ubistrano.rb +82 -0
- data/templates/apache/virtual_host.erb +32 -0
- data/templates/log/rotate.conf.erb +9 -0
- data/templates/rails/database.yml.erb +13 -0
- data/templates/sinatra/config.ru.erb +19 -0
- data/templates/ubuntu/apache.god.erb +31 -0
- data/templates/ubuntu/god.erb +36 -0
- data/templates/ubuntu/god.god.erb +1 -0
- data/templates/ubuntu/iptables.rules.erb +31 -0
- data/templates/ubuntu/mysql.god.erb +31 -0
- data/templates/ubuntu/sshd.god.erb +31 -0
- data/ubistrano.gemspec +49 -0
- metadata +90 -0
@@ -0,0 +1,275 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
|
3
|
+
namespace :ubuntu do
|
4
|
+
desc "Set up a fresh Ubuntu server"
|
5
|
+
task :default do
|
6
|
+
puts space(msg(:about_templates))
|
7
|
+
exit unless yes(msg(:visudo))
|
8
|
+
if yes("Create the remote deploy user?")
|
9
|
+
exit unless yes(msg(:add_user))
|
10
|
+
end
|
11
|
+
ssh.default
|
12
|
+
ubuntu.config.default
|
13
|
+
ubuntu.aptitude.default
|
14
|
+
puts space(msg(:run_ubuntu_install))
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Restart Ubuntu server"
|
18
|
+
task :restart do
|
19
|
+
if yes(msg(:ubuntu_restart))
|
20
|
+
sudo_each 'shutdown -r now'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :aptitude do
|
25
|
+
desc 'Run all aptitude tasks'
|
26
|
+
task :default do
|
27
|
+
if yes(msg(:aptitude_default))
|
28
|
+
aptitude.update
|
29
|
+
aptitude.upgrade
|
30
|
+
aptitude.essential
|
31
|
+
ubuntu.restart
|
32
|
+
else
|
33
|
+
exit unless yes(msg(:aptitude_instructions))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Aptitude update'
|
38
|
+
task :update do
|
39
|
+
sudo_puts 'aptitude update -q -y'
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Aptitude upgrade'
|
43
|
+
task :upgrade do
|
44
|
+
sudo_puts 'aptitude upgrade -q -y'
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Aptitude install build-essential'
|
48
|
+
task :essential do
|
49
|
+
sudo_puts 'aptitude install build-essential -q -y'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :config do
|
54
|
+
desc 'Run all tasks'
|
55
|
+
task :default do
|
56
|
+
ubuntu.config.sshd_config
|
57
|
+
ubuntu.config.ssh_config
|
58
|
+
ubuntu.config.iptables
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Updates server iptables"
|
62
|
+
task :iptables do
|
63
|
+
if yes(msg(:iptables))
|
64
|
+
upload_from_erb '/etc/iptables.rules', binding, :folder => 'ubuntu'
|
65
|
+
sudo_each [
|
66
|
+
'iptables-restore < /etc/iptables.rules',
|
67
|
+
'rm /etc/iptables.rules'
|
68
|
+
]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Updates sshd_config"
|
73
|
+
task :sshd_config do
|
74
|
+
if yes(msg(:sshd_config))
|
75
|
+
set :ssh_port, port
|
76
|
+
set :port, 22
|
77
|
+
change_line '/etc/ssh/sshd_config', 'Port 22', "Port #{port}"
|
78
|
+
change_line '/etc/ssh/sshd_config', 'PermitRootLogin yes', 'PermitRootLogin no'
|
79
|
+
change_line '/etc/ssh/sshd_config', 'X11Forwarding yes', 'X11Forwarding no'
|
80
|
+
change_line '/etc/ssh/sshd_config', 'UsePAM yes', 'UsePAM no'
|
81
|
+
remove_line '/etc/ssh/sshd_config', 'UseDNS .*'
|
82
|
+
add_line '/etc/ssh/sshd_config', 'UseDNS no'
|
83
|
+
remove_line '/etc/ssh/sshd_config', 'StrictHostKeyChecking .*'
|
84
|
+
sudo_puts '/etc/init.d/ssh reload'
|
85
|
+
set :port, ssh_port
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "Updates ssh_config"
|
90
|
+
task :ssh_config do
|
91
|
+
if yes(msg(:ssh_config))
|
92
|
+
remove_line '/etc/ssh/ssh_config', 'StrictHostKeyChecking .*'
|
93
|
+
add_line '/etc/ssh/ssh_config', 'StrictHostKeyChecking no'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
namespace :install do
|
99
|
+
desc 'Run all install tasks'
|
100
|
+
task :default do
|
101
|
+
ubuntu.install.apache
|
102
|
+
ubuntu.install.git
|
103
|
+
ubuntu.install.mysql
|
104
|
+
ubuntu.install.mysqltuner
|
105
|
+
ubuntu.install.perl
|
106
|
+
ubuntu.install.php
|
107
|
+
ubuntu.install.postfix
|
108
|
+
ubuntu.install.ruby
|
109
|
+
ubuntu.install.rubygems
|
110
|
+
ubuntu.install.passenger
|
111
|
+
ubuntu.install.god
|
112
|
+
ubuntu.install.rails
|
113
|
+
ubuntu.install.sinatra
|
114
|
+
ubuntu.install.sphinx
|
115
|
+
ubuntu.restart
|
116
|
+
puts space(msg(:ubuntu_finished))
|
117
|
+
end
|
118
|
+
|
119
|
+
desc 'Install Apache'
|
120
|
+
task :apache, :roles => :web do
|
121
|
+
if yes("May I install Apache?")
|
122
|
+
sudo_puts [
|
123
|
+
'aptitude install apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapr1 libaprutil1 ssl-cert -q -y',
|
124
|
+
'a2enmod rewrite',
|
125
|
+
'a2enmod ssl',
|
126
|
+
'a2dissite default'
|
127
|
+
]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
desc 'Install Git'
|
132
|
+
task :git, :roles => :app do
|
133
|
+
install_source(:git) do |path|
|
134
|
+
sudo_puts [
|
135
|
+
'apt-get build-dep git-core -q -y',
|
136
|
+
make_install(path)
|
137
|
+
]
|
138
|
+
end if yes("May I install Git?")
|
139
|
+
end
|
140
|
+
|
141
|
+
desc 'Install MySQL'
|
142
|
+
task :mysql, :roles => :db do
|
143
|
+
if yes("May I install MySQL?")
|
144
|
+
sudo_puts 'aptitude install mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 libmysqlclient15-dev libmysqlclient15off -q -y'
|
145
|
+
ROOT.mysql.create.user
|
146
|
+
exit unless yes(msg(:secure_mysql))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
desc "Install MySQLTuner"
|
151
|
+
task :mysqltuner, :roles => :db do
|
152
|
+
if yes(msg(:mysqltuner))
|
153
|
+
bin = "/usr/local/bin"
|
154
|
+
run_each [
|
155
|
+
"cd #{bin} && sudo wget --quiet #{sources[:mysqltuner]}",
|
156
|
+
"cd #{bin} && sudo chmod 0700 mysqltuner.pl",
|
157
|
+
"cd #{bin} && sudo mv mysqltuner.pl mysqltuner"
|
158
|
+
]
|
159
|
+
exit unless yes(msg(:mysqltuner_instructions))
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
desc 'Install Perl'
|
164
|
+
task :perl, :roles => :web do
|
165
|
+
if yes("May I install Perl?")
|
166
|
+
sudo_puts 'aptitude install libdbi-perl libnet-daemon-perl libplrpc-perl libdbd-mysql-perl -q -y'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
desc 'Install PHP'
|
171
|
+
task :php, :roles => :web do
|
172
|
+
if yes("May I install PHP?")
|
173
|
+
sudo_puts 'aptitude install php5-common php5-mysql libapache2-mod-php5 php-pear php-mail php-net-smtp -q -y'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
desc 'Install Postfix'
|
178
|
+
task :postfix, :roles => :web do
|
179
|
+
if yes("May I install Postfix and set it up as a relay?")
|
180
|
+
smtp = ask 'What is your SMTP server address?'
|
181
|
+
login = ask 'What is your SMTP server username?'
|
182
|
+
pass = ask 'What is your SMTP server password?'
|
183
|
+
sudo_puts 'aptitude install postfix -q -y'
|
184
|
+
add_line '/etc/postfix/main.cf',
|
185
|
+
'smtp_sasl_auth_enable = yes',
|
186
|
+
'smtp_sasl_security_options = noanonymous',
|
187
|
+
'smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd',
|
188
|
+
'smtp_always_send_ehlo = yes',
|
189
|
+
"relayhost = #{smtp}"
|
190
|
+
sudo_each 'touch /etc/postfix/saslpasswd'
|
191
|
+
add_line '/etc/postfix/saslpasswd', "#{smtp} #{login}:#{pass}"
|
192
|
+
sudo_each [
|
193
|
+
'postmap /etc/postfix/saslpasswd',
|
194
|
+
'/etc/init.d/postfix restart'
|
195
|
+
]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
desc 'Install Ruby'
|
200
|
+
task :ruby, :roles => :app do
|
201
|
+
if yes("May I install Ruby?")
|
202
|
+
sudo_puts "aptitude install libopenssl-ruby -q -y"
|
203
|
+
install_source(:ruby) do |path|
|
204
|
+
sudo_puts make_install(path)
|
205
|
+
sudo_puts make_install(path) # install twice because openssl doesn't the first time
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
desc 'Install RubyGems'
|
211
|
+
task :rubygems, :roles => :app do
|
212
|
+
if yes("May I install RubyGems?")
|
213
|
+
install_source(:rubygems) do |path|
|
214
|
+
run_puts "cd #{path} && sudo ruby setup.rb"
|
215
|
+
end
|
216
|
+
gems.update
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
desc 'Install Passenger'
|
221
|
+
task :passenger, :roles => :app do
|
222
|
+
if yes("May I install Passenger (mod_rails)?")
|
223
|
+
sudo_puts 'aptitude install apache2-prefork-dev -q -y'
|
224
|
+
gem_install :passenger
|
225
|
+
ROOT.apache.reload if yes(msg(:passenger))
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
desc 'Install God'
|
230
|
+
task :god, :roles => :app do
|
231
|
+
if yes(msg(:god))
|
232
|
+
gem_install 'god'
|
233
|
+
upload_from_erb '/etc/init.d/god', binding, :folder => 'ubuntu'
|
234
|
+
sudo_each [
|
235
|
+
';cd /etc/init.d && sudo chmod +x god',
|
236
|
+
'mkdir -p /usr/local/etc/god'
|
237
|
+
]
|
238
|
+
upload_from_erb('/usr/local/etc/god.god', binding, :folder => 'ubuntu')
|
239
|
+
upload_from_erb('/usr/local/etc/god/apache.god', binding, :folder => 'ubuntu') if yes(msg(:god_apache))
|
240
|
+
upload_from_erb('/usr/local/etc/god/mysql.god', binding, :folder => 'ubuntu') if yes(msg(:god_mysql))
|
241
|
+
upload_from_erb('/usr/local/etc/god/sshd.god', binding, :folder => 'ubuntu') if yes(msg(:god_sshd))
|
242
|
+
sudo_puts [
|
243
|
+
'update-rc.d god defaults',
|
244
|
+
'/etc/init.d/god start'
|
245
|
+
]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
desc 'Install Rails'
|
250
|
+
task :rails, :roles => :app do
|
251
|
+
if yes("May I install Rails?")
|
252
|
+
gem_install :mysql
|
253
|
+
gem_install :rails
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
desc 'Install Sinatra'
|
258
|
+
task :sinatra, :roles => :app do
|
259
|
+
if yes("May I install Sinatra?")
|
260
|
+
gem_install :do_mysql # Datamapper
|
261
|
+
gem_install 'dm-core'
|
262
|
+
gem_install :sinatra # Sinatra
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
desc 'Install Sphinx'
|
267
|
+
task :sphinx, :roles => :app do
|
268
|
+
install_source(:sphinx) do |path|
|
269
|
+
sudo_puts make_install(path)
|
270
|
+
end if yes("May I install Sphinx?")
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
data/lib/ubistrano.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
require 'EC2'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
# Require helpers and recipes
|
6
|
+
Dir["#{File.dirname(__FILE__)}/ubistrano/*.rb"].each { |f| require f }
|
7
|
+
|
8
|
+
|
9
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
10
|
+
|
11
|
+
# Default capistrano/ubistrano values
|
12
|
+
set :ubistrano, {
|
13
|
+
:base_dir => '/var/www',
|
14
|
+
:db_user => 'app',
|
15
|
+
:db_pass => '',
|
16
|
+
:deploy_via => :remote_cache,
|
17
|
+
:domains => [],
|
18
|
+
:platform => :rails,
|
19
|
+
:plugins => {},
|
20
|
+
:port => 22,
|
21
|
+
:repository_cache => 'git_cache',
|
22
|
+
:scm => :git,
|
23
|
+
:ssl => [],
|
24
|
+
:stage => :production,
|
25
|
+
:use_sudo => false,
|
26
|
+
:user => 'deploy',
|
27
|
+
:versions => {}
|
28
|
+
}.merge(ubistrano)
|
29
|
+
|
30
|
+
# Default plugins
|
31
|
+
ubistrano[:plugins] = {
|
32
|
+
:app_helpers => false,
|
33
|
+
:asset_packager => false,
|
34
|
+
:attachment_fu => false,
|
35
|
+
:rails_widget => false,
|
36
|
+
:thinking_sphinx => false
|
37
|
+
}.merge(ubistrano[:plugins])
|
38
|
+
|
39
|
+
# Default versions
|
40
|
+
ubistrano[:versions] = {
|
41
|
+
:git => '1.6.0.4',
|
42
|
+
:mysecureshell => '1.1',
|
43
|
+
:rails => '2.2.2',
|
44
|
+
:ruby => '1.8.7-p72',
|
45
|
+
:rubygems => '1.3.1',
|
46
|
+
:sphinx => '0.9.8.1'
|
47
|
+
}.merge(ubistrano[:versions])
|
48
|
+
|
49
|
+
# Merge ubistrano hash with capistrano
|
50
|
+
ubistrano.each do |key, value|
|
51
|
+
value.respond_to?(:keys) ?
|
52
|
+
value.each { |k, v| set "#{key}_#{k}".intern, v } :
|
53
|
+
set(key, value)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Default sources
|
57
|
+
set :sources, {
|
58
|
+
:git => "http://kernel.org/pub/software/scm/git/git-#{versions_git}.tar.gz",
|
59
|
+
:mysecureshell => "http://internap.dl.sourceforge.net/sourceforge/mysecureshell/MySecureShell-#{versions_mysecureshell}_source.tgz",
|
60
|
+
:mysqltuner => "http://mysqltuner.com/mysqltuner.pl",
|
61
|
+
:ruby => "ftp://ftp.ruby-lang.org/pub/ruby/#{versions_ruby.split('.')[0..1].join('.')}/ruby-#{versions_ruby}.tar.gz",
|
62
|
+
:rubygems => "http://rubyforge.org/frs/download.php/45905/rubygems-#{versions_rubygems}.tgz",
|
63
|
+
:sphinx => "http://www.sphinxsearch.com/downloads/sphinx-#{versions_sphinx}.tar.gz"
|
64
|
+
}.merge(fetch(:sources, {}))
|
65
|
+
|
66
|
+
# Events
|
67
|
+
on :before, 'setup_stage', :except => [ :staging, :testing ] # Executed before every task
|
68
|
+
after('deploy:update_code', 'rails:config:to_app' ) if platform == :rails
|
69
|
+
after('deploy:update_code', 'sinatra:config:to_app') if platform == :sinatra
|
70
|
+
after('deploy:update_code', 'rails:config:app_helpers') if plugins_app_helpers
|
71
|
+
after('deploy:update_code', 'rails:config:asset_packager') if plugins_asset_packager
|
72
|
+
after('deploy:update_code', 'rails:config:attachment_fu') if plugins_attachment_fu
|
73
|
+
after('deploy:update_code', 'rails:config:rails_widget') if plugins_rails_widget
|
74
|
+
after('deploy:update_code', 'rails:config:thinking_sphinx') if plugins_thinking_sphinx
|
75
|
+
|
76
|
+
# Other options
|
77
|
+
ssh_options[:paranoid] = false
|
78
|
+
|
79
|
+
# Reference ROOT when namespaces clash
|
80
|
+
ROOT = self
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
NameVirtualHost *:80
|
2
|
+
<% unless ssl.empty? %>
|
3
|
+
NameVirtualHost *:443
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<VirtualHost *:80>
|
7
|
+
<% unless domains.empty? %>
|
8
|
+
ServerName <%= domains.first %>
|
9
|
+
<% if domains.length > 1 %>
|
10
|
+
ServerAlias <%= domains[1..-1].join ' ' %>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
DocumentRoot <%= deploy_to %>/current/public
|
14
|
+
ErrorLog <%= deploy_to %>/current/log/error.log
|
15
|
+
CustomLog <%= deploy_to %>/current/log/access.log combined
|
16
|
+
<% unless ssl.empty? %>
|
17
|
+
Redirect / https://<%= ssl.first %>/
|
18
|
+
<% end %>
|
19
|
+
</VirtualHost>
|
20
|
+
|
21
|
+
<% ssl.each do |s| %>
|
22
|
+
<VirtualHost *:443>
|
23
|
+
ServerName <%= s %>
|
24
|
+
DocumentRoot <%= deploy_to %>/current/public
|
25
|
+
ErrorLog <%= deploy_to %>/current/log/error.log
|
26
|
+
CustomLog <%= deploy_to %>/current/log/access.log combined
|
27
|
+
|
28
|
+
SSLEngine On
|
29
|
+
SSLCertificateFile <%= deploy_to %>/current/cert/<%= s %>.crt
|
30
|
+
SSLCertificateKeyFile <%= deploy_to %>/current/cert/<%= s %>.key
|
31
|
+
</VirtualHost>
|
32
|
+
<% end unless ssl.empty? %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
Sinatra::Application.default_options.merge!(
|
5
|
+
:run => false,
|
6
|
+
:env => :production,
|
7
|
+
:raise_errors => true,
|
8
|
+
:app_file => 'app.rb',
|
9
|
+
:root => '<%= deploy_to %>/current',
|
10
|
+
:views => '<%= deploy_to %>/current/views',
|
11
|
+
:public => '<%= deploy_to %>/current/public'
|
12
|
+
)
|
13
|
+
|
14
|
+
log = File.new('<%= deploy_to %>/shared/log/sinatra.log', 'a')
|
15
|
+
STDOUT.reopen(log)
|
16
|
+
STDERR.reopen(log)
|
17
|
+
|
18
|
+
require 'app'
|
19
|
+
run Sinatra.application
|
@@ -0,0 +1,31 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'apache'
|
3
|
+
w.start = "/etc/init.d/apache2 start"
|
4
|
+
w.stop = "/etc/init.d/apache2 stop"
|
5
|
+
w.restart = "/etc/init.d/apache2 restart"
|
6
|
+
w.interval = 30.seconds
|
7
|
+
w.start_grace = 10.seconds
|
8
|
+
w.restart_grace = 10.seconds
|
9
|
+
w.pid_file = '/var/run/apache2.pid'
|
10
|
+
w.behavior(:clean_pid_file)
|
11
|
+
|
12
|
+
w.start_if do |start|
|
13
|
+
start.condition(:process_running) do |c|
|
14
|
+
c.interval = 5.seconds
|
15
|
+
c.running = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# lifecycle
|
20
|
+
w.lifecycle do |on|
|
21
|
+
on.condition(:flapping) do |c|
|
22
|
+
c.to_state = [:start, :restart]
|
23
|
+
c.times = 5
|
24
|
+
c.within = 5.minute
|
25
|
+
c.transition = :unmonitored
|
26
|
+
c.retry_in = 10.minutes
|
27
|
+
c.retry_times = 5
|
28
|
+
c.retry_within = 2.hours
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# God
|
4
|
+
#
|
5
|
+
# chkconfig: - 85 15
|
6
|
+
# description: start, stop, restart God (bet you feel powerful)
|
7
|
+
#
|
8
|
+
|
9
|
+
RETVAL=0
|
10
|
+
|
11
|
+
case "$1" in
|
12
|
+
start)
|
13
|
+
/usr/local/bin/god -P /var/run/god.pid -l /var/log/god.log
|
14
|
+
/usr/local/bin/god load /usr/local/etc/god.god
|
15
|
+
RETVAL=$?
|
16
|
+
;;
|
17
|
+
stop)
|
18
|
+
kill `cat /var/run/god.pid`
|
19
|
+
RETVAL=$?
|
20
|
+
;;
|
21
|
+
restart)
|
22
|
+
kill `cat /var/run/god.pid`
|
23
|
+
/usr/local/bin/god -P /var/run/god.pid -l /var/log/god.log
|
24
|
+
/usr/local/bin/god load /usr/local/etc/god.god
|
25
|
+
RETVAL=$?
|
26
|
+
;;
|
27
|
+
status)
|
28
|
+
RETVAL=$?
|
29
|
+
;;
|
30
|
+
*)
|
31
|
+
echo "Usage: god {start|stop|restart|status}"
|
32
|
+
exit 1
|
33
|
+
;;
|
34
|
+
esac
|
35
|
+
|
36
|
+
exit $RETVAL
|
@@ -0,0 +1 @@
|
|
1
|
+
God.load "/usr/local/etc/god/*.god"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
*filter
|
2
|
+
|
3
|
+
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
|
4
|
+
-A INPUT -i lo -j ACCEPT
|
5
|
+
-A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
|
6
|
+
|
7
|
+
# Accept all established inbound connections
|
8
|
+
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
9
|
+
|
10
|
+
# Allow all outbound traffic
|
11
|
+
-A OUTPUT -j ACCEPT
|
12
|
+
|
13
|
+
# Allow HTTP and HTTPS connections
|
14
|
+
-A INPUT -p tcp --dport 80 -j ACCEPT
|
15
|
+
-A INPUT -p tcp --dport 443 -j ACCEPT
|
16
|
+
|
17
|
+
# Allow SSH connections
|
18
|
+
-A INPUT -p tcp -m state --state NEW --dport <%= port %> -j ACCEPT
|
19
|
+
|
20
|
+
# Allow ping
|
21
|
+
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
|
22
|
+
|
23
|
+
# Log iptables denied calls
|
24
|
+
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
|
25
|
+
|
26
|
+
# Reject all other inbound
|
27
|
+
-A INPUT -j REJECT
|
28
|
+
-A FORWARD -j REJECT
|
29
|
+
|
30
|
+
COMMIT
|
31
|
+
# There MUST be a new line after this line!
|
@@ -0,0 +1,31 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'mysql'
|
3
|
+
w.start = "/etc/init.d/mysqld start"
|
4
|
+
w.stop = "/etc/init.d/mysqld start"
|
5
|
+
w.restart = "/etc/init.d/mysqld restart"
|
6
|
+
w.interval = 30.seconds
|
7
|
+
w.start_grace = 10.seconds
|
8
|
+
w.restart_grace = 10.seconds
|
9
|
+
w.pid_file = '/var/run/mysqld/mysqld.pid'
|
10
|
+
w.behavior(:clean_pid_file)
|
11
|
+
|
12
|
+
w.start_if do |start|
|
13
|
+
start.condition(:process_running) do |c|
|
14
|
+
c.interval = 5.seconds
|
15
|
+
c.running = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# lifecycle
|
20
|
+
w.lifecycle do |on|
|
21
|
+
on.condition(:flapping) do |c|
|
22
|
+
c.to_state = [:start, :restart]
|
23
|
+
c.times = 5
|
24
|
+
c.within = 5.minute
|
25
|
+
c.transition = :unmonitored
|
26
|
+
c.retry_in = 10.minutes
|
27
|
+
c.retry_times = 5
|
28
|
+
c.retry_within = 2.hours
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'sshd'
|
3
|
+
w.start = "/etc/init.d/ssh start"
|
4
|
+
w.stop = "/etc/init.d/ssh stop"
|
5
|
+
w.restart = "/etc/init.d/ssh restart"
|
6
|
+
w.interval = 30.seconds
|
7
|
+
w.start_grace = 10.seconds
|
8
|
+
w.restart_grace = 10.seconds
|
9
|
+
w.pid_file = '/var/run/sshd.pid'
|
10
|
+
w.behavior(:clean_pid_file)
|
11
|
+
|
12
|
+
w.start_if do |start|
|
13
|
+
start.condition(:process_running) do |c|
|
14
|
+
c.interval = 5.seconds
|
15
|
+
c.running = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# lifecycle
|
20
|
+
w.lifecycle do |on|
|
21
|
+
on.condition(:flapping) do |c|
|
22
|
+
c.to_state = [:start, :restart]
|
23
|
+
c.times = 5
|
24
|
+
c.within = 5.minute
|
25
|
+
c.transition = :unmonitored
|
26
|
+
c.retry_in = 10.minutes
|
27
|
+
c.retry_times = 5
|
28
|
+
c.retry_within = 2.hours
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/ubistrano.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ubistrano'
|
3
|
+
s.version = '1.2.2'
|
4
|
+
s.date = '2008-02-22'
|
5
|
+
|
6
|
+
s.summary = "Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano"
|
7
|
+
s.description = "Provision and deploy to an Ubuntu/God/Apache/Passenger stack using Capistrano"
|
8
|
+
|
9
|
+
s.author = 'Winton Welsh'
|
10
|
+
s.email = 'mail@wintoni.us'
|
11
|
+
s.homepage = 'http://github.com/winton/ubistrano'
|
12
|
+
|
13
|
+
s.has_rdoc = false
|
14
|
+
s.add_dependency 'amazon-ec2', '>= 0.3.2'
|
15
|
+
|
16
|
+
# = MANIFEST =
|
17
|
+
s.files = %w[
|
18
|
+
MIT-LICENSE
|
19
|
+
README.markdown
|
20
|
+
Rakefile
|
21
|
+
changelog.markdown
|
22
|
+
example/deploy.rb
|
23
|
+
lib/ubistrano.rb
|
24
|
+
lib/ubistrano/apache.rb
|
25
|
+
lib/ubistrano/deploy.rb
|
26
|
+
lib/ubistrano/ec2.rb
|
27
|
+
lib/ubistrano/gems.rb
|
28
|
+
lib/ubistrano/helpers.rb
|
29
|
+
lib/ubistrano/log.rb
|
30
|
+
lib/ubistrano/mysql.rb
|
31
|
+
lib/ubistrano/rails.rb
|
32
|
+
lib/ubistrano/sinatra.rb
|
33
|
+
lib/ubistrano/ssh.rb
|
34
|
+
lib/ubistrano/stage.rb
|
35
|
+
lib/ubistrano/ubuntu.rb
|
36
|
+
templates/apache/virtual_host.erb
|
37
|
+
templates/log/rotate.conf.erb
|
38
|
+
templates/rails/database.yml.erb
|
39
|
+
templates/sinatra/config.ru.erb
|
40
|
+
templates/ubuntu/apache.god.erb
|
41
|
+
templates/ubuntu/god.erb
|
42
|
+
templates/ubuntu/god.god.erb
|
43
|
+
templates/ubuntu/iptables.rules.erb
|
44
|
+
templates/ubuntu/mysql.god.erb
|
45
|
+
templates/ubuntu/sshd.god.erb
|
46
|
+
ubistrano.gemspec
|
47
|
+
]
|
48
|
+
# = MANIFEST =
|
49
|
+
end
|