garlando 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/bin/garlando +4 -0
- data/garlando.gemspec +22 -0
- data/lib/garlando.rb +112 -0
- data/lib/garlando/version.rb +3 -0
- data/spec/garlando_spec.rb +69 -0
- data/spec/spec_helper.rb +6 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cfa5cad9a4e1f969113e9075792514547862b16
|
4
|
+
data.tar.gz: 32a0b2154abaab7a0bf8bf00003a47a60d9e6832
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2b9f94307c4d637bc185c2fca8d8862793871735cfefda4401904e8dd8f94bdbebb4d788b7085f2b1e3553e478961b99683b4c3f750124a884382655e3c413f
|
7
|
+
data.tar.gz: 4f5a43b9b150036dfeadfca2453936cd404907f1b74a0a5dfeeaf3823c236d08b6d09cff699c5f055fde5c4bc755a7eaad638c3400300058705f8ea6e9a92b09
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yuki MIYAUCHI
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Garlando
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'garlando'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install garlando
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/garlando/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/garlando
ADDED
data/garlando.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'garlando/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "garlando"
|
8
|
+
spec.version = Garlando::VERSION
|
9
|
+
spec.authors = ["miyucy"]
|
10
|
+
spec.email = ["fistfvck@gmail.com"]
|
11
|
+
spec.summary = %q{asset server}
|
12
|
+
spec.description = %q{asset server}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
end
|
data/lib/garlando.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'garlando/version'
|
2
|
+
require 'optparse'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module Garlando
|
6
|
+
class Server
|
7
|
+
COMMANDS = %i[start restart stop status]
|
8
|
+
OPTIONS = {
|
9
|
+
server: 'thin',
|
10
|
+
host: '0.0.0.0',
|
11
|
+
port: 65501,
|
12
|
+
pid: 'tmp/pids/asset_server.pid',
|
13
|
+
env: 'development',
|
14
|
+
pwd: Dir.pwd,
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(options={})
|
18
|
+
@options = OPTIONS.merge options
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(command)
|
22
|
+
raise ArgumentError unless COMMANDS.include? command
|
23
|
+
method(command).call
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
abort 'server is already running?' if File.exists? pid_path
|
28
|
+
abort "File could not found (#{env_path})" unless File.exists?(env_path)
|
29
|
+
|
30
|
+
Process.daemon nochdir = true
|
31
|
+
|
32
|
+
File.write pid_path, Process.pid.to_s
|
33
|
+
at_exit { File.unlink pid_path }
|
34
|
+
|
35
|
+
ENV['RACK_ENV'] = @options[:env]
|
36
|
+
require env_path
|
37
|
+
|
38
|
+
app = Rack::URLMap.new Rails.application.config.assets[:prefix] => Rails.application.assets
|
39
|
+
srv = Rack::Handler.pick @options[:server]
|
40
|
+
srv.run app, Host: @options[:host], Port: @options[:port]
|
41
|
+
end
|
42
|
+
|
43
|
+
def stop(aborting = true)
|
44
|
+
unless File.exists?(pid_path)
|
45
|
+
return unless aborting
|
46
|
+
abort 'server is not running'
|
47
|
+
end
|
48
|
+
|
49
|
+
pid = File.read(pid_path).to_i
|
50
|
+
Timeout.timeout(10) do
|
51
|
+
loop do
|
52
|
+
break unless system "ps -p #{pid} > /dev/null"
|
53
|
+
Process.kill :INT, pid
|
54
|
+
sleep 0.5
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def restart
|
60
|
+
stop aborting = false
|
61
|
+
start
|
62
|
+
end
|
63
|
+
|
64
|
+
def status
|
65
|
+
if File.exists? pid_path
|
66
|
+
puts "server is running (#{File.read pid_path})"
|
67
|
+
else
|
68
|
+
puts 'server is not running'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def pid_path
|
75
|
+
File.join @options[:pwd], @options[:pid]
|
76
|
+
end
|
77
|
+
|
78
|
+
def env_path
|
79
|
+
File.join @options[:pwd], 'config/environment.rb'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class CLI
|
84
|
+
def self.perform(args)
|
85
|
+
new.perform(args)
|
86
|
+
end
|
87
|
+
|
88
|
+
def perform(args)
|
89
|
+
commands, options = parse(args)
|
90
|
+
command = (commands.first || :restart).to_sym
|
91
|
+
|
92
|
+
begin
|
93
|
+
Server.new(options).call command
|
94
|
+
rescue ArgumentError
|
95
|
+
abort 'unsupported command'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse(args)
|
100
|
+
options = Server::OPTIONS.dup
|
101
|
+
|
102
|
+
opt = OptionParser.new
|
103
|
+
opt.on('-s', '--server SERVER') { |v| options[:server] = v }
|
104
|
+
opt.on('-o', '--host HOST') { |v| options[:host] = v }
|
105
|
+
opt.on('-p', '--port PORT') { |v| options[:port] = v }
|
106
|
+
opt.on('-P', '--pid FILE') { |v| options[:pid] = v }
|
107
|
+
opt.on('-E', '--env ENVIRONMENT') { |v| options[:env] = v }
|
108
|
+
|
109
|
+
[opt.parse(args), options]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Garlando::CLI do
|
4
|
+
let(:cli) { Garlando::CLI.new }
|
5
|
+
|
6
|
+
describe '#parse' do
|
7
|
+
it 'return command' do
|
8
|
+
commands, _ = cli.parse %w[start]
|
9
|
+
|
10
|
+
expect(commands).to eq ['start']
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'return options' do
|
14
|
+
_, options = cli.parse %w[-s puma]
|
15
|
+
|
16
|
+
expect(options[:server]).to eq 'puma'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#perform' do
|
21
|
+
it 'default command' do
|
22
|
+
Garlando::Server.any_instance.stub(:call)
|
23
|
+
# Garlando::Server.stub(new: true)
|
24
|
+
cli.perform %w[]
|
25
|
+
|
26
|
+
allow_any_instance_of(Garlando::Server).to receive(:call).with(:restart)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'send command' do
|
30
|
+
Garlando::Server.any_instance.stub(:call)
|
31
|
+
cli.perform %w[foo]
|
32
|
+
|
33
|
+
allow_any_instance_of(Garlando::Server).to receive(:call).with(:foo)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Garlando::Server do
|
39
|
+
let(:server) { Garlando::Server.new }
|
40
|
+
|
41
|
+
describe '#call' do
|
42
|
+
it 'raise ArgumentError' do
|
43
|
+
expect { server.call :unsupported_command }.to raise_error ArgumentError
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'otherwise' do
|
47
|
+
server.stub start: nil
|
48
|
+
server.call :start
|
49
|
+
|
50
|
+
allow(server).to receive :start
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#restart' do
|
55
|
+
before { server.stub stop: nil, start: nil }
|
56
|
+
|
57
|
+
it 'call stop' do
|
58
|
+
server.restart
|
59
|
+
|
60
|
+
allow(server).to receive(:stop)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'call start' do
|
64
|
+
server.restart
|
65
|
+
|
66
|
+
allow(server).to receive(:start)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: garlando
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- miyucy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
description: asset server
|
28
|
+
email:
|
29
|
+
- fistfvck@gmail.com
|
30
|
+
executables:
|
31
|
+
- garlando
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- bin/garlando
|
41
|
+
- garlando.gemspec
|
42
|
+
- lib/garlando.rb
|
43
|
+
- lib/garlando/version.rb
|
44
|
+
- spec/garlando_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.2.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: asset server
|
70
|
+
test_files:
|
71
|
+
- spec/garlando_spec.rb
|
72
|
+
- spec/spec_helper.rb
|