Class: Sunshine::Healthcheck
- Inherits:
-
Object
- Object
- Sunshine::Healthcheck
- Defined in:
- lib/sunshine/healthcheck.rb
Overview
Healthcheck objects handle enabling and disabling health checking for load balancers by touching health.enabled and health.disabled files on an app’s shell.
If you would like to use Sunshine’s healthcheck rack middleware, use the following command:
sunshine --middleware your_middleware_dir
Then simply specify the following in your config.ru:
require 'your_middleware_dir/health'
use Sunshine::Health
Sunshine::Health supports the following options:
- :uri_path
-
The path that healthcheck will be used on.
- :health_file
-
The file to check for health.
use SunshineHealth, :uri_path => "/health.txt",
:health_file => "health.txt"
Constant Summary collapse
- ENABLED_FILE =
"health.enabled"
- DISABLED_FILE =
"health.disabled"
Instance Attribute Summary collapse
-
#disabled_file ⇒ Object
Returns the value of attribute disabled_file.
-
#enabled_file ⇒ Object
Returns the value of attribute enabled_file.
-
#shell ⇒ Object
Returns the value of attribute shell.
Instance Method Summary collapse
-
#disable ⇒ Object
Disables healthcheck - status: :disabled.
-
#disabled? ⇒ Boolean
Check if healthcheck is disabled.
-
#down? ⇒ Boolean
Check if healthcheck is down.
-
#enable ⇒ Object
Enables healthcheck which should set status to :ok.
-
#enabled? ⇒ Boolean
Check if healthcheck is enabled.
-
#initialize(path, shell) ⇒ Healthcheck
constructor
A new instance of Healthcheck.
-
#remove ⇒ Object
Remove the healthcheck file - status: :down.
-
#status ⇒ Object
Get the health status from the shell.
Constructor Details
#initialize(path, shell) ⇒ Healthcheck
Returns a new instance of Healthcheck.
30 31 32 33 34 |
# File 'lib/sunshine/healthcheck.rb', line 30 def initialize path, shell @shell = shell @enabled_file = File.join path, ENABLED_FILE @disabled_file = File.join path, DISABLED_FILE end |
Instance Attribute Details
#disabled_file ⇒ Object
Returns the value of attribute disabled_file.
28 29 30 |
# File 'lib/sunshine/healthcheck.rb', line 28 def disabled_file @disabled_file end |
#enabled_file ⇒ Object
Returns the value of attribute enabled_file.
28 29 30 |
# File 'lib/sunshine/healthcheck.rb', line 28 def enabled_file @enabled_file end |
#shell ⇒ Object
Returns the value of attribute shell.
28 29 30 |
# File 'lib/sunshine/healthcheck.rb', line 28 def shell @shell end |
Instance Method Details
#disable ⇒ Object
Disables healthcheck - status: :disabled
40 41 42 |
# File 'lib/sunshine/healthcheck.rb', line 40 def disable @shell.call "touch #{@disabled_file} && rm -f #{@enabled_file}" end |
#disabled? ⇒ Boolean
Check if healthcheck is disabled.
48 49 50 |
# File 'lib/sunshine/healthcheck.rb', line 48 def disabled? @shell.file? @disabled_file end |
#down? ⇒ Boolean
Check if healthcheck is down.
56 57 58 |
# File 'lib/sunshine/healthcheck.rb', line 56 def down? !@shell.file?(@disabled_file) && !@shell.file?(@enabled_file) end |
#enable ⇒ Object
Enables healthcheck which should set status to :ok
64 65 66 |
# File 'lib/sunshine/healthcheck.rb', line 64 def enable @shell.call "rm -f #{@disabled_file} && touch #{@enabled_file}" end |
#enabled? ⇒ Boolean
Check if healthcheck is enabled.
72 73 74 |
# File 'lib/sunshine/healthcheck.rb', line 72 def enabled? @shell.file? @enabled_file end |
#remove ⇒ Object
Remove the healthcheck file - status: :down
80 81 82 |
# File 'lib/sunshine/healthcheck.rb', line 80 def remove @shell.call "rm -f #{@disabled_file} #{@enabled_file}" end |
#status ⇒ Object
Get the health status from the shell. Returns one of three states:
:enabled: everything is great
:disabled: healthcheck was explicitely turned off
:down: um, something is wrong
92 93 94 95 96 |
# File 'lib/sunshine/healthcheck.rb', line 92 def status return :disabled if disabled? return :enabled if enabled? :down end |