Last active
August 29, 2015 13:58
-
-
Save nkwhr/9952264 to your computer and use it in GitHub Desktop.
a serverspec resource type for checking services running under daemontools.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Serverspec | |
module Type | |
class Supervise < Base | |
def initialize(name) | |
@name = name | |
end | |
def status | |
ret = backend.run_command("svstat /service/#{@name} | awk '{print $2}'") | |
ret[:stdout].chomp | |
end | |
def uptime | |
ret = backend.run_command("svstat /service/#{@name} | grep ': up' | awk '{print $5}'") | |
ret[:stdout].to_i | |
end | |
def log_status | |
ret = backend.run_command("svstat /service/#{@name}/log | awk '{print $2}'") | |
ret[:stdout].chomp | |
end | |
def log_uptime | |
ret = backend.run_command("svstat /service/#{@name}/log | grep ': up' | awk '{print $5}'") | |
ret[:stdout].to_i | |
end | |
end | |
def supervise(name) | |
Supervise.new(name) | |
end | |
end | |
end | |
include Serverspec::Type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'path/to/supervise' | |
describe supervise('sshd') do | |
its(:status) { should eq 'up' } | |
its(:uptime) { should be >= 60 * 60 * 24 * 2 } | |
its(:log_status) { should eq 'up' } | |
its(:log_uptime) { should be >= 60 * 60 * 24 * 2 } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment