foreground 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # Files
4
- pid_file = "/tmp/#{File.basename($PROGRAM_NAME)}.pid"
5
- log_file = "/tmp/#{File.basename($PROGRAM_NAME)}.log"
4
+ name = File.basename($PROGRAM_NAME)
5
+ $PROGRAM_NAME=name
6
+ pid_file = "/tmp/#{name}.pid"
7
+ log_file = "/tmp/#{name}.log"
6
8
 
7
9
  # Run only run one daemon at a time.
8
10
  if File.exists?(pid_file)
9
- puts "PID file exists already!"
11
+ File.open(log_file, 'a') { |f| f.puts "PID file exists already!" }
10
12
  exit
11
13
  end
12
14
 
@@ -4,12 +4,28 @@ Feature: Start and stop
4
4
  As a funky user
5
5
  I want foreground to start and stop that background daemon
6
6
 
7
- Scenario: Start and stop sample daemon
7
+ Scenario: Run sample daemon via foreground
8
8
  When I run the sample daemon via foreground
9
- Then the sample daemon should run
9
+ Then foreground should run
10
+ And the sample daemon should run
10
11
 
11
- When I kill foreground
12
+ Scenario Outline: Kill sample daemon via foreground
13
+ Given I run the sample daemon via foreground
14
+ When I send foreground a <signal> signal
12
15
  And I run `sleep 1`
13
16
  Then foreground should not run
14
17
  And the sample daemon should not run
15
18
  And the sample daemon should have received a TERM signal
19
+
20
+ Examples:
21
+ | signal |
22
+ | TERM |
23
+ | INT |
24
+
25
+ Scenario: Refresh sample daemon via foreground
26
+ Given I run the sample daemon via foreground
27
+ When I send foreground a HUP signal
28
+ And I run `sleep 1`
29
+ Then foreground should run
30
+ And the sample daemon should run
31
+ And the sample daemon should have received a HUP signal
@@ -2,14 +2,20 @@ STDOUT.sync = true # for debugging
2
2
 
3
3
  def sample_daemons
4
4
  proclist = `/bin/ps -A -o pid,command`
5
- proclist.to_a.grep(%r{^\s*\d+\s+ruby\s+.*foreground_sample_daemon$}) { |l| l[/^\s*(\d+)\s+/,1].to_i }
5
+ proclist.to_a.grep(%r{^\s*\d+\s+foreground_sample_daemon\s*$}) { |l| l[/^\s*(\d+)\s+/,1].to_i }
6
6
  end
7
7
 
8
- def kill_foreground
8
+ def kill_foreground(signal = :TERM)
9
9
  if @foreground
10
+ #TODO: Replace sleep with a timeout!
11
+ sleep 2 # Give foreground some time to setup signal handling... or tests might break.
10
12
  begin
11
- Process.kill(:TERM, @foreground)
12
- Process.waitpid(@foreground)
13
+ Process.kill(signal, @foreground)
14
+ if signal.to_sym == :HUP
15
+ sleep 1
16
+ else
17
+ Process.waitpid(@foreground)
18
+ end
13
19
  rescue Errno::ESRCH, Errno::ECHILD
14
20
  end
15
21
  end
@@ -17,6 +23,7 @@ end
17
23
 
18
24
  def kill_all_sample_daemons(signal=:TERM)
19
25
  sample_daemons.each { |pid| system("kill -#{signal} #{pid}") }
26
+ #TODO: Replace sleep with a timeout!
20
27
  sleep 1 # Give the process time to say goodbye.
21
28
  end
22
29
 
@@ -46,8 +53,18 @@ When /^I send the sample daemon a (\w+) signal$/ do |signal|
46
53
  end
47
54
 
48
55
  When /^I kill foreground$/ do
49
- sleep 1 # Give foreground some time to setup signal handling... or tests will break.
50
- kill_foreground
56
+ steps %q{
57
+ When I send foreground a TERM signal
58
+ }
59
+ end
60
+
61
+ When /^I send foreground a (\w+) signal$/ do |signal|
62
+ kill_foreground(signal)
63
+ end
64
+
65
+ Then /^foreground should run$/ do
66
+ lambda { Process.kill(0, @foreground) }.should_not raise_error(Errno::ESRCH),
67
+ "No such foreground process with PID #{@foreground}"
51
68
  end
52
69
 
53
70
  Then /^foreground should not run$/ do
@@ -70,6 +87,8 @@ Then /^the sample daemon should not run$/ do
70
87
  end
71
88
 
72
89
  Then /^(\d+) sample daemons? should run$/ do |expected|
90
+ #TODO: Replace sleep with a timeout!
91
+ sleep 2 # some time to start the daemon
73
92
  expected = expected.to_i
74
93
  actual = sample_daemons.count
75
94
  actual.should eql(expected),
