health_check 1.3.1 → 1.4.1
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/.travis.yml +79 -32
- data/CHANGELOG +8 -0
- data/README.rdoc +4 -3
- data/config/routes.rb +5 -2
- data/lib/health_check/health_check_controller.rb +18 -14
- data/lib/health_check/health_check_routes.rb +3 -8
- data/lib/health_check/utils.rb +13 -4
- data/lib/health_check/version.rb +1 -1
- data/lib/health_check.rb +1 -1
- data/test/init_variables +1 -0
- data/test/rails_4.0.gemfile +1 -3
- data/test/rails_edge.gemfile +21 -0
- data/test/setup_railsapp +116 -17
- data/test/test_with_railsapp +266 -144
- data/test/testurl +5 -5
- metadata +6 -4
data/.travis.yml
CHANGED
@@ -16,56 +16,103 @@ bundler_args: "--binstubs"
|
|
16
16
|
script: ./test/test_with_railsapp
|
17
17
|
|
18
18
|
rvm:
|
19
|
-
- 1.8.7
|
20
|
-
- 1.9.2
|
21
|
-
- 1.9.3
|
22
19
|
- 2.0.0
|
23
|
-
- jruby-19mode
|
24
|
-
- rbx-19mode
|
25
|
-
- ree
|
26
20
|
|
27
21
|
gemfile:
|
28
|
-
- test/
|
29
|
-
|
30
|
-
env:
|
31
|
-
- RUBYGEMS_VERSION=
|
22
|
+
- test/rails_4.0.gemfile
|
32
23
|
|
33
24
|
matrix:
|
34
|
-
|
25
|
+
allow_failures:
|
26
|
+
- rvm: rbx-19mode
|
27
|
+
gemfile: test/rails_4.0.gemfile
|
28
|
+
env: RAILS_ENV2=development
|
29
|
+
|
30
|
+
- rvm: 1.9.3
|
31
|
+
gemfile: test/rails_edge.gemfile
|
32
|
+
|
33
|
+
- rvm: 2.0.0
|
34
|
+
gemfile: test/rails_edge.gemfile
|
35
|
+
|
36
|
+
- rvm: ruby-head
|
37
|
+
gemfile: test/rails_edge.gemfile
|
38
|
+
|
39
|
+
- rvm: jruby-head
|
40
|
+
gemfile: test/rails_edge.gemfile
|
41
|
+
|
42
|
+
include:
|
43
|
+
# rails edge
|
44
|
+
|
45
|
+
- rvm: 1.9.3
|
46
|
+
gemfile: test/rails_edge.gemfile
|
47
|
+
|
48
|
+
- rvm: 2.0.0
|
49
|
+
gemfile: test/rails_edge.gemfile
|
50
|
+
|
51
|
+
- rvm: ruby-head
|
52
|
+
gemfile: test/rails_edge.gemfile
|
53
|
+
|
54
|
+
- rvm: jruby-head
|
55
|
+
gemfile: test/rails_edge.gemfile
|
56
|
+
|
57
|
+
# rails 4.0 June 25, 2013
|
58
|
+
|
59
|
+
- rvm: 1.9.3
|
60
|
+
gemfile: test/rails_4.0.gemfile
|
61
|
+
|
62
|
+
- rvm: jruby-19mode
|
63
|
+
gemfile: test/rails_4.0.gemfile
|
64
|
+
|
65
|
+
- rvm: rbx-19mode
|
66
|
+
gemfile: test/rails_4.0.gemfile
|
67
|
+
env: RAILS_ENV2=development
|
68
|
+
|
69
|
+
- rvm: 2.0.0
|
70
|
+
gemfile: test/rails_4.0.gemfile
|
71
|
+
env: RAILS_SERVER=puma
|
72
|
+
|
73
|
+
- rvm: 2.0.0
|
74
|
+
gemfile: test/rails_4.0.gemfile
|
75
|
+
env: RAILS_SERVER=passenger
|
76
|
+
|
77
|
+
- rvm: 2.0.0
|
78
|
+
gemfile: test/rails_4.0.gemfile
|
79
|
+
env: RAILS_SERVER=thin
|
80
|
+
|
81
|
+
- rvm: 2.0.0
|
82
|
+
gemfile: test/rails_4.0.gemfile
|
83
|
+
env: RAILS_SERVER=unicorn
|
84
|
+
|
85
|
+
# rails 3.2 jan 20, 2012
|
35
86
|
- rvm: 1.8.7
|
36
87
|
gemfile: test/rails_3.2.gemfile
|
37
|
-
env: RUBYGEMS_VERSION=
|
38
88
|
|
39
|
-
|
89
|
+
#- rvm: 1.9.2
|
90
|
+
# gemfile: test/rails_3.2.gemfile
|
91
|
+
|
92
|
+
- rvm: 1.9.3
|
40
93
|
gemfile: test/rails_3.2.gemfile
|
41
|
-
env: RUBYGEMS_VERSION=
|
42
94
|
|
43
|
-
|
44
|
-
|
45
|
-
- rvm: 1.8.7
|
46
|
-
gemfile: test/rails_2.3.gemfile
|
47
|
-
env: RUBYGEMS_VERSION=1.8.25
|
95
|
+
- rvm: ree
|
96
|
+
gemfile: test/rails_3.2.gemfile
|
48
97
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
98
|
+
- rvm: jruby-19mode
|
99
|
+
gemfile: test/rails_3.2.gemfile
|
100
|
+
|
101
|
+
- rvm: rbx-19mode
|
102
|
+
gemfile: test/rails_3.2.gemfile
|
53
103
|
|
54
104
|
# rails 3.1 aug 31, 2011 - ruby 1.8.7 or 1.9.2
|
55
105
|
- rvm: 1.8.7
|
56
106
|
gemfile: test/rails_3.1.gemfile
|
57
|
-
env: RUBYGEMS_VERSION=
|
58
107
|
|
59
108
|
- rvm: 1.9.2
|
60
109
|
gemfile: test/rails_3.1.gemfile
|
61
|
-
env: RUBYGEMS_VERSION=
|
62
110
|
|
63
|
-
# rails
|
64
|
-
- rvm:
|
65
|
-
gemfile: test/
|
66
|
-
env: RUBYGEMS_VERSION=
|
111
|
+
# rails 3.0 aug 29 2010 - ruby 1.8.7
|
112
|
+
- rvm: 1.8.7
|
113
|
+
gemfile: test/rails_3.0.gemfile
|
67
114
|
|
68
|
-
-
|
69
|
-
|
115
|
+
# rails 2.3 march 16 2009 - ruby 1.8.7
|
116
|
+
- rvm: 1.8.7
|
117
|
+
gemfile: test/rails_2.3.gemfile
|
70
118
|
env: RUBYGEMS_VERSION=1.8.25
|
71
|
-
|
data/CHANGELOG
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= Change Log =
|
2
2
|
|
3
|
+
* 1.4.1 - Rails 4 and route changes
|
4
|
+
* Now handles routes being generated multiple times by some gem / rails / ruby combinations - Previously multiple calls to health_check_routes where ignored, now explicit calls to health_check_route always adds the route but flags that it doesn't have to be added again on the end of the list
|
5
|
+
* Uses ActiveRecord::Migration.check_pending! if available and returns the message if an exception is raised (Rails 4.0+)
|
6
|
+
* Simplified routing rules down to one rule for Rails 3.0+
|
7
|
+
* Includes some changes for rails 4.1 (edge) - but still a work in progress
|
8
|
+
* 1.3.1 - Include changes from contributers:
|
9
|
+
* Migrations with dots are now handled
|
10
|
+
* the list of checks for "full" / "all" can be configured
|
3
11
|
* 1.2.0 - The gem can now be configured, including timeouts, status codes and text returned on success
|
4
12
|
- Customn checks can be added via initializer like config.add_custom_check { CustomCheckClass.a_custom_check }
|
5
13
|
- You can now request the response to be json or xml (via url or Content-accepted header)
|
data/README.rdoc
CHANGED
@@ -41,7 +41,7 @@ The email gateway is not checked unless the smtp settings have been changed.
|
|
41
41
|
Specify full or include email in the list of checks to verify the smtp settings
|
42
42
|
(eg use 127.0.0.1 instead of localhost).
|
43
43
|
|
44
|
-
Note: rails 4.0 also checks migrations and throws an ActiveRecord::PendingMigrationError exception (http error 500) if there is an error
|
44
|
+
Note: rails 4.0 also checks migrations by default in development mode and throws an ActiveRecord::PendingMigrationError exception (http error 500) if there is an error
|
45
45
|
|
46
46
|
== Installation
|
47
47
|
|
@@ -101,7 +101,7 @@ To change the configuration of health_check, create a file `config/initializers/
|
|
101
101
|
config.http_status_for_error_object = 500
|
102
102
|
|
103
103
|
# You can set what tests are run with the 'full' or 'all' parameter
|
104
|
-
|
104
|
+
config.full_checks = ['database', 'migrations', 'custom', 'email', 'cache']
|
105
105
|
|
106
106
|
# Add one or more custom checks that return a blank string if ok, or an error message if there is an error
|
107
107
|
config.add_custom_check do
|
@@ -128,7 +128,8 @@ See
|
|
128
128
|
* NewRelic Availability Monitoring - http://newrelic.com/docs/features/availability-monitoring-faq
|
129
129
|
* Uptime by OpenACS - http://uptime.openacs.org/uptime/
|
130
130
|
* Engine Yard's guide - https://support.cloud.engineyard.com/entries/20996821-monitor-application-uptime (although the guide is based on fitter_happier plugin it will also work with this gem)
|
131
|
-
*
|
131
|
+
* Nagios check_http (with -s success) - https://www.nagios-plugins.org/doc/man/check_http.html
|
132
|
+
* Any other montoring service that can be set to check for the word success in the text returned from a url
|
132
133
|
|
133
134
|
=== Requesting Json and XML responses
|
134
135
|
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
if defined?(HealthCheck::Engine)
|
2
|
-
|
3
|
-
|
2
|
+
unless HealthCheck::Engine.routes_manually_defined
|
3
|
+
# Ifmountable use: HealthCheck::Engine.routes.draw do
|
4
|
+
Rails.application.routes.draw do
|
5
|
+
health_check_routes(false)
|
6
|
+
end
|
4
7
|
end
|
5
8
|
end
|
@@ -6,7 +6,7 @@ module HealthCheck
|
|
6
6
|
|
7
7
|
session(:off) if Rails.version < '3.0'
|
8
8
|
|
9
|
-
layout
|
9
|
+
layout false if self.respond_to? :layout
|
10
10
|
|
11
11
|
def index
|
12
12
|
checks = params[:checks] || 'standard'
|
@@ -51,24 +51,28 @@ module HealthCheck
|
|
51
51
|
|
52
52
|
# Silence logger as much as we can
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if
|
58
|
-
|
59
|
-
|
54
|
+
if Rails.version < '4.1'
|
55
|
+
|
56
|
+
def process_with_silent_log(method_name, *args)
|
57
|
+
if logger
|
58
|
+
@old_logger_level = logger.level
|
59
|
+
if Rails.version >= '3.2'
|
60
|
+
silence do
|
61
|
+
process_without_silent_log(method_name, *args)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
logger.silence do
|
65
|
+
process_without_silent_log(method_name, *args)
|
66
|
+
end
|
60
67
|
end
|
61
68
|
else
|
62
|
-
|
63
|
-
process_without_silent_log(method_name, *args)
|
64
|
-
end
|
69
|
+
process_without_silent_log(method_name, *args)
|
65
70
|
end
|
66
|
-
else
|
67
|
-
process_without_silent_log(method_name, *args)
|
68
71
|
end
|
69
|
-
end
|
70
72
|
|
71
|
-
|
73
|
+
alias_method_chain :process, :silent_log
|
74
|
+
|
75
|
+
end
|
72
76
|
|
73
77
|
end
|
74
78
|
end
|
@@ -2,14 +2,9 @@ if defined?(HealthCheck::Engine)
|
|
2
2
|
|
3
3
|
module ActionDispatch::Routing
|
4
4
|
class Mapper
|
5
|
-
def health_check_routes
|
6
|
-
|
7
|
-
|
8
|
-
get 'health_check', :to => 'health_check/health_check#index'
|
9
|
-
get 'health_check.:format', :to => 'health_check/health_check#index'
|
10
|
-
get 'health_check/:checks', :to => 'health_check/health_check#index'
|
11
|
-
get 'health_check/:checks.:format', :to => 'health_check/health_check#index'
|
12
|
-
end
|
5
|
+
def health_check_routes(routes_manually_defined = true)
|
6
|
+
HealthCheck::Engine.routes_manually_defined ||= routes_manually_defined
|
7
|
+
get 'health_check(/:checks)(.:format)', :to => 'health_check/health_check#index'
|
13
8
|
end
|
14
9
|
end
|
15
10
|
end
|
data/lib/health_check/utils.rb
CHANGED
@@ -29,10 +29,19 @@ module HealthCheck
|
|
29
29
|
when "email"
|
30
30
|
errors << HealthCheck::Utils.check_email
|
31
31
|
when "migrations", "migration"
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
if defined?(ActiveRecord::Migration) and ActiveRecord::Migration.respond_to?(:check_pending!)
|
33
|
+
# Rails 4+
|
34
|
+
begin
|
35
|
+
ActiveRecord::Migration.check_pending!
|
36
|
+
rescue ActiveRecord::PendingMigrationError => ex
|
37
|
+
errors << ex.message
|
38
|
+
end
|
39
|
+
else
|
40
|
+
database_version = HealthCheck::Utils.get_database_version
|
41
|
+
migration_version = HealthCheck::Utils.get_migration_version
|
42
|
+
if database_version.to_i != migration_version.to_i
|
43
|
+
errors << "Current database version (#{database_version}) does not match latest migration (#{migration_version}). "
|
44
|
+
end
|
36
45
|
end
|
37
46
|
when 'cache'
|
38
47
|
errors << HealthCheck::Utils.check_cache
|
data/lib/health_check/version.rb
CHANGED
data/lib/health_check.rb
CHANGED
data/test/init_variables
CHANGED
data/test/rails_4.0.gemfile
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Gemfile for health_test testing
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
|
7
|
+
ruby '1.9.3' if RUBY_VERSION < '1.9.3'
|
8
|
+
|
9
|
+
gem 'rails'
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rack'
|
12
|
+
|
13
|
+
group :development, :test do
|
14
|
+
if defined?(JRUBY_VERSION)
|
15
|
+
gem 'jruby-openssl'
|
16
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
17
|
+
else
|
18
|
+
gem 'sqlite3'
|
19
|
+
end
|
20
|
+
gem 'shoulda'
|
21
|
+
end
|
data/test/setup_railsapp
CHANGED
@@ -10,7 +10,7 @@ do
|
|
10
10
|
echo "Aborting..."
|
11
11
|
exit 2
|
12
12
|
;;
|
13
|
-
*/test/rails_[0-9].[0-9]*.gemfile)
|
13
|
+
*/test/rails_edge.gemfile|*/test/rails_[0-9].[0-9]*.gemfile)
|
14
14
|
if [ -f "$BUNDLE_GEMFILE" ]; then
|
15
15
|
break
|
16
16
|
fi
|
@@ -63,7 +63,7 @@ echo Gems in tmp/gems:
|
|
63
63
|
ls tmp/gems
|
64
64
|
|
65
65
|
echo Environment:
|
66
|
-
env | egrep 'TRAVIS|RAILS|RUBY|_ENV|GEM|BUNDLE'
|
66
|
+
env | egrep 'TRAVIS|RAILS|RUBY|_ENV|GEM|BUNDLE' || echo "No relevant variables set"
|
67
67
|
|
68
68
|
cd $tmp_dir
|
69
69
|
|
@@ -83,7 +83,14 @@ case "$actual_rails_version" in
|
|
83
83
|
$rails railsapp -d $db
|
84
84
|
;;
|
85
85
|
*' '[34].*)
|
86
|
-
$
|
86
|
+
case "$BUNDLE_GEMFILE" in
|
87
|
+
*rails_edge.gemfile)
|
88
|
+
$rails new railsapp -d $db --edge
|
89
|
+
;;
|
90
|
+
*)
|
91
|
+
$rails new railsapp -d $db
|
92
|
+
;;
|
93
|
+
esac
|
87
94
|
;;
|
88
95
|
*)
|
89
96
|
echo "Unknown rails version"
|
@@ -122,10 +129,6 @@ HealthCheck.setup do |config|
|
|
122
129
|
end
|
123
130
|
!
|
124
131
|
|
125
|
-
echo "Last ten lines of config/environment.rb:"
|
126
|
-
tail -10 config/environment.rb
|
127
|
-
echo
|
128
|
-
|
129
132
|
echo Unsetting BUNDLE_GEMFILE '(so Gemfile for rails application will be used)'
|
130
133
|
unset BUNDLE_GEMFILE
|
131
134
|
|
@@ -134,9 +137,15 @@ then
|
|
134
137
|
echo Adding health_check as gem to Gemfile...
|
135
138
|
echo "gem 'health_check', :path => '$base_dir'" >> Gemfile
|
136
139
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
+
case "$RAILS_SERVER" in
|
141
|
+
webrick|'')
|
142
|
+
echo "Using default webrick server"
|
143
|
+
;;
|
144
|
+
*)
|
145
|
+
echo "Adding $RAILS_SERVER gem to Gemfile (for use as server)"
|
146
|
+
echo "gem '$RAILS_SERVER'" >> Gemfile
|
147
|
+
;;
|
148
|
+
esac
|
140
149
|
echo
|
141
150
|
echo running bundle install --binstubs
|
142
151
|
bundle install --binstubs
|
@@ -152,6 +161,9 @@ then
|
|
152
161
|
rake="$railsapp/bin/rake"
|
153
162
|
# Fix for rvm, otherwise bundle run from rails create fails
|
154
163
|
export PATH="`pwd`/bin:$PATH"
|
164
|
+
echo ================= Gemfile ===================
|
165
|
+
cat Gemfile
|
166
|
+
echo
|
155
167
|
else
|
156
168
|
dest=$railsapp/vendor/plugins/health_check
|
157
169
|
echo Installing health_check as plugin in $dest ...
|
@@ -169,18 +181,37 @@ else
|
|
169
181
|
)
|
170
182
|
fi
|
171
183
|
|
172
|
-
|
173
|
-
|
184
|
+
for e in test ${RAILS_ENV2:-production}
|
185
|
+
do
|
186
|
+
if [ -f config/environments/$e.rb ]; then
|
187
|
+
echo ======== config/environments/$e.rb ================
|
188
|
+
sed -i.bak -e 's/config.serve_static_assets = false/config.serve_static_assets = true # NOTE: health_check test: changed to true/' \
|
189
|
+
-e 's/config.active_record.migration_error = :page_load/# & # NOTE: health_check test: commented out/' \
|
190
|
+
config/environments/$e.rb
|
191
|
+
cat config/environments/$e.rb || true
|
192
|
+
echo
|
193
|
+
fi
|
194
|
+
done
|
195
|
+
echo "============== config/environment.rb ============="
|
196
|
+
cat config/environment.rb
|
197
|
+
echo
|
174
198
|
|
199
|
+
echo ========================
|
175
200
|
case $db in
|
176
201
|
jdbcsqlite3)
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
202
|
+
for e in test ${RAILS_ENV2:-production}
|
203
|
+
do
|
204
|
+
echo
|
205
|
+
export RAILS_ENV=$e RACK_ENV=$e
|
206
|
+
echo "Jruby requires the database to be created before the server is started: running RAILS_ENV=$e rake db:migrate"
|
207
|
+
$rake db:migrate
|
208
|
+
echo
|
209
|
+
done
|
210
|
+
;;
|
182
211
|
esac
|
183
212
|
|
213
|
+
echo STATIC-FILE > public/static.txt
|
214
|
+
|
184
215
|
cat > public/ajax_example.html <<'EOF'
|
185
216
|
<html>
|
186
217
|
<head>
|
@@ -252,6 +283,74 @@ cat > public/ajax_example.html <<'EOF'
|
|
252
283
|
</html>
|
253
284
|
EOF
|
254
285
|
|
286
|
+
cat > app/controllers/example_controller.rb <<'EOF'
|
287
|
+
class ExampleController < ApplicationController
|
288
|
+
|
289
|
+
def index
|
290
|
+
render :text => 'example page'
|
291
|
+
end
|
292
|
+
|
293
|
+
def catchall
|
294
|
+
render :text => 'catch all route'
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
EOF
|
300
|
+
|
301
|
+
if [ -s config/routes.rb ]; then
|
302
|
+
mv -f config/routes.rb config/routes.rb-old
|
303
|
+
var=`ruby -n -e 'print $1 if /^[^#]+ do \|([^\|]+)\|/' config/routes.rb-old`
|
304
|
+
(
|
305
|
+
ruby -n -e 'print if not /^end/..9999' config/routes.rb-old | tee /tmp/t$$
|
306
|
+
if [ ! -s /tmp/t$$ ]; then
|
307
|
+
echo "WARNING: ruby -n -e failed silently - using sed instead!! (rbx-19mode has that problem)" >&3
|
308
|
+
sed -e '/^end/,$d' config/routes.rb-old
|
309
|
+
fi
|
310
|
+
|
311
|
+
case "$var" in
|
312
|
+
'')
|
313
|
+
echo " # -----------------------------------------"
|
314
|
+
echo " # START OF SECTION FOR TESTING HEALTH_CHECK"
|
315
|
+
echo " get 'example(/:action(/:id))(.:format)' => 'example'"
|
316
|
+
echo " if File.exists?('$catchall_file')"
|
317
|
+
echo " health_check_routes"
|
318
|
+
echo " # CATCH ALL ROUTE"
|
319
|
+
echo " get '*path' => 'example#catchall'"
|
320
|
+
echo " end"
|
321
|
+
echo " # END OF SECTION FOR TESTING HEALTH_CHECK"
|
322
|
+
echo " # ---------------------------------------"
|
323
|
+
;;
|
324
|
+
*)
|
325
|
+
echo " # -----------------------------------------"
|
326
|
+
echo " # START OF SECTION FOR TESTING HEALTH_CHECK"
|
327
|
+
echo " # example controller"
|
328
|
+
echo " ${var}.connect 'example(/:action(/:id))(.:format)', :controller => 'example'"
|
329
|
+
echo " if File.exists?('$catchall_file')"
|
330
|
+
echo " # health_check routes already at the top in rails 2.3! do not need to call health_check_routes"
|
331
|
+
echo " # CATCH ALL ROUTE"
|
332
|
+
echo " ${var}.connect '*path', :controller => 'example', :action => 'catchall'"
|
333
|
+
echo " end"
|
334
|
+
echo " # END OF SECTION FOR TESTING HEALTH_CHECK"
|
335
|
+
echo " # ---------------------------------------"
|
336
|
+
;;
|
337
|
+
esac
|
338
|
+
ruby -n -e 'print if /^end/..9999' config/routes.rb-old | tee /tmp/t$$
|
339
|
+
if [ ! -s /tmp/t$$ ]; then
|
340
|
+
echo "WARNING: ruby -n -e failed silently - using sed instead!! (rbx-19mode has that problem)" >&3
|
341
|
+
sed -n -e '/^end/,$p' config/routes.rb-old
|
342
|
+
fi
|
343
|
+
) 3>&1 > config/routes.rb
|
344
|
+
|
345
|
+
#echo =============== config/routes.rb-old ========================
|
346
|
+
#cat config/routes.rb-old
|
347
|
+
echo =============== config/routes.rb ========================
|
348
|
+
cat config/routes.rb
|
349
|
+
else
|
350
|
+
echo NO config/routes.rb file!!
|
351
|
+
fi
|
352
|
+
echo =======================================
|
353
|
+
|
255
354
|
echo
|
256
355
|
echo "Created $actual_rails_version app in $railsapp using adapter $db"
|
257
356
|
echo -n "Using "
|
data/test/test_with_railsapp
CHANGED
@@ -26,6 +26,7 @@ esac
|
|
26
26
|
|
27
27
|
cd $railsapp
|
28
28
|
date > $custom_file
|
29
|
+
rm -f $catchall_file
|
29
30
|
|
30
31
|
testurl="$base_dir/test/testurl"
|
31
32
|
fake_smtp_server="$base_dir/test/fake_smtp_server"
|
@@ -33,6 +34,104 @@ fake_smtp_server="$base_dir/test/fake_smtp_server"
|
|
33
34
|
server_pid=''
|
34
35
|
fake_smtp_pid=''
|
35
36
|
|
37
|
+
pick_a_port()
|
38
|
+
{
|
39
|
+
while :
|
40
|
+
do
|
41
|
+
port=`expr 10000 + $RANDOM`
|
42
|
+
# Check Tcp ports in Listen mode with No address resolution
|
43
|
+
if (netstat -tln | egrep ":${port} .*:"); then
|
44
|
+
echo "(Skipping used port)"
|
45
|
+
else
|
46
|
+
break
|
47
|
+
fi
|
48
|
+
done
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
start_server()
|
53
|
+
{
|
54
|
+
# restart migration list
|
55
|
+
rm -rf db/migrate db/schema.rb
|
56
|
+
mkdir -p db/migrate
|
57
|
+
|
58
|
+
# Increment port each time to make sure we have not trouble with address/port already allocated
|
59
|
+
pick_a_port
|
60
|
+
host=http://127.0.0.1:${port}
|
61
|
+
bundle_prefix=''
|
62
|
+
if [ -f Gemfile ]
|
63
|
+
then
|
64
|
+
bundle_prefix='bundle exec'
|
65
|
+
fi
|
66
|
+
server_arg=${RAILS_SERVER:-webrick}
|
67
|
+
case "$server_arg" in
|
68
|
+
puma)
|
69
|
+
$bundle_prefix puma -b tcp://127.0.0.1:$port &
|
70
|
+
;;
|
71
|
+
passenger)
|
72
|
+
$bundle_prefix passenger start -p $port &
|
73
|
+
;;
|
74
|
+
thin)
|
75
|
+
$bundle_prefix thin start -p $port &
|
76
|
+
;;
|
77
|
+
unicorn)
|
78
|
+
$bundle_prefix unicorn_rails -l 127.0.0.1:$port &
|
79
|
+
;;
|
80
|
+
*)
|
81
|
+
if [ -x script/server ]
|
82
|
+
then
|
83
|
+
echo Starting server on port $port using $bundle_prefix ./script/server ...
|
84
|
+
$bundle_prefix ./script/server $server_arg -p $port &
|
85
|
+
else
|
86
|
+
echo Starting server on port $port using $rails s ...
|
87
|
+
$bundle_prefix $rails server $server_arg -p $port &
|
88
|
+
fi
|
89
|
+
;;
|
90
|
+
esac
|
91
|
+
server_pid=$!
|
92
|
+
sleep 3
|
93
|
+
echo
|
94
|
+
echo 'Checking server is up ...'
|
95
|
+
for i in 1 2 3 4 5 6
|
96
|
+
do
|
97
|
+
if $testurl ${host}/static.txt ; then
|
98
|
+
break
|
99
|
+
fi
|
100
|
+
if kill -0 $server_pid ; then
|
101
|
+
echo "waiting ${i} ..."
|
102
|
+
else
|
103
|
+
echo "ERROR: Server has died!!"
|
104
|
+
exit 3
|
105
|
+
fi
|
106
|
+
done
|
107
|
+
}
|
108
|
+
|
109
|
+
stop_server()
|
110
|
+
{
|
111
|
+
case "$server_pid" in
|
112
|
+
[0-9]*)
|
113
|
+
echo ========================================================
|
114
|
+
echo "Killing rails server [pid: $server_pid]"
|
115
|
+
kill -1 $server_pid || true
|
116
|
+
sleep 2
|
117
|
+
kill -9 $server_pid || true
|
118
|
+
;;
|
119
|
+
esac
|
120
|
+
case "$fake_smtp_pid" in
|
121
|
+
[0-9]*)
|
122
|
+
echo ========================================================
|
123
|
+
echo "Killing fake smtp server [pid: $fake_smtp_pid]"
|
124
|
+
kill -1 $fake_smtp_pid || true
|
125
|
+
sleep 2
|
126
|
+
kill -9 $fake_smtp_pid || true
|
127
|
+
;;
|
128
|
+
esac
|
129
|
+
server_pid=''
|
130
|
+
fake_smtp_pid=''
|
131
|
+
wait
|
132
|
+
sleep 2
|
133
|
+
}
|
134
|
+
|
36
135
|
finish()
|
37
136
|
{
|
38
137
|
set +e
|
@@ -49,21 +148,7 @@ finish()
|
|
49
148
|
tail -50 $railsapp/log/test.log
|
50
149
|
fi
|
51
150
|
|
52
|
-
|
53
|
-
[0-9]*)
|
54
|
-
echo ========================================================
|
55
|
-
echo "Killing fake smtp server [pid: $fake_smtp_pid]"
|
56
|
-
kill -9 $fake_smtp_pid
|
57
|
-
;;
|
58
|
-
esac
|
59
|
-
case "$server_pid" in
|
60
|
-
[0-9]*)
|
61
|
-
echo ========================================================
|
62
|
-
echo "Killing rails server [pid: $server_pid]"
|
63
|
-
kill -9 $server_pid
|
64
|
-
;;
|
65
|
-
esac
|
66
|
-
wait
|
151
|
+
stop_server
|
67
152
|
trap "" 0
|
68
153
|
echo ========================================================
|
69
154
|
echo TEST ${1:-FAILED}
|
@@ -73,151 +158,188 @@ finish()
|
|
73
158
|
|
74
159
|
trap "finish FAILED 1" 0
|
75
160
|
|
76
|
-
|
77
|
-
|
78
|
-
if [ -x script/server ]
|
79
|
-
then
|
80
|
-
if [ -f Gemfile ]
|
81
|
-
then
|
82
|
-
echo Starting server on port $port using bundle exec ./script/server ...
|
83
|
-
bundle exec ./script/server webrick -p $port &
|
84
|
-
else
|
85
|
-
echo Starting server on port $port using ./script/server ...
|
86
|
-
./script/server webrick -p $port &
|
87
|
-
fi
|
88
|
-
else
|
89
|
-
echo Starting server on port $port using $rails s ...
|
90
|
-
$rails s webrick -p $port &
|
91
|
-
fi
|
92
|
-
server_pid=$!
|
93
|
-
sleep 17
|
94
|
-
|
95
|
-
echo STATIC-FILE > public/static.txt
|
96
|
-
|
97
|
-
host=http://localhost:${port}
|
98
|
-
|
99
|
-
# get a static file
|
100
|
-
echo
|
101
|
-
echo 'TESTING can get a static file ...'
|
102
|
-
$testurl ${host}/static.txt 200 text/plain STATIC-FILE
|
103
|
-
echo
|
104
|
-
|
105
|
-
echo 'TESTING health_check/migration should pass with no database migrations ...'
|
106
|
-
mkdir -p db/migrate
|
107
|
-
ls db/migrate
|
108
|
-
$testurl ${host}/health_check/migration 200 text/plain $success
|
109
|
-
echo
|
110
|
-
|
111
|
-
echo 'TESTING health_check/migration should fail without initial database migration ...'
|
112
|
-
cp $base_dir/test/migrate/nine/* db/migrate
|
113
|
-
ls db/migrate
|
114
|
-
$testurl ${host}/health_check/migration 550 text/plain failed
|
115
|
-
echo
|
116
|
-
|
117
|
-
echo 'TESTING health_check/database should pass without initial database migration (since it ignores the difference) ...'
|
118
|
-
$testurl ${host}/health_check/database 200 text/plain $success
|
119
|
-
echo
|
120
|
-
|
121
|
-
echo 'TESTING health_check/site should pass ...'
|
122
|
-
$testurl ${host}/health_check/site 200 text/plain $success
|
123
|
-
echo
|
124
|
-
|
125
|
-
echo 'TESTING health_check/migration should pass after initial database migration ...'
|
126
|
-
$rake db:migrate
|
127
|
-
$testurl ${host}/health_check/migration 200 text/plain $success
|
128
|
-
echo
|
129
|
-
|
130
|
-
echo 'TESTING health_check/migration should fail without all migrations ...'
|
131
|
-
cp $base_dir/test/migrate/twelve/* db/migrate
|
132
|
-
|
133
|
-
case "$actual_rails_version" in
|
134
|
-
*' '[12].*|*' '3.[01]*)
|
135
|
-
echo removing db/migrate/*.*.rb "($actual_rails_version does not support extra dots in migration names)"
|
136
|
-
rm -f db/migrate/*.*.rb
|
137
|
-
;;
|
138
|
-
esac
|
139
|
-
ls db/migrate
|
140
|
-
$testurl ${host}/health_check/migration 550 text/plain failed
|
141
|
-
echo
|
142
|
-
|
143
|
-
echo 'TESTING health_check/migration should pass after both database migrations ...'
|
144
|
-
$rake db:migrate
|
145
|
-
$testurl ${host}/health_check/migration 200 text/plain $success
|
146
|
-
echo
|
161
|
+
common_tests()
|
162
|
+
{
|
147
163
|
|
148
|
-
echo '
|
149
|
-
$rake
|
150
|
-
|
151
|
-
|
164
|
+
echo 'CHECKING routes exist...'
|
165
|
+
$rake routes | tee /tmp/t$$
|
166
|
+
echo
|
167
|
+
case `egrep health_check /tmp/t$$ || true` in
|
168
|
+
'')
|
169
|
+
echo WARNING - routes for health_check not listed!
|
170
|
+
;;
|
171
|
+
esac
|
152
172
|
|
153
|
-
echo
|
154
|
-
|
155
|
-
|
173
|
+
echo
|
174
|
+
echo 'TESTING can get a static file ...'
|
175
|
+
$testurl ${host}/static.txt 200 text/plain STATIC-FILE
|
176
|
+
echo
|
177
|
+
|
178
|
+
echo
|
179
|
+
echo 'TESTING can get an example controller ...'
|
180
|
+
$testurl ${host}/example 200 text/html 'example page'
|
181
|
+
echo
|
182
|
+
|
183
|
+
echo
|
184
|
+
echo 'TESTING direct call to catchall method on example controller ...'
|
185
|
+
$testurl ${host}/example/catchall 200 text/html 'catch all route'
|
186
|
+
echo
|
187
|
+
|
188
|
+
echo 'TESTING health_check/migration should pass with no database migrations ...'
|
189
|
+
ls db/migrate
|
190
|
+
$testurl ${host}/health_check/migration 200 text/plain $success
|
191
|
+
echo
|
192
|
+
|
193
|
+
echo 'TESTING health_check/migration should fail without initial database migration ...'
|
194
|
+
cp $base_dir/test/migrate/nine/* db/migrate
|
195
|
+
ls db/migrate
|
196
|
+
$testurl ${host}/health_check/migration 550 text/plain failed
|
197
|
+
echo
|
198
|
+
|
199
|
+
echo 'TESTING health_check/database should pass without initial database migration (since it ignores the difference) ...'
|
200
|
+
$testurl ${host}/health_check/database 200 text/plain $success
|
201
|
+
echo
|
202
|
+
|
203
|
+
echo 'TESTING health_check/site should pass ...'
|
204
|
+
$testurl ${host}/health_check/site 200 text/plain $success
|
205
|
+
echo
|
206
|
+
|
207
|
+
echo 'TESTING health_check/migration should pass after initial database migration ...'
|
208
|
+
$rake db:migrate
|
209
|
+
$testurl ${host}/health_check/migration 200 text/plain $success
|
210
|
+
echo
|
211
|
+
|
212
|
+
echo 'TESTING health_check/migration should fail without all migrations ...'
|
213
|
+
cp $base_dir/test/migrate/twelve/* db/migrate
|
214
|
+
|
215
|
+
case "$actual_rails_version" in
|
216
|
+
*' '[12].*|*' '3.[01]*)
|
217
|
+
echo removing db/migrate/*.*.rb "($actual_rails_version does not support extra dots in migration names)"
|
218
|
+
rm -f db/migrate/*.*.rb
|
219
|
+
;;
|
220
|
+
esac
|
221
|
+
ls db/migrate
|
222
|
+
$testurl ${host}/health_check/migration 550 text/plain failed
|
223
|
+
echo
|
224
|
+
|
225
|
+
echo 'TESTING health_check/migration should pass after both database migrations ...'
|
226
|
+
$rake db:migrate
|
227
|
+
$testurl ${host}/health_check/migration 200 text/plain $success
|
228
|
+
echo
|
229
|
+
|
230
|
+
echo 'TESTING health_check/migration should pass after both database migrations ...'
|
231
|
+
$rake db:migrate
|
232
|
+
$testurl ${host}/health_check/migration 200 text/plain $success
|
233
|
+
echo
|
234
|
+
|
235
|
+
echo 'TESTING health_check/email should fail without smtp available ...'
|
236
|
+
$testurl ${host}/health_check/email 550 text/plain failed
|
237
|
+
echo
|
238
|
+
|
239
|
+
echo 'TESTING health_check/email should pass with smtp available ...'
|
240
|
+
$fake_smtp_server &
|
241
|
+
fake_smtp_pid=$!
|
242
|
+
sleep 5
|
243
|
+
$testurl ${host}/health_check/email 200 text/plain $success
|
244
|
+
echo
|
245
|
+
|
246
|
+
echo 'TESTING health_check (all) should fail without smtp available ...'
|
247
|
+
$testurl ${host}/health_check 550 text/plain failed
|
248
|
+
echo
|
249
|
+
|
250
|
+
echo 'TESTING health_check/all should fail without smtp available ...'
|
251
|
+
$testurl ${host}/health_check 550 text/plain failed
|
252
|
+
echo
|
253
|
+
|
254
|
+
kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
|
255
|
+
echo 'TESTING health_check (all) should pass with smtp available ...'
|
256
|
+
$fake_smtp_server &
|
257
|
+
fake_smtp_pid=$!
|
258
|
+
sleep 5
|
259
|
+
$testurl ${host}/health_check 200 text/plain $success
|
260
|
+
echo
|
261
|
+
|
262
|
+
kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
|
263
|
+
echo 'TESTING health_check/all should pass with smtp available ...'
|
264
|
+
$fake_smtp_server &
|
265
|
+
fake_smtp_pid=$!
|
266
|
+
sleep 5
|
267
|
+
$testurl ${host}/health_check/all 200 text/plain $success
|
268
|
+
echo
|
269
|
+
|
270
|
+
echo 'TESTING health_check/custom should pass ...'
|
271
|
+
$testurl ${host}/health_check/custom 200 text/plain $success
|
272
|
+
echo
|
273
|
+
|
274
|
+
echo 'TESTING health_check/custom.html should pass (returning plain text) ...'
|
275
|
+
$testurl ${host}/health_check/custom.html 200 text/plain $success
|
276
|
+
echo
|
277
|
+
|
278
|
+
echo 'TESTING health_check/custom.json should pass ...'
|
279
|
+
$testurl ${host}/health_check/custom.json 200 application/json '"healthy":true'
|
280
|
+
$testurl ${host}/health_check/custom.json 200 application/json "\"message\":\"$success\""
|
281
|
+
echo
|
282
|
+
|
283
|
+
echo 'TESTING health_check/custom.xml should pass ...'
|
284
|
+
$testurl ${host}/health_check/custom.xml 200 application/xml '<healthy type="boolean">true</healthy>'
|
285
|
+
$testurl ${host}/health_check/custom.xml 200 application/xml "<message>$success</message>"
|
286
|
+
echo
|
287
|
+
|
288
|
+
echo 'TESTING health_check/custom should fail when custom returns string ...'
|
289
|
+
rm -f $custom_file
|
290
|
+
$testurl ${host}/health_check/custom 550 text/plain failed
|
291
|
+
echo
|
292
|
+
|
293
|
+
echo 'TESTING health_check (all) should fail when custom check fails ...'
|
294
|
+
$testurl ${host}/health_check 550 text/plain "$custom_file is missing!"
|
295
|
+
echo
|
296
|
+
|
297
|
+
echo 'TESTING health_check.json (all) should fail when custom check fails ...'
|
298
|
+
$testurl ${host}/health_check.json 555 application/json '"healthy":false'
|
299
|
+
$testurl ${host}/health_check.json 555 application/json "$custom_file is missing!"
|
300
|
+
echo
|
301
|
+
|
302
|
+
echo 'TESTING health_check.xml (all) should fail when custom check fails ...'
|
303
|
+
$testurl ${host}/health_check.xml 555 application/xml '<healthy type="boolean">false</healthy>'
|
304
|
+
echo
|
305
|
+
|
306
|
+
date > $custom_file
|
307
|
+
}
|
156
308
|
|
157
|
-
echo
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
$testurl ${host}/health_check/email 200 text/plain $success
|
162
|
-
echo
|
309
|
+
echo ========================================================
|
310
|
+
echo TESTING WITHOUT CATCHALL in test env
|
311
|
+
echo ========================================================
|
312
|
+
export RAILS_ENV=test RACK_ENV=test
|
163
313
|
|
164
|
-
|
165
|
-
$testurl ${host}/health_check 550 text/plain failed
|
166
|
-
echo
|
314
|
+
start_server
|
167
315
|
|
168
|
-
|
169
|
-
$testurl ${host}/health_check 550 text/plain failed
|
170
|
-
echo
|
316
|
+
# get a static file
|
171
317
|
|
172
|
-
kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
|
173
|
-
echo 'TESTING health_check (all) should pass with smtp available ...'
|
174
|
-
$fake_smtp_server &
|
175
|
-
fake_smtp_pid=$!
|
176
|
-
sleep 5
|
177
|
-
$testurl ${host}/health_check 200 text/plain $success
|
178
318
|
echo
|
319
|
+
echo 'TESTING no catchall route active ...'
|
320
|
+
expected_status=404,500,502
|
321
|
+
$testurl ${host}/another/url $expected_status
|
179
322
|
|
180
|
-
|
181
|
-
echo 'TESTING health_check/all should pass with smtp available ...'
|
182
|
-
$fake_smtp_server &
|
183
|
-
fake_smtp_pid=$!
|
184
|
-
sleep 5
|
185
|
-
$testurl ${host}/health_check/all 200 text/plain $success
|
186
|
-
echo
|
323
|
+
common_tests
|
187
324
|
|
188
|
-
echo
|
189
|
-
|
190
|
-
echo
|
325
|
+
echo ========================================================
|
326
|
+
echo TESTING WITH CATCHALL in ${RAILS_ENV2:-production} env
|
327
|
+
echo ========================================================
|
328
|
+
export RAILS_ENV=${RAILS_ENV2:-production} RACK_ENV=${RAILS_ENV2:-production}
|
191
329
|
|
192
|
-
|
193
|
-
$testurl ${host}/health_check/custom.json 200 application/json '"healthy":true'
|
194
|
-
$testurl ${host}/health_check/custom.json 200 application/json "\"message\":\"$success\""
|
195
|
-
echo
|
330
|
+
date > $catchall_file
|
196
331
|
|
197
|
-
|
198
|
-
|
199
|
-
$testurl ${host}/health_check/custom.xml 200 application/xml "<message>$success</message>"
|
200
|
-
echo
|
332
|
+
stop_server
|
333
|
+
start_server
|
201
334
|
|
202
|
-
echo 'TESTING health_check/custom should fail when custom returns string ...'
|
203
|
-
rm -f $custom_file
|
204
|
-
$testurl ${host}/health_check/custom 550 text/plain failed
|
205
335
|
echo
|
206
|
-
|
207
|
-
|
208
|
-
$testurl ${host}/health_check 550 text/plain "$custom_file is missing!"
|
336
|
+
echo 'TESTING catchall route active ...'
|
337
|
+
$testurl ${host}/another/url 200 text/html 'catch all route'
|
209
338
|
echo
|
210
339
|
|
211
|
-
|
212
|
-
$testurl ${host}/health_check.json 555 application/json '"healthy":false'
|
213
|
-
$testurl ${host}/health_check.json 555 application/json "$custom_file is missing!"
|
214
|
-
echo
|
340
|
+
common_tests
|
215
341
|
|
216
|
-
|
217
|
-
$testurl ${host}/health_check.xml 555 application/xml '<healthy type="boolean">false</healthy>'
|
218
|
-
echo
|
219
|
-
|
220
|
-
date > $custom_file
|
342
|
+
rm -f $catchall_file
|
221
343
|
|
222
344
|
finish PASSED 0
|
223
345
|
exit 0
|
data/test/testurl
CHANGED
@@ -30,16 +30,16 @@ puts " response code: #{response.code} #{response.message}"
|
|
30
30
|
puts " content_type: #{response.content_type}"
|
31
31
|
puts " body: #{page_content}"
|
32
32
|
|
33
|
-
if ARGV[1]
|
34
|
-
if
|
35
|
-
puts "PASS (response code was #{ARGV[1]})"
|
33
|
+
if ARGV[1] and ARGV[1] != ''
|
34
|
+
if ARGV[1].split(',').include?(response.code)
|
35
|
+
puts "PASS (response code was #{response.code} which matched #{ARGV[1]})"
|
36
36
|
else
|
37
37
|
puts "FAIL (response code was #{response.code}, expected #{ARGV[1]})"
|
38
38
|
exit 1
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
if ARGV[2]
|
42
|
+
if ARGV[2] and ARGV[2] != ''
|
43
43
|
if response.content_type == ARGV[2]
|
44
44
|
puts "PASS (content type was #{response.content_type})"
|
45
45
|
else
|
@@ -48,7 +48,7 @@ if ARGV[2]
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
if ARGV[3]
|
51
|
+
if ARGV[3] and ARGV[3] != ''
|
52
52
|
if page_content.to_s.include? ARGV[3]
|
53
53
|
puts "PASS (found #{ARGV[3]})"
|
54
54
|
else
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: health_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 1
|
10
|
-
version: 1.
|
10
|
+
version: 1.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ian Heggie
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-10-21 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- test/rails_3.1.gemfile
|
138
138
|
- test/rails_3.2.gemfile
|
139
139
|
- test/rails_4.0.gemfile
|
140
|
+
- test/rails_edge.gemfile
|
140
141
|
- test/setup_railsapp
|
141
142
|
- test/test_helper.rb
|
142
143
|
- test/test_with_railsapp
|
@@ -190,6 +191,7 @@ test_files:
|
|
190
191
|
- test/rails_3.1.gemfile
|
191
192
|
- test/rails_3.2.gemfile
|
192
193
|
- test/rails_4.0.gemfile
|
194
|
+
- test/rails_edge.gemfile
|
193
195
|
- test/setup_railsapp
|
194
196
|
- test/test_helper.rb
|
195
197
|
- test/test_with_railsapp
|