Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
[router] Use pidfile utils in vcap_common. Disable thin's signal to a…
Browse files Browse the repository at this point in the history
…void swallowing signals.

Test plan:

- BVT passed
- Unit test passed
- Check the pidfile in bosh env

Change-Id: I0a087b84146c3e3d3f7ba586c04437c645bcad7a
  • Loading branch information
Anfernee Gui committed May 14, 2012
1 parent 8d51f72 commit d7b01b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
20 changes: 14 additions & 6 deletions lib/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require 'router/const'
require 'router/router'
require 'router/router_uls_server'
require 'router/utils'

config_path = ENV["CLOUD_FOUNDRY_CONFIG_PATH"] || File.join(File.dirname(__FILE__), '../config')
config_file = File.join(config_path, 'router.yml')
Expand Down Expand Up @@ -64,8 +63,8 @@

EM.run do

trap("TERM") { stop(config['pid']) }
trap("INT") { stop(config['pid']) }
trap("TERM") { Router.stop() }
trap("INT") { Router.stop() }

Router.config(config)
Router.log.info "Starting VCAP Router (#{Router.version})"
Expand Down Expand Up @@ -93,7 +92,13 @@
EM.set_descriptor_table_size(32768) # Requires Root privileges
Router.log.info "Socket Limit:#{EM.set_descriptor_table_size}"

create_pid_file(config['pid'])
Router.log.info "Pid file: %s" % config['pid']
begin
Router.pid_file = VCAP::PidFile.new(config['pid'])
rescue => e
Router.log.fatal "Can't create router pid file: #{e}"
exit 1
end

NATS.on_error do |e|
if e.kind_of? NATS::ConnectError
Expand All @@ -111,8 +116,11 @@

begin
# TCP/IP Socket
Router.server = Thin::Server.start(inet, port, RouterULSServer) if inet && port
Router.local_server = Thin::Server.start(fn, RouterULSServer) if fn
Router.server = Thin::Server.new(inet, port, RouterULSServer, :signals => false) if inet && port
Router.local_server = Thin::Server.new(fn, RouterULSServer, :signals => false) if fn

Router.server.start if Router.server
Router.local_server.start if Router.local_server
rescue => e
Router.log.fatal "Problem starting server, #{e}"
exit
Expand Down
15 changes: 12 additions & 3 deletions lib/router/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ class Router

class << self
attr_reader :log, :notfound_redirect, :session_key
attr_accessor :server, :local_server, :timestamp, :shutting_down
attr_accessor :server, :local_server, :timestamp, :pid_file
attr_accessor :inet, :port

alias :shutting_down? :shutting_down

def version
VERSION
end

def stop
log.info 'Signal caught, shutting down..'

server.stop if server
local_server.stop if local_server

NATS.stop { EM.stop }
pid_file.unlink()
log.info 'Bye'
end

def config(config)
@droplets = {}
VCAP::Logging.setup_from_config(config['logging'] || {})
Expand Down
29 changes: 0 additions & 29 deletions lib/router/utils.rb

This file was deleted.

0 comments on commit d7b01b3

Please sign in to comment.