gemirro 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gemirro might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 88720262f04cf437d78990d801473153965d7ee8
4
- data.tar.gz: 5d05de8d3fdb9b9cc07c69b4483a7263e9eb8690
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTE2OTU0OTYxMmU0Y2JkZjBlZTQxMWRiZDQ4MWZkNzVlZDAyZWRlZQ==
5
+ data.tar.gz: !binary |-
6
+ NDk1ZDFlYWYxYmE1NjY1MmNiNzUxYzRjZjA0N2Q2MzI1YjNlZDEyZg==
5
7
  SHA512:
6
- metadata.gz: 61fd8692d6885444ea4505c698b6d7420910a0b8ed9c7315d6e87b6c94b1ed8b3fee10358cfe6cde6c6a97d734f105aad9b9b0e5373810b7af21a69c8f0fb0e7
7
- data.tar.gz: d614a2c7de6b2ef408afc0194ce48c039831edf36037c8c60b297b5b39d9fea2d75ff99d99c1fac3b9928d4ec32e75e5478eb202e8179fcbcba4a85d05daa347
8
+ metadata.gz: !binary |-
9
+ MTQ0MWI1ODQ4NWVhODA0ZTlmMzMzZDU3N2ViNDM4MmY0ODViN2EyZmEzNjBl
10
+ ZDNhNDQ4NjIwYTU5OWJlMTM4MzY4OWZmODg0MmY2NDUxOThmZTY4NGZhMzZm
11
+ MmZiYzBlNzI5NzcxMzIxMTdkOGIwNzA2ZmJjYmFlZWM5NjAzMzU=
12
+ data.tar.gz: !binary |-
13
+ MDhkOTcyMTk5NDIyMzI5MzA0YTM1ODAxNmIzMDliZWMzMWY2ZWY4YjdmZTQw
14
+ YjJhZWM4NjU2YmU3MGJhOWZlMTk4NDE2YzYwM2UyMTg1YWRmMDU5NjZjN2Iw
15
+ ZTQ0MWEwNjA4OTI4NjEwN2YwNTY1ZDU3OTFkMjk0ODQ1ZmMyZjY=
data/README.md CHANGED
@@ -43,11 +43,14 @@ Once all the Gems have been downloaded you'll need to generate an index of all t
43
43
  $ gemirro index
44
44
  ```
45
45
 
46
-
47
- Last, launch the `TCPServer`, and all requests will check if gems are detected, and download them if necessary and generate index immediately.
46
+ Last, launch the server, and all requests will check if gems are detected, and download them if necessary and generate index immediately.
48
47
 
49
48
  ```bash
