eye 0.2.4 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/bin/eye +7 -0
- data/bin/loader_eye +7 -5
- data/examples/notify.eye +1 -1
- data/eye.gemspec +4 -4
- data/lib/eye.rb +1 -3
- data/lib/eye/controller.rb +4 -0
- data/lib/eye/controller/status.rb +1 -1
- data/lib/eye/dsl.rb +1 -1
- data/lib/eye/dsl/main.rb +0 -13
- data/lib/eye/dsl/opts.rb +4 -2
- data/lib/eye/loader.rb +2 -3
- data/lib/eye/notify.rb +3 -3
- data/lib/eye/process/monitor.rb +5 -3
- data/lib/eye/process/notify.rb +5 -5
- data/lib/eye/process/scheduler.rb +4 -4
- data/lib/eye/process/system.rb +3 -10
- data/lib/eye/process/trigger.rb +1 -1
- data/lib/eye/process/watchers.rb +1 -1
- data/lib/eye/server.rb +9 -8
- data/lib/eye/system.rb +2 -7
- data/lib/eye/system_resources.rb +3 -3
- data/lib/eye/utils/celluloid_chain.rb +2 -2
- metadata +7 -241
- data/lib/eye/io/unix_server.rb +0 -44
- data/lib/eye/io/unix_socket.rb +0 -39
- data/spec/checker/cpu_spec.rb +0 -58
- data/spec/checker/file_ctime_spec.rb +0 -34
- data/spec/checker/file_size_spec.rb +0 -107
- data/spec/checker/http_spec.rb +0 -114
- data/spec/checker/memory_spec.rb +0 -64
- data/spec/checker/socket_spec.rb +0 -116
- data/spec/checker_spec.rb +0 -187
- data/spec/child_process/child_process_spec.rb +0 -46
- data/spec/client_server_spec.rb +0 -33
- data/spec/controller/commands_spec.rb +0 -92
- data/spec/controller/controller_spec.rb +0 -157
- data/spec/controller/find_objects_spec.rb +0 -176
- data/spec/controller/group_spec.rb +0 -110
- data/spec/controller/intergration_spec.rb +0 -366
- data/spec/controller/load_spec.rb +0 -371
- data/spec/controller/races_spec.rb +0 -70
- data/spec/controller/stop_on_delete_spec.rb +0 -157
- data/spec/dsl/chain_spec.rb +0 -146
- data/spec/dsl/checks_spec.rb +0 -219
- data/spec/dsl/config_spec.rb +0 -44
- data/spec/dsl/dsl_spec.rb +0 -73
- data/spec/dsl/getter_spec.rb +0 -223
- data/spec/dsl/integration_spec.rb +0 -376
- data/spec/dsl/load_spec.rb +0 -52
- data/spec/dsl/notify_spec.rb +0 -114
- data/spec/dsl/process_spec.rb +0 -380
- data/spec/dsl/sub_procs_spec.rb +0 -93
- data/spec/dsl/with_server_spec.rb +0 -128
- data/spec/example/em.rb +0 -57
- data/spec/example/forking.rb +0 -20
- data/spec/example/sample.rb +0 -154
- data/spec/fixtures/dsl/0.rb +0 -8
- data/spec/fixtures/dsl/0a.rb +0 -8
- data/spec/fixtures/dsl/0c.rb +0 -8
- data/spec/fixtures/dsl/1.rb +0 -5
- data/spec/fixtures/dsl/bad.eye +0 -6
- data/spec/fixtures/dsl/configs/1.eye +0 -3
- data/spec/fixtures/dsl/configs/2.eye +0 -1
- data/spec/fixtures/dsl/configs/3.eye +0 -1
- data/spec/fixtures/dsl/configs/4.eye +0 -3
- data/spec/fixtures/dsl/empty.eye +0 -20
- data/spec/fixtures/dsl/include_test.eye +0 -5
- data/spec/fixtures/dsl/include_test/1.rb +0 -6
- data/spec/fixtures/dsl/include_test/ha.rb +0 -4
- data/spec/fixtures/dsl/include_test2.eye +0 -5
- data/spec/fixtures/dsl/integration.eye +0 -30
- data/spec/fixtures/dsl/integration2.eye +0 -32
- data/spec/fixtures/dsl/integration_locks.eye +0 -30
- data/spec/fixtures/dsl/integration_sor.eye +0 -32
- data/spec/fixtures/dsl/integration_sor2.eye +0 -27
- data/spec/fixtures/dsl/integration_sor3.eye +0 -32
- data/spec/fixtures/dsl/load.eye +0 -25
- data/spec/fixtures/dsl/load2.eye +0 -7
- data/spec/fixtures/dsl/load2_dup2.eye +0 -13
- data/spec/fixtures/dsl/load2_dup_pid.eye +0 -7
- data/spec/fixtures/dsl/load3.eye +0 -10
- data/spec/fixtures/dsl/load4.eye +0 -7
- data/spec/fixtures/dsl/load5.eye +0 -8
- data/spec/fixtures/dsl/load6.eye +0 -17
- data/spec/fixtures/dsl/load_dubls.eye +0 -36
- data/spec/fixtures/dsl/load_dup_ex_names.eye +0 -15
- data/spec/fixtures/dsl/load_error.eye +0 -5
- data/spec/fixtures/dsl/load_error_folder/load3.eye +0 -10
- data/spec/fixtures/dsl/load_error_folder/load4.eye +0 -7
- data/spec/fixtures/dsl/load_folder/load3.eye +0 -10
- data/spec/fixtures/dsl/load_folder/load4.eye +0 -7
- data/spec/fixtures/dsl/load_int.eye +0 -8
- data/spec/fixtures/dsl/load_int2.eye +0 -13
- data/spec/fixtures/dsl/load_logger.eye +0 -26
- data/spec/fixtures/dsl/load_logger2.eye +0 -3
- data/spec/fixtures/dsl/long_load.eye +0 -5
- data/spec/fixtures/dsl/subfolder1/proc1.rb +0 -3
- data/spec/fixtures/dsl/subfolder2.eye +0 -9
- data/spec/fixtures/dsl/subfolder2/common.rb +0 -1
- data/spec/fixtures/dsl/subfolder2/proc2.rb +0 -3
- data/spec/fixtures/dsl/subfolder2/sub/proc3.rb +0 -6
- data/spec/fixtures/dsl/subfolder3.eye +0 -8
- data/spec/fixtures/dsl/subfolder3/common.rb +0 -1
- data/spec/fixtures/dsl/subfolder3/proc4.rb +0 -3
- data/spec/fixtures/dsl/subfolder3/sub/proc5.rb +0 -6
- data/spec/fixtures/dsl/subfolder4.eye +0 -6
- data/spec/fixtures/dsl/subfolder4/a.rb +0 -2
- data/spec/fixtures/dsl/subfolder4/b.rb +0 -1
- data/spec/fixtures/dsl/subfolder4/c.rb +0 -1
- data/spec/mock_spec.rb +0 -31
- data/spec/notify/jabber_spec.rb +0 -25
- data/spec/notify/mail_spec.rb +0 -26
- data/spec/notify_spec.rb +0 -90
- data/spec/process/checks/child_checks_spec.rb +0 -79
- data/spec/process/checks/cpu_spec.rb +0 -114
- data/spec/process/checks/ctime_spec.rb +0 -43
- data/spec/process/checks/fsize_spec.rb +0 -22
- data/spec/process/checks/http_spec.rb +0 -52
- data/spec/process/checks/intergration_spec.rb +0 -32
- data/spec/process/checks/memory_spec.rb +0 -127
- data/spec/process/child_process_spec.rb +0 -125
- data/spec/process/config_spec.rb +0 -74
- data/spec/process/controller_spec.rb +0 -173
- data/spec/process/monitoring_spec.rb +0 -180
- data/spec/process/notify_spec.rb +0 -27
- data/spec/process/restart_spec.rb +0 -186
- data/spec/process/scheduler_spec.rb +0 -178
- data/spec/process/start_spec.rb +0 -261
- data/spec/process/states_history_spec.rb +0 -123
- data/spec/process/stop_spec.rb +0 -156
- data/spec/process/system_spec.rb +0 -136
- data/spec/process/triggers/flapping_spec.rb +0 -242
- data/spec/process/update_config_spec.rb +0 -62
- data/spec/spec_helper.rb +0 -128
- data/spec/support/rr_celluloid.rb +0 -15
- data/spec/support/spec_support.rb +0 -163
- data/spec/system_resources_spec.rb +0 -56
- data/spec/system_spec.rb +0 -174
- data/spec/utils/alive_array_spec.rb +0 -49
- data/spec/utils/celluloid_chain_spec.rb +0 -89
- data/spec/utils/tail_spec.rb +0 -20
data/spec/dsl/sub_procs_spec.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe "sub procs" do
|
4
|
-
it "include lambda" do
|
5
|
-
conf = <<-E
|
6
|
-
proc = lambda do |proxy|
|
7
|
-
proxy.working_dir "/tmp"
|
8
|
-
end
|
9
|
-
|
10
|
-
Eye.application("bla") do
|
11
|
-
include proc
|
12
|
-
end
|
13
|
-
E
|
14
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:working_dir=>"/tmp", :name => "bla"}}
|
15
|
-
end
|
16
|
-
|
17
|
-
it "include lambda with arg" do
|
18
|
-
conf = <<-E
|
19
|
-
proc = lambda do |proxy, arg|
|
20
|
-
proxy.working_dir arg
|
21
|
-
end
|
22
|
-
|
23
|
-
Eye.application("bla") do
|
24
|
-
include proc, "1"
|
25
|
-
end
|
26
|
-
E
|
27
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:name=>"bla", :working_dir=>"1"}}
|
28
|
-
end
|
29
|
-
|
30
|
-
it "include proc" do
|
31
|
-
conf = <<-E
|
32
|
-
proc = Proc.new do
|
33
|
-
working_dir "/tmp"
|
34
|
-
end
|
35
|
-
|
36
|
-
Eye.application("bla") do
|
37
|
-
include proc
|
38
|
-
end
|
39
|
-
E
|
40
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:working_dir=>"/tmp", :name => "bla"}}
|
41
|
-
end
|
42
|
-
|
43
|
-
it "include proc with arg" do
|
44
|
-
conf = <<-E
|
45
|
-
proc = Proc.new do |proxy, arg|
|
46
|
-
proxy.working_dir arg
|
47
|
-
end
|
48
|
-
|
49
|
-
Eye.application("bla") do
|
50
|
-
include proc, "1"
|
51
|
-
end
|
52
|
-
E
|
53
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:name=>"bla", :working_dir=>"1"}}
|
54
|
-
end
|
55
|
-
|
56
|
-
it "include method" do
|
57
|
-
conf = <<-E
|
58
|
-
def add_process(proxy)
|
59
|
-
working_dir "/tmp"
|
60
|
-
end
|
61
|
-
|
62
|
-
Eye.application("bla") do
|
63
|
-
include method(:add_process)
|
64
|
-
end
|
65
|
-
E
|
66
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:working_dir=>"/tmp", :name => "bla"}}
|
67
|
-
end
|
68
|
-
|
69
|
-
it "include method with arg" do
|
70
|
-
conf = <<-E
|
71
|
-
def add_process(proxy, arg)
|
72
|
-
working_dir arg
|
73
|
-
end
|
74
|
-
|
75
|
-
Eye.application("bla") do
|
76
|
-
include method(:add_process), "1"
|
77
|
-
end
|
78
|
-
E
|
79
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:name=>"bla", :working_dir=>"1"}}
|
80
|
-
end
|
81
|
-
|
82
|
-
it "include part of code" do
|
83
|
-
Eye::Dsl.parse_apps(nil, fixture("dsl/include_test.eye")).should == {
|
84
|
-
"test" => {:name=>"test", :environment=>{"a"=>"b"},
|
85
|
-
:groups=>{"__default__"=>{:name=>"__default__", :environment=>{"a"=>"b"}, :application=>"test",
|
86
|
-
:processes=>{"bla"=>{:name=>"bla", :environment=>{"a"=>"b"}, :application=>"test", :group=>"__default__", :pid_file=>"10"}}}}}}
|
87
|
-
end
|
88
|
-
|
89
|
-
it "include part of code 2 times" do
|
90
|
-
Eye::Dsl.parse_apps(nil, fixture("dsl/include_test2.eye")).should == {"test2" => {:name=>"test2", :groups=>{"ha"=>{:name=>"ha", :application=>"test2", :environment=>{"a"=>"b"}, :processes=>{"bla"=>{:name=>"bla", :application=>"test2", :environment=>{"a"=>"b"}, :group=>"ha", :pid_file=>"10"}}}}}}
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
@@ -1,128 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe "with_server feature" do
|
4
|
-
|
5
|
-
it "should load matched by string process" do
|
6
|
-
stub(Eye::System).host{ "server1" }
|
7
|
-
|
8
|
-
conf = <<-E
|
9
|
-
Eye.application("bla") do
|
10
|
-
with_server "server1" do
|
11
|
-
process("1"){ pid_file "1.pid" }
|
12
|
-
end
|
13
|
-
|
14
|
-
with_server "server2" do
|
15
|
-
process("2"){ pid_file "2.pid" }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
E
|
19
|
-
|
20
|
-
Eye::Dsl.parse_apps(conf).should == {"bla"=>{:name => "bla", :groups=>{"__default__"=>{:name => "__default__", :application => "bla", :processes=>{"1"=>{:pid_file=>"1.pid", :application=>"bla", :group=>"__default__", :name=>"1"}}}}}}
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should another host conditions" do
|
24
|
-
stub(Eye::System).host{ "server1" }
|
25
|
-
|
26
|
-
conf = <<-E
|
27
|
-
Eye.application("bla") do
|
28
|
-
with_server %w{server1 server2} do
|
29
|
-
process("1"){ pid_file "1.pid" }
|
30
|
-
|
31
|
-
if Eye::SystemResources == 'server2'
|
32
|
-
process("2"){ pid_file "2.pid" }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
E
|
37
|
-
|
38
|
-
Eye::Dsl.parse_apps(conf).should == {"bla"=>{:name => "bla", :groups=>{"__default__"=>{:name => "__default__", :application => "bla", :processes=>{"1"=>{:pid_file=>"1.pid", :application=>"bla", :group=>"__default__", :name=>"1"}}}}}}
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should behaves like scoped" do
|
42
|
-
stub(Eye::System).host{ "server1" }
|
43
|
-
|
44
|
-
conf = <<-E
|
45
|
-
Eye.application("bla") do
|
46
|
-
env "A" => "B"
|
47
|
-
with_server /server1/ do
|
48
|
-
env "A" => "C"
|
49
|
-
group(:a){}
|
50
|
-
end
|
51
|
-
|
52
|
-
group(:b){}
|
53
|
-
end
|
54
|
-
E
|
55
|
-
|
56
|
-
Eye::Dsl.parse_apps(conf).should == {
|
57
|
-
"bla" => {:name=>"bla", :environment=>{"A"=>"B"},
|
58
|
-
:groups=>{
|
59
|
-
"a"=>{:name=>"a", :environment=>{"A"=>"C"}, :application=>"bla", :processes=>{}},
|
60
|
-
"b"=>{:name=>"b", :environment=>{"A"=>"B"}, :application=>"bla", :processes=>{}}}}}
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "matches" do
|
64
|
-
subject{ Eye::Dsl::Opts.new }
|
65
|
-
|
66
|
-
it "match string" do
|
67
|
-
stub(Eye::System).host{ "server1" }
|
68
|
-
subject.with_server("server1").should == true
|
69
|
-
subject.with_server("server2").should == false
|
70
|
-
subject.with_server('').should == true
|
71
|
-
subject.with_server(nil).should == true
|
72
|
-
end
|
73
|
-
|
74
|
-
it "match array" do
|
75
|
-
stub(Eye::System).host{ "server1" }
|
76
|
-
subject.with_server(%w{ server1 server2}).should == true
|
77
|
-
subject.with_server(%w{ server2 server3}).should == false
|
78
|
-
end
|
79
|
-
|
80
|
-
it "match regexp" do
|
81
|
-
stub(Eye::System).host{ "server1" }
|
82
|
-
subject.with_server(%r{server}).should == true
|
83
|
-
subject.with_server(%r{myserver}).should == false
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "helpers" do
|
88
|
-
it "hostname on with server" do
|
89
|
-
conf = <<-E
|
90
|
-
Eye.application("bla"){
|
91
|
-
with_server('muga_server') do
|
92
|
-
working_dir "/tmp"
|
93
|
-
end
|
94
|
-
}
|
95
|
-
E
|
96
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:name => "bla"}}
|
97
|
-
end
|
98
|
-
|
99
|
-
it "with_server work" do
|
100
|
-
Eye::System.host = 'mega_server'
|
101
|
-
|
102
|
-
conf = <<-E
|
103
|
-
Eye.application("bla"){
|
104
|
-
with_server('mega_server') do
|
105
|
-
group :blo do
|
106
|
-
working_dir "/tmp"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
}
|
110
|
-
E
|
111
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:name=>"bla", :groups=>{"blo"=>{:name=>"blo", :application=>"bla", :working_dir=>"/tmp", :processes=>{}}}}}
|
112
|
-
end
|
113
|
-
|
114
|
-
it "hostname work" do
|
115
|
-
Eye::System.host = 'supa_server'
|
116
|
-
|
117
|
-
conf = <<-E
|
118
|
-
Eye.application("bla"){
|
119
|
-
working_dir "/tmp"
|
120
|
-
env "HOST" => hostname
|
121
|
-
}
|
122
|
-
E
|
123
|
-
Eye::Dsl.parse_apps(conf).should == {"bla" => {:name => "bla", :working_dir=>"/tmp", :environment=>{"HOST"=>"supa_server"}}}
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
data/spec/example/em.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'eventmachine'
|
3
|
-
|
4
|
-
def answer(data)
|
5
|
-
case data
|
6
|
-
when 'ping' then "pong\n"
|
7
|
-
when 'bad' then "what\n"
|
8
|
-
when 'timeout' then sleep 5; "ok\n"
|
9
|
-
when 'exception' then raise 'haha'
|
10
|
-
when 'quit' then EM.stop
|
11
|
-
when 'big' then 'a' * 10_000_000
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Echo < EM::Connection
|
16
|
-
def post_init
|
17
|
-
puts "-- someone connected to the echo server!"
|
18
|
-
end
|
19
|
-
|
20
|
-
def receive_data data
|
21
|
-
puts "receive #{data.inspect}"
|
22
|
-
send_data(answer(data))
|
23
|
-
end
|
24
|
-
|
25
|
-
def unbind
|
26
|
-
puts "-- someone disconnected from the echo server!"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class EchoObj < EM::Connection
|
31
|
-
include EM::P::ObjectProtocol
|
32
|
-
|
33
|
-
def post_init
|
34
|
-
puts "-- someone connected to the echo server!"
|
35
|
-
end
|
36
|
-
|
37
|
-
def receive_object obj # {:command => 'ping'}
|
38
|
-
puts "receive #{obj.inspect}"
|
39
|
-
send_object(answer(obj[:command]).chop)
|
40
|
-
end
|
41
|
-
|
42
|
-
def unbind
|
43
|
-
puts "-- someone disconnected from the echo server!"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
trap "TERM" do
|
48
|
-
EM.stop
|
49
|
-
`rm /tmp/em_test_sock_spec` rescue nil
|
50
|
-
end
|
51
|
-
|
52
|
-
EM.run do
|
53
|
-
EM.start_server '127.0.0.1', 33231, Echo
|
54
|
-
EM.start_server '127.0.0.1', 33232, EchoObj
|
55
|
-
EM.start_server "/tmp/em_test_sock_spec", nil, Echo
|
56
|
-
puts 'started'
|
57
|
-
end
|
data/spec/example/forking.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'forking'
|
3
|
-
|
4
|
-
root = File.expand_path(File.dirname(__FILE__))
|
5
|
-
|
6
|
-
f = Forking.new(:name => 'forking', :working_dir => root,
|
7
|
-
:log_file => "#{root}/forking.log",
|
8
|
-
:pid_file => "#{root}/forking.pid", :sync_log => true)
|
9
|
-
|
10
|
-
3.times do |i|
|
11
|
-
f.spawn(:log_file => "#{root}/child#{i}.log", :sync_log => true) do
|
12
|
-
$0 = "forking child"
|
13
|
-
loop do
|
14
|
-
p "#{Time.now} - #{Time.now.to_f} - #{i} - tick"
|
15
|
-
sleep 0.1
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
f.run!
|
data/spec/example/sample.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'optparse'
|
3
|
-
|
4
|
-
# This hash will hold all of the options
|
5
|
-
# parsed from the command-line by
|
6
|
-
# OptionParser.
|
7
|
-
options = {}
|
8
|
-
|
9
|
-
optparse = OptionParser.new do|opts|
|
10
|
-
# This displays the help screen, all programs are
|
11
|
-
# assumed to have this option.
|
12
|
-
opts.on( '-h', '--help', 'Display this screen' ) do
|
13
|
-
puts opts
|
14
|
-
exit
|
15
|
-
end
|
16
|
-
|
17
|
-
opts.on( '-p', '--pid FILE', 'pid_file' ) do |a|
|
18
|
-
options[:pid_file] = a
|
19
|
-
end
|
20
|
-
|
21
|
-
opts.on( '-l', '--log FILE', 'log_file' ) do |a|
|
22
|
-
options[:log_file] = a
|
23
|
-
end
|
24
|
-
|
25
|
-
opts.on( '-L', '--lock FILE', 'lock_file' ) do |a|
|
26
|
-
options[:lock_file] = a
|
27
|
-
end
|
28
|
-
|
29
|
-
opts.on( '-d', '--daemonize', 'Daemonize' ) do
|
30
|
-
options[:daemonize] = true
|
31
|
-
end
|
32
|
-
|
33
|
-
opts.on( '-s', '--daemonize_delay DELAY', 'Daemonized time' ) do |d|
|
34
|
-
options[:daemonize_delay] = d
|
35
|
-
end
|
36
|
-
|
37
|
-
opts.on( '-r', '--raise', 'Raised execution' ) do
|
38
|
-
options[:raise] = true
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on( '-w', '--watch_file FILE', 'Exit on touched file' ) do |w|
|
42
|
-
options[:watch_file] = w
|
43
|
-
end
|
44
|
-
|
45
|
-
opts.on( '-W', '--watch_file_delay DELAY', 'Exit on touched file, after delay' ) do |w|
|
46
|
-
options[:watch_file_delay] = w
|
47
|
-
end
|
48
|
-
|
49
|
-
opts.on( '-T', '--no_terminate', 'catch terminate signal and not die' ) do
|
50
|
-
options[:no_terminate] = true
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
optparse.parse!
|
56
|
-
|
57
|
-
module Sample
|
58
|
-
def puts(mes = "")
|
59
|
-
tm = Time.now
|
60
|
-
STDOUT.puts "#{tm.to_s} (#{tm.to_f}) - #{mes}"
|
61
|
-
STDOUT.flush
|
62
|
-
end
|
63
|
-
|
64
|
-
def daemonize(pid_file, log_file, daemonize_delay = 0)
|
65
|
-
puts "daemonize start #{pid_file}, #{log_file}, #{daemonize_delay}"
|
66
|
-
|
67
|
-
if daemonize_delay && daemonize_delay.to_f > 0
|
68
|
-
puts "daemonize delay start #{daemonize_delay}"
|
69
|
-
sleep daemonize_delay.to_f
|
70
|
-
puts "daemonize delay end"
|
71
|
-
end
|
72
|
-
|
73
|
-
daemon
|
74
|
-
STDOUT.reopen(log_file, "a")
|
75
|
-
STDERR.reopen(log_file, "a")
|
76
|
-
File.open(pid_file, 'w'){|f| f.write $$.to_s}
|
77
|
-
|
78
|
-
puts "daemonized"
|
79
|
-
end
|
80
|
-
|
81
|
-
def daemon
|
82
|
-
exit if fork # Parent exits, child continues.
|
83
|
-
Process.setsid # Become session leader.
|
84
|
-
exit if fork # Zap session leader. See [1].
|
85
|
-
|
86
|
-
STDIN.reopen "/dev/null" # Free file descriptors and
|
87
|
-
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
|
88
|
-
STDERR.reopen '/dev/null', 'a'
|
89
|
-
return 0
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
extend Sample
|
94
|
-
|
95
|
-
if options[:daemonize]
|
96
|
-
daemonize(options[:pid_file], options[:log_file], options[:daemonize_delay])
|
97
|
-
end
|
98
|
-
|
99
|
-
puts "Started #{ARGV.inspect}, #{options.inspect}, #{ENV["ENV1"]}"
|
100
|
-
|
101
|
-
if options[:lock_file]
|
102
|
-
if File.exists?(options[:lock_file])
|
103
|
-
puts "Lock file exists, exiting"
|
104
|
-
exit 1
|
105
|
-
else
|
106
|
-
File.open(options[:lock_file], 'w'){|f| f.write $$ }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
if options[:raise]
|
111
|
-
puts "Raised"
|
112
|
-
File.unlink(options[:lock_file]) if options[:lock_file]
|
113
|
-
exit 1
|
114
|
-
end
|
115
|
-
|
116
|
-
trap("USR1") do
|
117
|
-
puts "USR1 signal!"
|
118
|
-
end
|
119
|
-
|
120
|
-
trap("USR2") do
|
121
|
-
puts "USR2 start memory leak"
|
122
|
-
$ar = []
|
123
|
-
300_000.times{|i| $ar << "memory leak #{i}" * 10}
|
124
|
-
end
|
125
|
-
|
126
|
-
if options[:no_terminate]
|
127
|
-
trap("TERM") do
|
128
|
-
puts "TERM signal! and we not die O_o"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
loop do
|
133
|
-
sleep 0.1
|
134
|
-
puts "tick"
|
135
|
-
|
136
|
-
if options[:watch_file]
|
137
|
-
if File.exists?(options[:watch_file])
|
138
|
-
puts "watch file finded"
|
139
|
-
File.unlink(options[:watch_file])
|
140
|
-
|
141
|
-
if options[:watch_file_delay]
|
142
|
-
puts "watch_file delay start"
|
143
|
-
sleep options[:watch_file_delay].to_f
|
144
|
-
puts "watch_file delay end"
|
145
|
-
end
|
146
|
-
|
147
|
-
break
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
puts "exit"
|
153
|
-
File.unlink(options[:lock_file]) if options[:lock_file]
|
154
|
-
exit 0
|