Method: StompServer::Run#start
- Defined in:
- lib/stomp_server_ng.rb
#start ⇒ Object
Startup
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/stomp_server_ng.rb', line 375 def start @@log.debug("#{self.class}.start begins") # Handle group priviliges! # N.B.: Handle these options from the command line ????????? begin if @opts[:group] @@log.debug "Changing group to #{@opts[:group]}." Process::GID.change_privilege(Etc.getgrnam(@opts[:group]).gid) end if @opts[:user] @@log.debug "Changing user to #{@opts[:user]}." Process::UID.change_privilege(Etc.getpwnam(@opts[:user]).uid) end rescue Errno::EPERM @@log.error "FAILED to change user:group #{@opts[:user]}:#{@opts[:group]}: #$!" exit 1 end # Make required directories unless they already exist 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]) # Determine qstore type if @opts[:queue] == 'dbm' qstore=StompServer::DBMQueue.new(@opts[:storage]) @@log.debug "Queue storage is DBM" elsif @opts[:queue] == 'file' qstore=StompServer::FileQueue.new(@opts[:storage]) @@log.debug "Queue storage is FILE" elsif @opts[:queue] == 'activerecord' require 'stomp_server_ng/queue/activerecord_queue' qstore=StompServer::ActiveRecordQueue.new(@opts[:etcdir], @opts[:storage], @opts[:dbyml]) @@log.debug "Queue storage is ActiveRecord" else qstore=StompServer::MemoryQueue.new @@log.debug "Queue storage is MEMORY" end # Set checkpoint interval qstore.checkpoint_interval = @opts[:checkpoint] @@log.debug "Checkpoint interval is #{qstore.checkpoint_interval}" if $DEBUG # @topic_manager = StompServer::TopicManager.new @queue_manager = StompServer::QueueManager.new(qstore) @@log.debug("Managers are initialized.") @@log.debug("Topic Manager: #{@topic_manager}") @@log.debug("Queue Manager: #{@queue_manager}") # Authorization: requirement @auth_required = @opts[:auth] if @auth_required @stompauth = StompServer::StompAuth.new(@opts[:passwd]) end # Initialize session ID cache if @opts[:session_cache] > 0 StompServer::SessionIDManager.initialize_cache(@opts[:session_cache]) StompServer::SessionIDManager.dump_cache(@@log); end # If we are going to daemonize, it should be almost the last # thing we do here. @@log.debug("#{self.class}.start Daemonize: #{@opts[:daemon]}") if @opts[:daemon] @@log.debug("#{self.class}.start going to background") @@log.debug("#{self.class}.start check #{@opts[:logfile]}") StompServer::LogHelper.showversion(@@log) STDOUT.flush # clear the decks Daemonize.daemonize(log_file=@opts[:logfile]) # change back to the original starting directory Dir.chdir(@opts[:working_dir]) end # But write pidfile only after possible daemonization curr_pid = Process.pid open(@opts[:pidfile],"w") {|f| f.write(curr_pid) } @@log.debug("Pid File Contents: #{curr_pid}") # OK, log and set the SIGINT signal handler. @@log.debug("#{self.class}.start setting trap at completion") StompServer::LogHelper.showversion(@@log) # one more time at startup # Show Load Path StompServer::LogHelper.showloadpath(@@log) StompServer::LogHelper.(@@log, @opts) # Dump runtime options trap("INT") { @@log.debug "INT signal received.";stop(@opts[:pidfile]) } trap("TERM") { @@log.debug "TERM signal received.";stop(@opts[:pidfile]) } end |