@@ -1,6 +1,13 @@
1
1
  module Foreground
2
- trap(:TERM) do
3
- Daemon.kill(:TERM)
4
- exit
2
+ [:TERM, :INT].each do |signal|
3
+ trap(signal) do
4
+ Daemon.kill(:TERM)
5
+ exit
6
+ end
7
+ end
8
+
9
+ trap(:HUP) do
10
+ sleep 1
11
+ Daemon.kill(:HUP)
5
12
  end
6
13
  end
@@ -1,3 +1,3 @@
1
1
  module Foreground
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,143 +1,137 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: foreground
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
13
- - "Bjo\xCC\x88rn Albers"
7
+ authors:
8
+ - Björn Albers
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-08 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mixlib-cli
16
+ requirement: !ruby/object:Gem::Requirement
22
17
  none: false
23
- requirements:
18
+ requirements:
24
19
  - - ~>
25
- - !ruby/object:Gem::Version
26
- hash: 27
27
- segments:
28
- - 1
29
- - 2
30
- - 2
20
+ - !ruby/object:Gem::Version
31
21
  version: 1.2.2
32
- prerelease: false
33
22
  type: :runtime
34
- name: mixlib-cli
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 25
43
- segments:
44
- - 0
45
- - 4
46
- - 11
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: aruba
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
47
37
  version: 0.4.11
48
- prerelease: false
49
38
  type: :development
50
- name: aruba
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
54
41
  none: false
55
- requirements:
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.11
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba-doubles
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
56
51
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 29
59
- segments:
60
- - 1
61
- - 2
62
- - 1
52
+ - !ruby/object:Gem::Version
63
53
  version: 1.2.1
64
- prerelease: false
65
54
  type: :development
66
- name: aruba-doubles
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 9
75
- segments:
76
- - 0
77
- - 7
78
- - 5
79
- version: 0.7.5
80
55
  prerelease: false
81
- type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ - !ruby/object:Gem::Dependency
82
63
  name: guard-cucumber
83
- version_requirements: *id004
84
- - !ruby/object:Gem::Dependency
85
- requirement: &id005 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
86
65
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 9
91
- segments:
92
- - 0
93
- - 5
94
- - 1
95
- version: 0.5.1
96
- prerelease: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.7.5
97
70
  type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.7.5
78
+ - !ruby/object:Gem::Dependency
98
79
  name: guard-rspec
99
- version_requirements: *id005
100
- - !ruby/object:Gem::Dependency
101
- requirement: &id006 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
102
81
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
108
- - 0
109
- version: "0"
110
- prerelease: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.5.1
111
86
  type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.5.1
94
+ - !ruby/object:Gem::Dependency
112
95
  name: rake
113
- version_requirements: *id006
114
- - !ruby/object:Gem::Dependency
115
- requirement: &id007 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
116
97
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 59
121
- segments:
122
- - 0
123
- - 9
124
- - 0
125
- version: 0.9.0
126
- prerelease: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
127
102
  type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
128
111
  name: rb-fsevent
129
- version_requirements: *id007
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 0.9.0
130
126
  description: Control daemonizing background processes with launchd.
131
- email:
127
+ email:
132
128
  - bjoernalbers@googlemail.com
133
- executables:
129
+ executables:
134
130
  - foreground
135
131
  - foreground_sample_daemon
136
132
  extensions: []
137
-
138
133
  extra_rdoc_files: []
139
-
140
- files:
134
+ files:
141
135
  - .gitignore
142
136
  - Gemfile
143
137
  - Guardfile
@@ -162,38 +156,35 @@ files:
162
156
  - spec/spec_helper.rb
163
157
  homepage: https://github.com/bjoernalbers/foreground
164
158
  licenses: []
165
-
166
159
  post_install_message:
167
160
  rdoc_options: []
168
-
169
- require_paths:
161
+ require_paths:
170
162
  - lib
171
- required_ruby_version: !ruby/object:Gem::Requirement
163
+ required_ruby_version: !ruby/object:Gem::Requirement
172
164
  none: false
173
- requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- hash: 3
177
- segments:
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ segments:
178
170
  - 0
179
- version: "0"
180
- required_rubygems_version: !ruby/object:Gem::Requirement
171
+ hash: -3093177780394288803
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
173
  none: false
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- hash: 3
186
- segments:
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ segments:
187
179
  - 0
188
- version: "0"
180
+ hash: -3093177780394288803
189
181
  requirements: []
190
-
191
182
  rubyforge_project:
192
183
  rubygems_version: 1.8.24
193
184
  signing_key:
194
185
  specification_version: 3
195
- summary: foreground-0.0.3
196
- test_files:
186
+ summary: foreground-0.0.4
187
+ test_files:
197
188
  - features/sample_daemon.feature
198
189
  - features/start_stop.feature
199
190
  - features/steps/sample_daemon_steps.rb