50
- $ gemirro server
49
+ $ gemirro server --start
50
+ $ gemirro server --status
51
+ $ gemirro server --restart
52
+ $ gemirro server --stop
53
+
51
54
  ```
52
55
 
53
56
  If you want to use a custom configuration file not located in the current directory, use the `-c` or `--config` option.
data/gemirro.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'thin', '~>1.6'
26
26
 
27
27
  s.add_development_dependency 'rake', '~>10.0'
28
+ s.add_development_dependency 'rack-test', '~>0.6'
28
29
  s.add_development_dependency 'rspec', '~>3.0'
29
30
  s.add_development_dependency 'simplecov', '~>0.9'
30
31
  s.add_development_dependency 'rubocop', '~>0.25'
@@ -1,12 +1,26 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  Gemirro::CLI.options.command 'server' do
3
4
  banner 'Usage: gemirro server [OPTIONS]'
4
- description 'Run web server'
5
+ description 'Manage web server'
5
6
  separator "\nOptions:\n"
6
7
 
8
+ on :start, 'Run web server'
9
+ on :stop, 'Stop web server'
10
+ on :restart, 'Restart web server'
11
+ on :status, 'Status of web server'
7
12
  on :c=, :config=, 'Path to the configuration file'
13
+ @pid_file = nil
8
14
 
9
15
  run do |opts, _args|
16
+ load_configuration(opts)
17
+ start if opts[:start]
18
+ stop if opts[:stop]
19
+ restart if opts[:restart]
20
+ status if opts[:status]
21
+ end
22
+
23
+ def load_configuration(opts)
10
24
  Gemirro::CLI.load_configuration(opts[:c])
11
25
  config = Gemirro.configuration
12
26
  unless File.directory?(config.destination)
@@ -14,7 +28,87 @@ Gemirro::CLI.options.command 'server' do
14
28
  abort
15
29
  end
16
30
 
31
+ @pid_file = File.join(config.destination, '..', 'gemirro.pid')
17
32
  require 'gemirro/server'
33
+ end
34
+
35
+ # Copy stdout because we'll need to reopen it later on
36
+ @orig_stdout = STDOUT.clone
37
+ $PROGRAM_NAME = 'gemirro'
38
+
39
+ def create_pid
40
+ File.open(@pid_file, 'w') do |f|
41
+ f.write("#{Process.pid}")
42
+ end
43
+ rescue Errno::EACCES
44
+ STDOUT.reopen @orig_stdout
45
+ puts "Error: Can't write to #{@pid_file} - Permission denied"
46
+ exit!
47
+ end
48
+
49
+ def destroy_pid
50
+ File.delete(@pid_file) if File.exist?(@pid_file) && pid == Process.pid
51
+ end
52
+
53
+ def pid
54
+ File.open(@pid_file, 'r') do |f|
55
+ return f.gets.to_i
56
+ end
57
+ rescue Errno::ENOENT
58
+ puts "Error: PID File not found #{@pid_file}"
59
+ exit!
60
+ end
61
+
62
+ def start
63
+ puts 'Starting...'
64
+ if File.exist?(@pid_file)
65
+ if running?(pid)
66
+ puts "Error: #{$PROGRAM_NAME} already running"
67
+ abort
68
+ end
69
+ end
70
+
71
+ Process.daemon
72
+ create_pid
73
+ STDOUT.reopen @orig_stdout
74
+ puts "done! (PID is #{pid})\n"
18
75
  Gemirro::Server.run!
76
+ destroy_pid
77
+ STDOUT.reopen '/dev/null', 'a'
78
+ end
79
+
80
+ def stop
81
+ process_pid = pid
82
+ begin
83
+ Process.kill('TERM', process_pid)
84
+ Timeout.timeout(30) { sleep 0.1 while running?(process_pid) }
85
+ rescue Errno::ESRCH
86
+ puts "Error: Couldn't find process with PID #{process_pid}"
87
+ exit!
88
+ rescue Timeout::Error
89
+ puts 'timeout while sending TERM signal, sending KILL signal now... '
90
+ Process.kill('KILL', process_pid)
91
+ destroy_pid
92
+ end
93
+ puts 'done!'
94
+ end
95
+
96
+ def restart
97
+ stop
98
+ start
99
+ end
100
+
101
+ def status
102
+ if running?(pid)
103
+ puts "#{$PROGRAM_NAME} is running"
104
+ else
105
+ puts "#{$PROGRAM_NAME} is not running"
106
+ end
107
+ end
108
+
109
+ def running?(process_id)
110
+ Process.getpgid(process_id) != -1
111
+ rescue Errno::ESRCH
112
+ false
19
113
  end
20
114
  end
@@ -4,18 +4,16 @@ require 'thin'
4
4
 
5
5
  module Gemirro
6
6
  ##
7
- # Launch TCPServer to easily download gems.
7
+ # Launch Sinatra server to easily download gems.
8
8
  #
9
- # @!attribute [r] server
10
- # @return [TCPServer]
11
- # @!attribute [r] destination
12
- # @return [String]
13
9
  # @!attribute [r] versions_fetcher
14
10
  # @return [VersionsFetcher]
15
11
  # @!attribute [r] gems_fetcher
16
12
  # @return [Gemirro::GemsFetcher]
17
13
  #
18
14
  class Server < Sinatra::Base
15
+ attr_accessor :versions_fetcher, :gems_fetcher
16
+
19
17
  ##
20
18
  # Configure server
21
19
  #
@@ -29,7 +27,8 @@ module Gemirro
29
27
  end
30
28
 
31
29
  ##
32
- # Run the server and accept all connection
30
+ # Try to get all request and download files
31
+ # if files aren't found.
33
32
  #
34
33
  # @return [nil]
35
34
  #
@@ -41,14 +40,10 @@ module Gemirro
41
40
  # If not found again, return a 404
42
41
  return not_found unless File.exist?(resource)
43
42
 
44
- begin
45
- if File.directory?(resource)
46
- display_directory(resource)
47
- else
48
- send_file resource
49
- end
50
- rescue Errno::ECONNRESET, Errno::EPIPE => e
51
- logger.info(e.message)
43
+ if File.directory?(resource)
44
+ display_directory(resource)
45
+ else
46
+ send_file resource
52
47
  end
53
48
  end
54
49
 
@@ -139,7 +134,7 @@ module Gemirro
139
134
  # @return [Gemirro::GemsFetcher]
140
135
  #
141
136
  def gems_fetcher
142
- @gems_fetcher = Gemirro::GemsFetcher.new(
137
+ @gems_fetcher ||= Gemirro::GemsFetcher.new(
143
138
  configuration.source, versions_fetcher)
144
139
  end
145
140
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Gemirro Version
3
3
  module Gemirro
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -25,7 +25,7 @@ module Gemirro
25
25
  version = options.fetch_option(:v)
26
26
  expect(version.short).to eq('v')
27
27
  expect(version.long).to eq('version')
28
- expect(version.call).to be_nil
28
+ expect { version.call }.to output(/gemirro v.* on ruby/).to_stdout
29
29
  end
30
30
 
31
31
  it 'should retrieve version information' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemirro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Rambaud
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.6'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -231,12 +245,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
245
  version: 1.9.2
232
246
  required_rubygems_version: !ruby/object:Gem::Requirement
233
247
  requirements:
234
- - - '>='
248
+ - - ! '>='
235
249
  - !ruby/object:Gem::Version
236
250
  version: '0'
237
251
  requirements: []
238
252
  rubyforge_project:
239
- rubygems_version: 2.0.14
253
+ rubygems_version: 2.4.1
240
254
  signing_key:
241
255
  specification_version: 4
242
256
  summary: Gem for easily creating your own RubyGems mirror.