Class: StompServer::Run
- Inherits:
-
Object
- Object
- StompServer::Run
- Defined in:
- lib/stomp_server.rb
Instance Attribute Summary collapse
-
#auth_required ⇒ Object
Returns the value of attribute auth_required.
-
#queue_manager ⇒ Object
Returns the value of attribute queue_manager.
-
#stompauth ⇒ Object
Returns the value of attribute stompauth.
-
#topic_manager ⇒ Object
Returns the value of attribute topic_manager.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Run
constructor
A new instance of Run.
- #start ⇒ Object
- #stop(pidfile) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Run
Returns a new instance of Run.
83 84 85 86 87 88 89 |
# File 'lib/stomp_server.rb', line 83 def initialize(opts) @opts = opts @queue_manager = nil @auth_required = nil @stompauth = nil @topic_manager = nil end |
Instance Attribute Details
#auth_required ⇒ Object
Returns the value of attribute auth_required.
81 82 83 |
# File 'lib/stomp_server.rb', line 81 def auth_required @auth_required end |
#queue_manager ⇒ Object
Returns the value of attribute queue_manager.
81 82 83 |
# File 'lib/stomp_server.rb', line 81 def queue_manager @queue_manager end |
#stompauth ⇒ Object
Returns the value of attribute stompauth.
81 82 83 |
# File 'lib/stomp_server.rb', line 81 def stompauth @stompauth end |
#topic_manager ⇒ Object
Returns the value of attribute topic_manager.
81 82 83 |
# File 'lib/stomp_server.rb', line 81 def topic_manager @topic_manager end |
Instance Method Details
#start ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 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 145 146 147 148 |
# File 'lib/stomp_server.rb', line 98 def start begin if @opts[:group] puts "Changing group to #{@opts[:group]}." Process::GID.change_privilege(Etc.getgrnam(@opts[:group]).gid) end if @opts[:user] puts "Changing user to #{@opts[:user]}." Process::UID.change_privilege(Etc.getpwnam(@opts[:user]).uid) end rescue Errno::EPERM puts "FAILED to change user:group #{@opts[:user]}:#{@opts[:group]}: #$!" exit 1 end Dir.mkdir(@opts[:working_dir]) unless File.directory?(@opts[:working_dir]) Dir.mkdir(@opts[:logdir]) unless File.directory?(@opts[:logdir]) Dir.mkdir(@opts[:etcdir]) unless File.directory?(@opts[:etcdir]) if @opts[:daemon] Daemonize.daemonize(log_file=@opts[:logfile]) # change back to the original starting directory Dir.chdir(@opts[:working_dir]) end # Write pidfile open(@opts[:pidfile],"w") {|f| f.write(Process.pid) } if @opts[:queue] == 'dbm' qstore=StompServer::DBMQueue.new(@opts[:storage]) elsif @opts[:queue] == 'file' qstore=StompServer::FileQueue.new(@opts[:storage]) elsif @opts[:queue] == 'activerecord' require 'stomp_server/queue/activerecord_queue' qstore=StompServer::ActiveRecordQueue.new(@opts[:etcdir], @opts[:storage]) else qstore=StompServer::MemoryQueue.new end qstore.checkpoint_interval = @opts[:checkpoint] puts "Checkpoing interval is #{qstore.checkpoint_interval}" if $DEBUG @topic_manager = StompServer::TopicManager.new @queue_manager = StompServer::QueueManager.new(qstore) @auth_required = @opts[:auth] if @auth_required @stompauth = StompServer::StompAuth.new(@opts[:passwd]) end trap("INT") { puts "INT signal received.";stop(@opts[:pidfile]) } end |
#stop(pidfile) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/stomp_server.rb', line 91 def stop(pidfile) @queue_manager.stop puts "Stompserver shutting down" if $DEBUG EventMachine::stop_event_loop File.delete(pidfile) end |