File: passenger-spawn-server

package info (click to toggle)
passenger 2.2.11debian-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,576 kB
  • ctags: 28,138
  • sloc: cpp: 66,323; ruby: 9,646; ansic: 2,425; python: 141; sh: 56; makefile: 29
file content (68 lines) | stat: -rwxr-xr-x 2,614 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env ruby
#  Phusion Passenger - http://www.modrails.com/
#  Copyright (c) 2008, 2009 Phusion
#
#  "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.

root = File.expand_path("#{File.dirname(__FILE__)}/..")
$LOAD_PATH.unshift("#{root}/lib", "#{root}/ext")
DEFAULT_INPUT_FD = 3

begin
	STDOUT.sync = true
	STDERR.sync = true
	$0 = "Passenger spawn server"
	if GC.respond_to?(:copy_on_write_friendly=)
		GC.copy_on_write_friendly = true
	end
	
	input = IO.new(DEFAULT_INPUT_FD)
	# Optimization for decreasing startup time. Since Apache starts the spawn
	# server twice during startup, we don't want to load the Passenger classes
	# if we don't need them.
	# So we check whether Apache immediately closes the connection. If so,
	# we exit without loading the rest of Passenger. If Apache doesn't close
	# the connection within 4 seconds then we continue with loading Passenger,
	# so that loading doesn't happen during the first spawn.
	begin
		if select([input], nil, nil, 4) && input.eof?
			exit
		end
	rescue Interrupt
		exit
	end
	
	require 'phusion_passenger/utils'
	if defined?(PhusionPassenger::NativeSupport)
		PhusionPassenger::NativeSupport.disable_stdio_buffering
	end
	PhusionPassenger::Utils.passenger_tmpdir = ARGV[0]
	
	require 'phusion_passenger/spawn_manager'
	spawn_manager = PhusionPassenger::SpawnManager.new
	spawn_manager.start_synchronously(input)
	spawn_manager.cleanup
rescue => e
	require 'phusion_passenger/utils'
	include PhusionPassenger::Utils
	print_exception("spawn manager", e)
	exit 10
end