sunshine 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/Manifest.txt +0 -3
- data/README.txt +50 -43
- data/Rakefile +4 -4
- data/bin/sunshine +1 -1
- data/examples/deploy_tasks.rake +0 -27
- data/lib/commands/list.rb +0 -24
- data/lib/sunshine.rb +24 -14
- data/lib/sunshine/app.rb +127 -211
- data/lib/sunshine/binder.rb +1 -2
- data/lib/sunshine/daemon.rb +1 -1
- data/lib/sunshine/daemons/apache.rb +1 -1
- data/lib/sunshine/remote_shell.rb +14 -16
- data/lib/sunshine/repos/git_repo.rb +1 -1
- data/lib/sunshine/server_app.rb +12 -76
- data/lib/sunshine/shell.rb +38 -20
- data/templates/apache/apache.conf.erb +0 -2
- data/templates/sunshine/sunshine.rake +0 -33
- data/test/unit/test_app.rb +0 -43
- data/test/unit/test_nginx.rb +1 -1
- data/test/unit/test_server_app.rb +17 -87
- metadata +20 -32
- data/lib/sunshine/healthcheck.rb +0 -98
- data/templates/sunshine/middleware/health.rb +0 -58
- data/test/unit/test_healthcheck.rb +0 -70
@@ -1,58 +0,0 @@
|
|
1
|
-
module Sunshine
|
2
|
-
|
3
|
-
class Health
|
4
|
-
|
5
|
-
##
|
6
|
-
# Default healthcheck request path.
|
7
|
-
|
8
|
-
DEFAULT_REQUEST_PATH = '/_health'
|
9
|
-
|
10
|
-
|
11
|
-
##
|
12
|
-
# The healthcheck-enabled file.
|
13
|
-
|
14
|
-
HEALTHCHECK_FILE = '../../health.enabled'
|
15
|
-
|
16
|
-
|
17
|
-
##
|
18
|
-
# Creates a new SunshineHealth middleware. Supported options are:
|
19
|
-
# :uri_path:: The path that healthcheck will be used on.
|
20
|
-
# :health_file:: The file to check for health.
|
21
|
-
|
22
|
-
def initialize app, options={}
|
23
|
-
@app = app
|
24
|
-
@uri_path = options[:uri_path] || DEFAULT_REQUEST_PATH
|
25
|
-
@healthcheck_file = options[:health_file] || HEALTHCHECK_FILE
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def call env
|
30
|
-
check_health?(env) ? health_response : @app.call(env)
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
##
|
35
|
-
# Given the rack env, do we need to perform a health check?
|
36
|
-
|
37
|
-
def check_health? env
|
38
|
-
env['PATH_INFO'] == @uri_path
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
##
|
43
|
-
# Check if healthcheck is enabled.
|
44
|
-
|
45
|
-
def health_enabled?
|
46
|
-
File.file? @healthcheck_file
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
##
|
51
|
-
# Get a rack response for the current health status.
|
52
|
-
|
53
|
-
def health_response
|
54
|
-
status, body = health_enabled? ? [200, "OK"] : [404, "404"]
|
55
|
-
[status, {'Content-Type' => 'text/html'}, body]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'test/test_helper'
|
2
|
-
|
3
|
-
class TestHealthcheck < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@remote_shell = mock_remote_shell
|
7
|
-
@health = Sunshine::Healthcheck.new "somepath", @remote_shell
|
8
|
-
|
9
|
-
@test_disabled = "test -f #{@health.disabled_file}"
|
10
|
-
@test_enabled = "test -f #{@health.enabled_file}"
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def test_initialize
|
15
|
-
assert_equal @remote_shell, @health.shell
|
16
|
-
assert_equal "somepath/health.enabled", @health.enabled_file
|
17
|
-
assert_equal "somepath/health.disabled", @health.disabled_file
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def test_disable
|
22
|
-
@health.disable
|
23
|
-
|
24
|
-
cmd = "touch #{@health.disabled_file} && rm -f #{@health.enabled_file}"
|
25
|
-
assert_ssh_call cmd
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def test_enable
|
30
|
-
@health.enable
|
31
|
-
|
32
|
-
cmd = "rm -f #{@health.disabled_file} && touch #{@health.enabled_file}"
|
33
|
-
assert_ssh_call cmd
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def test_remove
|
38
|
-
@health.remove
|
39
|
-
|
40
|
-
cmd = "rm -f #{@health.disabled_file} #{@health.enabled_file}"
|
41
|
-
assert_ssh_call cmd
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def test_status_down
|
46
|
-
@remote_shell.set_mock_response 1,
|
47
|
-
@test_disabled => [:err, ""],
|
48
|
-
@test_enabled => [:err, ""]
|
49
|
-
|
50
|
-
assert_equal(:down, @health.status)
|
51
|
-
|
52
|
-
assert_ssh_call @test_disabled
|
53
|
-
assert_ssh_call @test_enabled
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
def test_status_ok
|
58
|
-
@remote_shell.set_mock_response 1, @test_disabled => [:err, ""]
|
59
|
-
@remote_shell.set_mock_response 0, @test_enabled => [:out, ""]
|
60
|
-
|
61
|
-
assert_equal(:enabled, @health.status)
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def test_status_disabled
|
66
|
-
@remote_shell.set_mock_response 0, @test_disabled => [:out, ""]
|
67
|
-
|
68
|
-
assert_equal(:disabled, @health.status)
|
69
|
-
end
|
70
|
-
end
|