Class: Updater::Setup
- Inherits:
-
Object
- Object
- Updater::Setup
- Defined in:
- lib/updater/setup.rb
Constant Summary collapse
- ROOT =
File.dirname(self.config_file || Dir.pwd)
Class Attribute Summary collapse
-
.init ⇒ Object
Returns the value of attribute init.
Class Method Summary collapse
-
.client_setup(options = {}) ⇒ Object
Connect a client to a server.
-
.config_file(options = {}) ⇒ Object
Retruns tha locaion of the config file.
-
.monitor ⇒ Object
pendeing.
-
.noop(options = {}) ⇒ Object
Used for testing.
-
.start(options = {}) ⇒ Object
start a new server.
-
.stop(options = {}) ⇒ Object
stop the server.
- .test_setup(options = {}) ⇒ Object
Instance Method Summary collapse
-
#client_setup(init = true) ⇒ Object
The client is responcible for loading classes and making connections.
-
#initialize(file_or_hash, extended = {}) ⇒ Setup
constructor
extended used for clients who want to override parameters.
- #noop ⇒ Object
- #socket_for_client ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #test_setup ⇒ Object
Constructor Details
#initialize(file_or_hash, extended = {}) ⇒ Setup
extended used for clients who want to override parameters
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/updater/setup.rb', line 55 def initialize(file_or_hash, extended = {}) @options = file_or_hash.kind_of?(Hash) ? file_or_hash : load_file(file_or_hash) @options.merge!(extended) @options[:pid_file] ||= File.join(ROOT,'updater.pid') @options[:host] ||= "localhost" @logger = @options[:logger] || Logger.new(@options[:log_file] || STDOUT) level = Logger::SEV_LABEL.index(@options[:log_level].upcase) if @options[:log_level] @logger.level = level || Logger::WARN unless @options[:logger] #only set this if we were not handed a logger @logger.debug "Debugging output enabled" unless @options[:logger] Update.logger = @logger end |
Class Attribute Details
.init ⇒ Object
Returns the value of attribute init.
9 10 11 |
# File 'lib/updater/setup.rb', line 9 def init @init end |
Class Method Details
.client_setup(options = {}) ⇒ Object
Connect a client to a server
27 28 29 |
# File 'lib/updater/setup.rb', line 27 def client_setup( = {}) new(config_file(), ).client_setup end |
.config_file(options = {}) ⇒ Object
Retruns tha locaion of the config file.
41 42 43 44 45 46 47 48 49 |
# File 'lib/updater/setup.rb', line 41 def config_file( = {}) if [:config_file] && File.exists?([:config_file]) [:config_file] elsif ENV['UPDATE_CONFIG'] && File.exists(ENV['UPDATE_CONFIG']) ENV['UPDATE_CONFIG'] else (Dir.glob('{config,.}/updater.config') + Dir.glob('.updater')).first end end |
.monitor ⇒ Object
pendeing
36 37 38 |
# File 'lib/updater/setup.rb', line 36 def monitor end |
.noop(options = {}) ⇒ Object
Used for testing. Will run through the entire setup process, but not actually start the server, but will log the resulting options.
22 23 24 |
# File 'lib/updater/setup.rb', line 22 def noop(={}) new(config_file(), ).noop end |
.start(options = {}) ⇒ Object
start a new server
11 12 13 |
# File 'lib/updater/setup.rb', line 11 def start(={}) new(config_file(), ).start end |
.stop(options = {}) ⇒ Object
stop the server
16 17 18 |
# File 'lib/updater/setup.rb', line 16 def stop(={}) new(config_file(), ).stop end |
.test_setup(options = {}) ⇒ Object
31 32 33 |
# File 'lib/updater/setup.rb', line 31 def test_setup( = {}) new().test_setup end |
Instance Method Details
#client_setup(init = true) ⇒ Object
The client is responcible for loading classes and making connections. We will simply setup the Updater spesifics.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/updater/setup.rb', line 91 def client_setup(init = true) @logger.info "Updater Client is being initialized... (#{__FILE__}:#{__LINE__})" @logger.debug " Call Stack:\n - #{caller[0..3].join("\n - ")}" set_orm Updater::Update.socket = socket_for_client init_orm if init #set PID if File.exists? @options[:pid_file] Updater::Update.pid = File.read(@options[:pid_file]).strip end Updater::Update.config_file = @config_file self end |
#noop ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/updater/setup.rb', line 80 def noop @logger.warn "NOOP: will not start service" set_orm init_orm load_models client_setup @logger.debug @options.inspect exit end |
#socket_for_client ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/updater/setup.rb', line 119 def socket_for_client if @options[:socket] && File.exists?(@options[:socket]) @logger.debug "Using UNIX Socket \"#{@options[:socket]}\"" return UNIXSocket.new(@options[:socket]) if File.exists?(@options[:socket]) && File.stat(@options[:socket]).socket? end if @options[:udp] socket = UDPSocket.new() socket.connect(@options[:host],@options[:udp]) begin socket.write '.' #must test UDP sockets return socket rescue Errno::ECONNREFUSED end end if @options[:tcp] begin return TCPSocket.new(@options[:host],@options[:tcp]) rescue Errno::ECONNREFUSED end end if @options[:remote] return nil raise NotImplimentedError #For future Authenticated Http Rest Server end return nil end |
#start ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/updater/setup.rb', line 67 def start pid = Process.fork do _start end @logger.warn "Successfully started Master Loop at pid #{pid}" puts "Job Queue Processor Started at PID: #{pid}" end |
#stop ⇒ Object
75 76 77 78 |
# File 'lib/updater/setup.rb', line 75 def stop Process.kill("TERM",File.read(@options[:pid_file]).to_i) sleep 1.0 end |