spider-gazelle 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06ce9d0c2e12d8dda15fd597dbba9026d8848520
4
- data.tar.gz: 3c649fbf8734a3f73e50073d3cf83efdc590e2a6
3
+ metadata.gz: 637abdac912362192fa95d5ac953e859c856c0b6
4
+ data.tar.gz: 0c56ae0b98de48a37cb2b66c55d9e42d1085454d
5
5
  SHA512:
6
- metadata.gz: 438f525a31e89401f9c86dd57c50a97c3a558eca28e04dc82e1173cd9af801e3de899282f55a387fccbc2ff2d13b0da5ca74645320edc8fc2a0c4fb7b0756d32
7
- data.tar.gz: 4a52edec124cb480ab4c51a9c584923529045f51007ee3213ef58a77669896ef51569d461ffd9d8e12e10148106fb80305bd4f8395e65d2a908771cfef5f88dd
6
+ metadata.gz: 658c6babb2b9f7e46ca956d966bf661ac8eed64867c04e6e3f63482f612d58b18284a9a1ae7d1eb1fa776badba5775adbbba3deb6d791d1466b72bbf8a99522f
7
+ data.tar.gz: 1af8beea242d2137379dd96547d14acea49e937a941f1be6f506fc6691afb992fdd71a465ff35bd88a8ea8043c9219e4230d5063b1d3773e77f99d9e7c2203c5
data/bin/sg CHANGED
@@ -34,10 +34,14 @@ parser = OptionParser.new do |opts|
34
34
  options[:rackup] = arg
35
35
  end
36
36
 
37
- opts.on "-l", "--logfile FILE", "Location of the servers log file (default: logs/server.log)" do |arg|
37
+ opts.on "-l", "--log FILE", "Location of the servers log file (default: logs/server.log)" do |arg|
38
38
  ENV['SG_LOG'] = arg
39
39
  end
40
40
 
41
+ opts.on "-P", "--pid FILE", "Location of the servers pid file (default: tmp/pids/sg-PORT.pid)" do |arg|
42
+ ENV['SG_PID'] = arg
43
+ end
44
+
41
45
  opts.on "-m", "--mode MODE", "Either thread, process or no_ipc (default: thread)" do |arg|
42
46
  ENV['SG_MODE'] = arg
43
47
  end
@@ -7,6 +7,8 @@ require "spider-gazelle/request" # Holds request information and handles
7
7
  require "spider-gazelle/connection" # Holds connection information and handles request pipelining
8
8
  require "spider-gazelle/gazelle" # Processes data received from connections
9
9
 
10
+ require "spider-gazelle/management/process" # Processes data received from connections
11
+
10
12
  require "spider-gazelle/app_store" # Holds references to the loaded rack applications
11
13
  require "spider-gazelle/binding" # Holds a reference to a bound port and associated rack application
12
14
  require "spider-gazelle/spider" # Accepts connections and offloads them to gazelles
@@ -27,7 +27,7 @@ module SpiderGazelle
27
27
  # REMOTE_USER, or REMOTE_HOST parameters since those are either a security problem or
28
28
  # too taxing on performance.
29
29
  module Const
30
- SPIDER_GAZELLE_VERSION = VERSION = "1.0.1".freeze
30
+ SPIDER_GAZELLE_VERSION = VERSION = "1.0.2".freeze
31
31
  # CODE_NAME = "Earl of Sandwich Partition"
32
32
  SERVER = "SpiderGazelle".freeze
33
33
 
