#!/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' require 'jerbil/servers' require 'jerbil/version' require 'jerbil/config' require 'jerbil/support' require 'optparse' # force quiet to suppress client output regardless of whether verbose is selected options = Hash.new verbose = false config_file = nil env = :null quiet = nil OptionParser.new do |opts| opts.banner = "Usage: jerbil-status [opts]" opts.separator "" opts.separator " stop the given Jerbil Service" opts.separator "" opts.on("-n", "--no-daemon", "Do not daemonize") 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 to find Jerbil" ) do |cfile| if FileTest.readable?(cfile) then options = Jerbil.get_config(cfile) else puts "Config file cannot be read." exit 1 end end opts.on("-e", "--environment [TYPE]", [:prod, :test, :dev], "Select env (prod, test, dev), default is prod") do |e| env = e end opts.on("-V", "--verbose", "output more information about what is going on ") do verbose = true 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! puts "Check status of the local Jerbil Server" if verbose #puts "Version: jerbil-" + Jerbil::Version + " [#{Jerbil::Version_Date}]" if verbose #options = Jerbil::Config.new(config_file) #servers = options[:servers] #server_env = nil if env != :null then server_env = env else server_env = options[:environment] || :prod end puts "Running with environment: #{server_env}" if verbose local = Jerbil::Servers.get_local_server(server_env) if local.nil? then puts "Cannot find record for a local Jerbil Server" if verbose exit 1 end puts "Found local Jerbil Server record" if verbose begin jerbild = local.connect # see if you can verify? jerbild.verify if verbose then puts "Jerbil Server is running" puts " started on #{jerbild.started.strftime('%d-%m-%y %H:%M')}" end exit 0 rescue DRb::DRbConnError, Jerbil::ServerConnectError #fall back to pid killing puts "Failed to connect to the Jerbil Server" if verbose exit 1 end