foreverb 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +7 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/Rakefile +13 -3
- data/bin/foreverb +14 -4
- data/foreverb.gemspec +1 -0
- data/lib/forever.rb +5 -0
- data/lib/forever/base.rb +2 -0
- data/lib/forever/extensions.rb +1 -0
- data/lib/forever/version.rb +1 -1
- data/spec/cli_spec.rb +25 -0
- data/spec/foreverb_spec.rb +47 -0
- data/spec/spec_helper.rb +48 -0
- metadata +28 -6
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# Version 0.2.4 (unreleased)
|
2
|
+
|
3
|
+
* Ruby 1.9.2 compatibility
|
4
|
+
* Stop process using pid instead of file
|
5
|
+
* Added specs
|
6
|
+
* Fixed `foreverb list` where in some scenarios don't return a list of processes
|
7
|
+
|
1
8
|
# Version 0.2.3
|
2
9
|
|
3
10
|
* Added global monitoring, to easily watch each `foreverb` daemon
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems' unless defined?(Gem)
|
2
2
|
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
%w(install release).each do |task|
|
5
6
|
Rake::Task[task].enhance do
|
@@ -9,9 +10,18 @@ end
|
|
9
10
|
|
10
11
|
desc "Bump version on github"
|
11
12
|
task :bump do
|
12
|
-
puts "
|
13
|
+
puts "\e[31mNothing to commit (working directory clean)\e[0m" and return unless `git status -s`.chomp!
|
13
14
|
version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
|
14
|
-
sh "git add .; git commit -m \"Bump to version #{version}\""
|
15
|
+
sh "git add .; git commit -a -m \"Bump to version #{version}\""
|
15
16
|
end
|
16
17
|
|
17
|
-
task :release => :bump
|
18
|
+
task :release => :bump
|
19
|
+
|
20
|
+
desc "Run complete application spec suite"
|
21
|
+
RSpec::Core::RakeTask.new("spec") do |t|
|
22
|
+
t.skip_bundler = true
|
23
|
+
t.pattern = './spec/**/*_spec.rb'
|
24
|
+
t.rspec_opts = %w(-fs --color --fail-fast)
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :spec
|
data/bin/foreverb
CHANGED
@@ -3,6 +3,7 @@ require 'rubygems' unless defined?(Gem)
|
|
3
3
|
require File.expand_path('../../lib/forever/version.rb', __FILE__)
|
4
4
|
require 'thor'
|
5
5
|
require 'yaml'
|
6
|
+
require 'fileutils'
|
6
7
|
|
7
8
|
FOREVER_PATH = ENV['FOREVER_PATH'] ||= File.expand_path("~/.foreverb") unless defined?(FOREVER_PATH)
|
8
9
|
|
@@ -11,19 +12,20 @@ class CLI < Thor
|
|
11
12
|
desc "list", "List Forever running daemons"
|
12
13
|
method_option :monitor, :type => :boolean, :aliases => "-m", :default => false, :desc => "Show memory and cpu usage with ps"
|
13
14
|
def list
|
14
|
-
say "
|
15
|
+
say "Your config is empty, so no deamons was found.", :red if config.empty? && !options.monitor
|
15
16
|
|
16
17
|
if options.monitor
|
17
18
|
print_table([%w(PID RSS CPU CMD), *ps])
|
18
19
|
else
|
19
20
|
config.each do |conf|
|
20
21
|
status = begin
|
21
|
-
"WRONG CONFIG" and return unless File.exist?(conf[:pid])
|
22
22
|
pid = File.read(conf[:pid]).to_i
|
23
23
|
Process.kill(0, pid)
|
24
24
|
"RUNNING"
|
25
25
|
rescue Errno::ESRCH, Errno::ENOENT
|
26
26
|
"NOT RUNNING"
|
27
|
+
rescue Errno::EPERM
|
28
|
+
"RUNNING"
|
27
29
|
end
|
28
30
|
say_status status, conf[:file], status =~ /^RUNNING/ ? :green : :red
|
29
31
|
end
|
@@ -38,7 +40,12 @@ class CLI < Thor
|
|
38
40
|
find(daemon, :multiple => options.all).each do |conf|
|
39
41
|
if options.yes || yes?("Do you want really stop \e[1m#{conf[:file]}\e[0m?")
|
40
42
|
say_status "STOPPING", conf[:file]
|
41
|
-
|
43
|
+
begin
|
44
|
+
pid = File.read(conf[:pid]).to_i
|
45
|
+
Process.kill(:INT, pid)
|
46
|
+
rescue Exception => e
|
47
|
+
say_status "ERROR", e.message, :red
|
48
|
+
end
|
42
49
|
end
|
43
50
|
end
|
44
51
|
end
|
@@ -71,7 +78,10 @@ class CLI < Thor
|
|
71
78
|
method_option :all, :type => :boolean, :aliases => "-a", :desc => "All matching daemons"
|
72
79
|
method_option :yes, :type => :boolean, :aliases => "-y", :desc => "Don't ask permission to start the daemon"
|
73
80
|
def update(daemon=nil)
|
74
|
-
find(daemon, :multiple => options.all)
|
81
|
+
match = find(daemon, :multiple => options.all)
|
82
|
+
return if match.empty?
|
83
|
+
FileUtils.rm_rf(FOREVER_PATH)
|
84
|
+
match.each do |conf|
|
75
85
|
system(conf[:file], 'up') if options.yes || yes?("Do you want really update config from \e[1m#{conf[:file]}\e[0m?")
|
76
86
|
end
|
77
87
|
end
|
data/foreverb.gemspec
CHANGED
data/lib/forever.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'yaml' unless defined?(YAML)
|
1
2
|
require "forever/extensions"
|
2
3
|
require "forever/every"
|
3
4
|
require "forever/base"
|
4
5
|
require "forever/version"
|
5
6
|
|
7
|
+
YAML::ENGINE.yamler = "syck" if defined?(YAML::ENGINE)
|
8
|
+
|
6
9
|
FOREVER_PATH = ENV['FOREVER_PATH'] ||= File.expand_path("~/.foreverb") unless defined?(FOREVER_PATH)
|
10
|
+
path = File.dirname(FOREVER_PATH)
|
11
|
+
Dir.mkdir(path) unless File.exist?(path)
|
7
12
|
|
8
13
|
module Forever
|
9
14
|
extend self
|
data/lib/forever/base.rb
CHANGED
data/lib/forever/extensions.rb
CHANGED
data/lib/forever/version.rb
CHANGED
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CLI" do
|
4
|
+
|
5
|
+
it "should list no daemons" do
|
6
|
+
cli('list').should match(/Your config is empty/)
|
7
|
+
cli('list').should match(FOREVER_PATH)
|
8
|
+
cli('list -m').should match(/PID RSS CPU CMD/)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should list a daemon" do
|
12
|
+
run_example
|
13
|
+
cli('list').should match(/RUNNING/)
|
14
|
+
cli('list -m').should match(/Forever:\s/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should stop daemons" do
|
18
|
+
run_example
|
19
|
+
cli('list').should match(/RUNNING/)
|
20
|
+
result = cli('stop -a -y')
|
21
|
+
result.should match(/STOPPING/)
|
22
|
+
result.should_not match(/ERROR/)
|
23
|
+
cli('list').should match(/NOT RUNNING/)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forever do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
ARGV << 'up'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should set a basic config' do
|
10
|
+
@forever = Forever.run {}
|
11
|
+
@forever.dir.should == File.expand_path("../../", __FILE__)
|
12
|
+
@forever.log.should == File.join(@forever.dir, 'log', File.basename(__FILE__) + '.log')
|
13
|
+
@forever.pid.should == File.join(@forever.dir, 'tmp', File.basename(__FILE__) + '.pid')
|
14
|
+
@forever.file.should == __FILE__
|
15
|
+
config = YAML.load_file(FOREVER_PATH)
|
16
|
+
config[0][:file].should == __FILE__
|
17
|
+
config[0][:log].should == @forever.log
|
18
|
+
config[0][:pid].should == @forever.pid
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should set a custom config' do
|
22
|
+
@forever = Forever.run do
|
23
|
+
dir File.expand_path('../', __FILE__)
|
24
|
+
end
|
25
|
+
@forever.dir.should == File.expand_path('../', __FILE__)
|
26
|
+
@forever.log.should == File.join(@forever.dir, 'log', File.basename(__FILE__) + '.log')
|
27
|
+
@forever.pid.should == File.join(@forever.dir, 'tmp', File.basename(__FILE__) + '.pid')
|
28
|
+
@forever.file.should == __FILE__
|
29
|
+
config = YAML.load_file(FOREVER_PATH)
|
30
|
+
config[0][:file].should == __FILE__
|
31
|
+
config[0][:log].should == @forever.log
|
32
|
+
config[0][:pid].should == @forever.pid
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should launch a daemon' do
|
36
|
+
ARGV.clear
|
37
|
+
stdout_was, $stdout = $stdout, StringIO.new
|
38
|
+
@forever = Forever.run do
|
39
|
+
on_ready { sleep 2 }
|
40
|
+
end
|
41
|
+
sleep 0.1 while !File.exist?(@forever.pid)
|
42
|
+
pid = File.read(@forever.pid).to_i
|
43
|
+
Process.waitpid(pid)
|
44
|
+
$stdout.string.should match(/pid not found/i)
|
45
|
+
$stdout = stdout_was
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
FOREVER_PATH = ENV['FOREVER_PATH'] ||= File.expand_path("../tmp/db.yaml", __FILE__)
|
2
|
+
require 'rubygems' unless defined?(Gem)
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec'
|
5
|
+
require 'forever'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
module Helper
|
9
|
+
def capture_stdout(&block)
|
10
|
+
stdout_was, $stdout = $stdout, StringIO.new
|
11
|
+
block.call
|
12
|
+
return $stdout
|
13
|
+
ensure
|
14
|
+
$stdout = stdout_was
|
15
|
+
end
|
16
|
+
|
17
|
+
def run_example
|
18
|
+
capture_stdout do
|
19
|
+
@forever = Forever.run do
|
20
|
+
on_ready { sleep }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def cli(task)
|
26
|
+
output = `#{Gem.ruby} #{File.expand_path('../../bin/foreverb', __FILE__)} #{task}`
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.include(Helper)
|
32
|
+
|
33
|
+
config.before :each do
|
34
|
+
FileUtils.rm_rf File.dirname(FOREVER_PATH)
|
35
|
+
Dir.mkdir File.dirname(FOREVER_PATH)
|
36
|
+
ARGV.clear
|
37
|
+
end
|
38
|
+
|
39
|
+
config.after :each do
|
40
|
+
FileUtils.rm_rf(File.dirname(FOREVER_PATH))
|
41
|
+
if @forever
|
42
|
+
capture_stdout { @forever.stop! }
|
43
|
+
FileUtils.rm_rf(File.dirname(@forever.log)) if @forever.log
|
44
|
+
FileUtils.rm_rf(File.dirname(@forever.pid)) if @forever.pid
|
45
|
+
end
|
46
|
+
ARGV.clear
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreverb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- DAddYE
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-26 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,22 @@ dependencies:
|
|
34
34
|
version: 0.14.6
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
- 0
|
50
|
+
version: 2.6.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
37
53
|
description: Small daemon framework for ruby, with logging, error handler, scheduling and much more.
|
38
54
|
email:
|
39
55
|
- d.dagostino@lipsiasoft.com
|
@@ -47,6 +63,7 @@ files:
|
|
47
63
|
- .gitignore
|
48
64
|
- CHANGES.md
|
49
65
|
- Gemfile
|
66
|
+
- Guardfile
|
50
67
|
- README.md
|
51
68
|
- Rakefile
|
52
69
|
- bin/foreverb
|
@@ -57,6 +74,9 @@ files:
|
|
57
74
|
- lib/forever/every.rb
|
58
75
|
- lib/forever/extensions.rb
|
59
76
|
- lib/forever/version.rb
|
77
|
+
- spec/cli_spec.rb
|
78
|
+
- spec/foreverb_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
60
80
|
has_rdoc: true
|
61
81
|
homepage: https://github.com/daddye/forever
|
62
82
|
licenses: []
|
@@ -91,5 +111,7 @@ rubygems_version: 1.6.2
|
|
91
111
|
signing_key:
|
92
112
|
specification_version: 3
|
93
113
|
summary: Small daemon framework for ruby
|
94
|
-
test_files:
|
95
|
-
|
114
|
+
test_files:
|
115
|
+
- spec/cli_spec.rb
|
116
|
+
- spec/foreverb_spec.rb
|
117
|
+
- spec/spec_helper.rb
|