@@ -0,0 +1,90 @@
1
+
2
+ if ::FFI::Platform.windows?
3
+ begin
4
+ require 'win32/process'
5
+ rescue LoadError
6
+ puts "Warning: The win32-process gem is required for PID file use on Windows. Install the gem (in your Gemfile if using bundler) to avoid errors."
7
+ end
8
+ end
9
+
10
+ module SpiderGazelle
11
+ class PidFileExists < RuntimeError; end
12
+
13
+ module Management
14
+ class Pid
15
+ def initialize(path)
16
+ @pid_file = path
17
+
18
+ remove_stale_pid_file
19
+ write_pid_file
20
+
21
+ # At application exit remove the file
22
+ # unless of course we do not own the file
23
+ cur = ::Process.pid
24
+ at_exit do
25
+ if cur == current
26
+ remove_pid_file
27
+ end
28
+ end
29
+ end
30
+
31
+ def current
32
+ File.exist?(@pid_file) ? open(@pid_file).read.to_i : nil
33
+ end
34
+
35
+ def running?(pid)
36
+ if ::FFI::Platform.windows?
37
+ begin
38
+ # Returns exit code or nil if still running
39
+ if ::Process.respond_to? :get_exitcode
40
+ return ::Process.get_exitcode(pid).nil?
41
+ else
42
+ # win32/process not loaded
43
+ return false
44
+ end
45
+ rescue
46
+ # PID probably doesn't exist
47
+ false
48
+ end
49
+ else
50
+ begin
51
+ ::Process.getpgid(pid) != -1
52
+ rescue ::Errno::EPERM
53
+ # Operation not permitted
54
+ true
55
+ rescue ::Errno::ESRCH
56
+ # No such process
57
+ false
58
+ end
59
+ end
60
+ end
61
+
62
+ protected
63
+
64
+
65
+ def remove_stale_pid_file
66
+ if File.exist?(@pid_file)
67
+ pid = current
68
+
69
+ if pid && running?(pid)
70
+ raise PidFileExists, "#{@pid_file} already exists, seems like it's already running (process ID: #{pid}). " +
71
+ "Stop the process or delete #{@pid_file}."
72
+ else
73
+ remove_pid_file
74
+ end
75
+ end
76
+ end
77
+
78
+ def write_pid_file
79
+ File.open(@pid_file, 'w') do |f|
80
+ f.write ::Process.pid
81
+ end
82
+ File.chmod(0644, @pid_file)
83
+ end
84
+
85
+ def remove_pid_file
86
+ File.delete(@pid_file) if @pid_file && File.exists?(@pid_file)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -70,12 +70,18 @@ module SpiderGazelle
70
70
  @delegate = method(no_ipc? ? :direct_delegate : :delegate)
71
71
  @squash = method(:squash)
72
72
 
73
- # FIXME The expanded path path seems a bit risky
74
- log_path = ENV['SG_LOG'] || File.expand_path('../../../logs/server.log', __FILE__)
73
+ log_path = ENV['SG_LOG'] || File.expand_path('log/sg.log', Dir.pwd)
75
74
  dirname = File.dirname(log_path)
76
75
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
77
76
  @logger = ::Logger.new(log_path.to_s, 10, 4194304)
78
77
 
78
+ # Create the PID file
79
+ pid_path = ENV['SG_PID'] || File.expand_path('tmp/pids/sg.pid', Dir.pwd)
80
+ dirname = File.dirname(pid_path)
81
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
82
+ @pid = Management::Pid.new(pid_path)
83
+
84
+
79
85
  # Keep track of the loading process
80
86
  @waiting_gazelle = 0
81
87
  @gazelle_count = 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spider-gazelle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -155,6 +155,7 @@ files:
155
155
  - lib/spider-gazelle/connection.rb
156
156
  - lib/spider-gazelle/const.rb
157
157
  - lib/spider-gazelle/gazelle.rb
158
+ - lib/spider-gazelle/management/process.rb
158
159
  - lib/spider-gazelle/request.rb
159
160
  - lib/spider-gazelle/spider.rb
160
161
  - lib/spider-gazelle/upgrades/websocket.rb
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  version: '0'
186
187
  requirements: []
187
188
  rubyforge_project:
188
- rubygems_version: 2.1.11
189
+ rubygems_version: 2.0.14
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: A fast, parallel and concurrent web server for ruby