/usr/lib/ruby/1.8/stomp_server.rb is in stompserver 0.9.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 149 150 | require 'eventmachine'
require 'stomp_server/stomp_frame'
require 'stomp_server/stomp_id'
require 'stomp_server/stomp_auth'
require 'stomp_server/topic_manager'
require 'stomp_server/queue_manager'
require 'stomp_server/queue'
require 'stomp_server/queue/memory_queue'
require 'stomp_server/queue/file_queue'
require 'stomp_server/queue/dbm_queue'
require 'stomp_server/protocols/stomp'
module StompServer
VERSION = '0.9.9'
class Configurator
attr_accessor :opts
def initialize
@opts = nil
@defaults = {
:port => 61613,
:host => "127.0.0.1",
:debug => false,
:queue => 'memory',
:auth => false,
:working_dir => Dir.getwd,
:storage => ".stompserver",
:logdir => 'log',
:etcdir => 'etc',
:configfile => 'stompserver.conf',
:logfile => 'stompserver.log',
:pidfile => 'stompserver.pid',
:checkpoint => 0
}
@opts = getopts
if opts[:debug]
$DEBUG=true
end
end
def getopts
copts = OptionParser.new
copts.on("-C", "--config=CONFIGFILE", String, "Configuration File (default: stompserver.conf)") {|c| @defaults[:configfile] = c}
copts.on("-p", "--port=PORT", Integer, "Change the port (default: 61613)") {|p| @defaults[:port] = p}
copts.on("-b", "--host=ADDR", String, "Change the host (default: localhost)") {|a| @defaults[:host] = a}
copts.on("-q", "--queuetype=QUEUETYPE", String, "Queue type (memory|dbm|activerecord|file) (default: memory)") {|q| @defaults[:queue] = q}
copts.on("-w", "--working_dir=DIR", String, "Change the working directory (default: current directory)") {|s| @defaults[:working_dir] = s}
copts.on("-s", "--storage=DIR", String, "Change the storage directory (default: .stompserver, relative to working_dir)") {|s| @defaults[:storage] = s}
copts.on("-d", "--debug", String, "Turn on debug messages") {|d| @defaults[:debug] = true}
copts.on("-a", "--auth", String, "Require client authorization") {|a| @defaults[:auth] = true}
copts.on("-c", "--checkpoint=SECONDS", Integer, "Time between checkpointing the queues in seconds (default: 0)") {|c| @defaults[:checkpoint] = c}
copts.on("-h", "--help", "Show this message") do
puts copts
exit
end
puts copts.parse(ARGV)
if File.exists?(@defaults[:configfile])
opts = @defaults.merge(YAML.load_file(@defaults[:configfile]))
else
opts = @defaults
end
opts[:etcdir] = opts[:etcdir] =~ /^\// ? opts[:etcdir] : File.join(opts[:working_dir],opts[:etcdir])
opts[:storage] = opts[:storage] =~ /^\// ? opts[:storage] : File.join(opts[:working_dir],opts[:storage])
opts[:logdir] = opts[:logdir] =~ /^\// ? opts[:logdir] : File.join(opts[:working_dir],opts[:logdir])
opts[:logfile] = opts[:logfile] =~ /^\// ? opts[:logfile] : File.join(opts[:logdir],opts[:logfile])
opts[:pidfile] = opts[:pidfile] =~ /^\// ? opts[:pidfile] : File.join(opts[:logdir],opts[:pidfile])
if opts[:auth]
opts[:passwd] = File.join(opts[:etcdir],'.passwd')
end
return opts
end
end
class Run
attr_accessor :queue_manager, :auth_required, :stompauth, :topic_manager
def initialize(opts)
@opts = opts
@queue_manager = nil
@auth_required = nil
@stompauth = nil
@topic_manager = nil
end
def stop(pidfile)
@queue_manager.stop
puts "Stompserver shutting down" if $DEBUG
EventMachine::stop_event_loop
File.delete(pidfile)
end
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
end
end
|