Skip to content

Instantly share code, notes, and snippets.

@nkwhr
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkwhr/9952264 to your computer and use it in GitHub Desktop.
Save nkwhr/9952264 to your computer and use it in GitHub Desktop.
a serverspec resource type for checking services running under daemontools.
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
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