foreman-kicker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/foreman-kicker.gemspec +19 -0
- data/lib/foreman/kicker/executor.rb +28 -0
- data/lib/foreman/kicker/version.rb +5 -0
- data/lib/foreman/kicker/watchdog.rb +31 -0
- data/lib/foreman/kicker.rb +30 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 2012 Naoto Takai. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Foreman::Kicker
|
2
|
+
## Usage
|
3
|
+
### RSpec
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before(:suite) do
|
8
|
+
Foreman::Kicker.kick '-p', '5000'
|
9
|
+
sleep 0.1 # wait for servers to start up
|
10
|
+
end
|
11
|
+
|
12
|
+
config.after(:suite) do
|
13
|
+
Foreman::Kicker.stop
|
14
|
+
end
|
15
|
+
end
|
16
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'foreman/kicker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "foreman-kicker"
|
8
|
+
gem.version = Foreman::Kicker::VERSION
|
9
|
+
gem.authors = ["Naoto Takai"]
|
10
|
+
gem.email = %w(takai@cookpad.com)
|
11
|
+
gem.description = ""
|
12
|
+
gem.summary = ""
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Foreman
|
2
|
+
module Kicker
|
3
|
+
class Executor
|
4
|
+
attr_reader :pid
|
5
|
+
|
6
|
+
def run(*args)
|
7
|
+
fork_exec(args)
|
8
|
+
wait
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def fork_exec(args)
|
13
|
+
@pid = fork do
|
14
|
+
puts "Executing `foreman start #{args.join(' ')}`"
|
15
|
+
|
16
|
+
Process.setpgid(0, 0)
|
17
|
+
Process.exec('foreman', 'start', *args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def wait
|
22
|
+
Process.waitpid(@pid)
|
23
|
+
rescue Errno::ESRCH
|
24
|
+
# ignored
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Foreman
|
2
|
+
module Kicker
|
3
|
+
class Watchdog
|
4
|
+
def start(*args)
|
5
|
+
@pid = fork do
|
6
|
+
trap(:TERM) do
|
7
|
+
terminate(@executor.pid)
|
8
|
+
Kernel.exit(0)
|
9
|
+
end
|
10
|
+
|
11
|
+
loop do
|
12
|
+
@executor = Executor.new
|
13
|
+
@executor.run(*args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop
|
19
|
+
terminate(@pid)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def terminate(pid)
|
24
|
+
Process.kill('TERM', pid)
|
25
|
+
Process.waitpid(pid)
|
26
|
+
rescue Errno::ESRCH, Errno::ECHILD
|
27
|
+
# ignored
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "foreman/kicker/version"
|
2
|
+
require "foreman/kicker/executor"
|
3
|
+
require "foreman/kicker/watchdog"
|
4
|
+
|
5
|
+
module Foreman
|
6
|
+
module Kicker
|
7
|
+
def self.port=(port)
|
8
|
+
@port = port
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.port
|
12
|
+
@port
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.kick(*args)
|
16
|
+
if args.include?('-p') || args.include?('--port')
|
17
|
+
self.port = args[(args.find('-p') || args.find('--port')) + 1]
|
18
|
+
else
|
19
|
+
args += ['-p', port]
|
20
|
+
end
|
21
|
+
|
22
|
+
@watchdog = Foreman::Kicker::Watchdog.new
|
23
|
+
@watchdog.start(*args.map(&:to_s))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.stop
|
27
|
+
@watchdog.stop
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman-kicker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Naoto Takai
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ''
|
15
|
+
email:
|
16
|
+
- takai@cookpad.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- foreman-kicker.gemspec
|
27
|
+
- lib/foreman/kicker.rb
|
28
|
+
- lib/foreman/kicker/executor.rb
|
29
|
+
- lib/foreman/kicker/version.rb
|
30
|
+
- lib/foreman/kicker/watchdog.rb
|
31
|
+
homepage: ''
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.23
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: ''
|
55
|
+
test_files: []
|