#!/usr/bin/env ruby # # # = Jerbil Service Start # # == starts 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 # # # require 'rubygems' require 'jerbil/jerbil_service/sclient' require 'jerbil/jerbil_service/utils' require 'optparse' config_file = nil # let it be the default daemonize = true log_to_syslog = true verbose = true quiet = false my_service = nil log_daemon = false OptionParser.new do |opts| opts.banner = "Usage: jservice [opts] -s " opts.separator "" opts.separator " start the jerbil service with the given " opts.separator "" opts.on("-s", "--service [name]", String, "start 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", "Log daemon output") do log_daemon = true 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 for the service" ) do |cfile| if FileTest.readable?(cfile) then 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 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! verbose = false if quiet puts "Ready to start. Looking for class" if verbose unless my_service puts "Error: You must name a service (-s name)" exit 1 else service_name = JerbilService::Utils.classify(my_service) puts "Requiring modules for: #{service_name}" if verbose require "#{my_service}" require "#{my_service}/config" require "#{my_service}/version" puts "Required modules" if verbose the_service = Module.const_get(service_name) puts "Obtained module name: #{the_service}" if verbose end puts "Starting the Supervisor" if verbose JerbilService::Supervisor.new(the_service) do |jservice| jservice.no_daemon unless daemonize jservice.quiet if quiet jservice.verbose if verbose jservice.log_daemon if log_daemon jservice.no_syslog unless log_to_syslog jservice.config_file = config_file end puts "Everything should be working now" if verbose