#!/usr/bin/env ruby # # # = Jerbil Service Stop # # == stops a jerbil service # # Author:: Robert Sharp # Copyright:: Copyright (c) 2012 Robert Sharp # License:: Open Software Licence v3.0 # # This software is licensed for use under the Open Software Licence v. 3.0 # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php # and in the file copyright.txt. Under the terms of this licence, all derivative works # must themselves be licensed under the Open Software Licence v. 3.0 # # This script should be used to stop a jerbil service, typically through the jerbil init script. # require 'rubygems' require 'jerbil/jerbil_service/client' require 'jerbil/jerbil_service/utils' require 'jerbil/errors' require 'optparse' # force quiet to suppress client output regardless of whether verbose is selected client_opts = {:local=>true, :quiet=>true} verbose = false my_service = nil quiet = false OptionParser.new do |opts| opts.banner = "Usage: service-status [opts]" opts.separator "" opts.separator " stop the given Jerbil Service" opts.separator "" opts.on("-s", "--service [name]", String, "check the given service") do |name| my_service = name end opts.on("-n", "--no-daemon", "Do not daemonize") do daemonize = false end opts.on("-l", "--log-daemon", "ignored") do daemonize = false end opts.on("-S", "--no-syslog", "Do not log to syslog") do log_to_syslog = false end opts.on("-c", "--config [file]", String, "use this config file instead of the default" ) do |cfile| if FileTest.readable?(cfile) then client_opts[:config_file] = cfile else puts "Config file cannot be read." exit 1 end end opts.on("-V", "--verbose", "output more information about what is going on ") do verbose = true client_opts[:quiet] = false end opts.on("-q", "--quiet", "output nothing") do quiet = true end opts.on("-h", "--help", "Provide Help") do |h| opts.separator "" puts opts exit 0 end end.parse! unless my_service puts "Error: You must provide a service (-s name)" exit 1 else service_name = JerbilService::Utils.classify(my_service) puts "Checking status for #{service_name}" unless quiet require "#{my_service}" require "#{my_service}/config" require "#{my_service}/version" the_service = Module.const_get(service_name) end running = false begin JerbilService::Client.connect(the_service, client_opts) do |jservice| running = jservice.verify end rescue Jerbil::ServiceNotFound running = false end if verbose then puts running ? "Service #{service_name} is running" : "Service #{service_name} is not running" end running ? exit(0) : exit(1)