poise-service 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -3
- data/README.md +25 -0
- data/chef/templates/default/inittab.sh.erb +15 -0
- data/lib/poise_service/service_providers.rb +1 -0
- data/lib/poise_service/service_providers/inittab.rb +150 -0
- data/lib/poise_service/version.rb +1 -1
- data/test/cookbooks/poise-service_test/recipes/default.rb +8 -0
- data/test/integration/default/serverspec/default_spec.rb +4 -0
- data/test/spec/service_providers/inittab_spec.rb +288 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe7845772574fbc6fe57ffb8acaa41fe59e7c9f
|
4
|
+
data.tar.gz: 03e35f8aabba36c7ebbb775672b3491e2b65d55a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4adb8f04f30a3c8a00c4cbf87413c69ece21f64bc23ea468c8a149f6aea6547261ed04aa59b09c2091d9b2895d0ab6478dac656f68cccd83e80fb87e69bb8cd
|
7
|
+
data.tar.gz: 189e48201d52da6f2ad5c4e77d9580ad6a981258fc5392b93a3ea557b1b570e0f36249d8b37b574bf15756532de8a645dc085c47dff0d9332940773f5497d1c9
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -319,6 +319,31 @@ end
|
|
319
319
|
* `never_reload` – Never try to reload the service.
|
320
320
|
* `auto_reload` – Run `systemctl daemon-reload` after changes to the unit file. *(default: true)*
|
321
321
|
|
322
|
+
### `inittab`
|
323
|
+
|
324
|
+
The `inittab` provider supports managing services via `/etc/inittab` using
|
325
|
+
[SystemV Init](http://www.nongnu.org/sysvinit/). This can provide basic
|
326
|
+
process supervision even on very old *nix machines.
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
poise_service 'myapp' do
|
330
|
+
provider :inittab
|
331
|
+
command 'myapp --serve'
|
332
|
+
end
|
333
|
+
```
|
334
|
+
|
335
|
+
**NOTE:** Inittab does not allow stopping services, and they are started as soon
|
336
|
+
as they are enabled.
|
337
|
+
|
338
|
+
#### Options
|
339
|
+
|
340
|
+
* `never_restart` – Never try to restart the service.
|
341
|
+
* `never_reload` – Never try to reload the service.
|
342
|
+
* `pid_file` – Path to PID file that the service command will create.
|
343
|
+
* `service_id` – Unique 1-4 character tag for the service. Defaults to an
|
344
|
+
auto-generated hash based on the service name. If these collide, bad things
|
345
|
+
happen. Don't do that.
|
346
|
+
|
322
347
|
## ServiceMixin
|
323
348
|
|
324
349
|
For the common case of a resource (LWRP or plain Ruby) that roughly maps to
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
exec /opt/chef/embedded/bin/ruby <<EOH
|
3
|
+
require 'etc'
|
4
|
+
IO.write("<%= @pid_file %>", Process.pid)
|
5
|
+
Dir.chdir("<%= @directory %>")
|
6
|
+
ent = Etc.getpwnam("<%= @user %>")
|
7
|
+
if Process.euid != ent.uid || Process.egid != ent.gid
|
8
|
+
Process.initgroups(ent.name, ent.gid)
|
9
|
+
Process::GID.change_privilege(ent.gid) if Process.egid != ent.gid
|
10
|
+
Process::UID.change_privilege(ent.uid) if Process.euid != ent.uid
|
11
|
+
end
|
12
|
+
(ENV["HOME"] = Dir.home("<%= @user %>")) rescue nil
|
13
|
+
<%= @environment.map {|key, value| "ENV[\"#{key}\"] = \"#{value}\"" }.join("; ") %>
|
14
|
+
exec(*<%= Shellwords.split(@command).inspect %>)
|
15
|
+
EOH
|
@@ -17,6 +17,7 @@
|
|
17
17
|
require 'chef/platform/provider_priority_map'
|
18
18
|
|
19
19
|
require 'poise_service/service_providers/dummy'
|
20
|
+
require 'poise_service/service_providers/inittab'
|
20
21
|
require 'poise_service/service_providers/systemd'
|
21
22
|
require 'poise_service/service_providers/sysvinit'
|
22
23
|
require 'poise_service/service_providers/upstart'
|
@@ -0,0 +1,150 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'chef/util/file_edit'
|
18
|
+
|
19
|
+
require 'poise_service/service_providers/base'
|
20
|
+
|
21
|
+
|
22
|
+
module PoiseService
|
23
|
+
module ServiceProviders
|
24
|
+
class Inittab < Base
|
25
|
+
provides(:inittab)
|
26
|
+
|
27
|
+
def self.provides_auto?(node, resource)
|
28
|
+
::File.exist?('/etc/inittab')
|
29
|
+
end
|
30
|
+
|
31
|
+
def pid
|
32
|
+
IO.read(pid_file).to_i if ::File.exist?(pid_file)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Don't try to stop when disabling because we can't.
|
36
|
+
def action_disable
|
37
|
+
disable_service
|
38
|
+
notifying_block do
|
39
|
+
destroy_service
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def action_start
|
44
|
+
Chef::Log.debug("[#{new_resource}] Inittab services are always started.")
|
45
|
+
end
|
46
|
+
|
47
|
+
def action_stop
|
48
|
+
raise NotImplementedError.new("[#{new_resource}] Inittab services cannot be stopped")
|
49
|
+
end
|
50
|
+
|
51
|
+
def action_restart
|
52
|
+
return if options['never_restart']
|
53
|
+
# Just kill it and let init restart it.
|
54
|
+
Process.kill(new_resource.stop_signal, pid) if pid
|
55
|
+
end
|
56
|
+
|
57
|
+
def action_reload
|
58
|
+
return if options['never_reload']
|
59
|
+
Process.kill(new_resource.reload_signal, pid) if pid
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def service_resource
|
65
|
+
# Intentionally not implemented.
|
66
|
+
raise NotImplementedError
|
67
|
+
end
|
68
|
+
|
69
|
+
def enable_service
|
70
|
+
end
|
71
|
+
|
72
|
+
def disable_service
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_service
|
76
|
+
# Sigh scoping.
|
77
|
+
pid_file_ = pid_file
|
78
|
+
# Inittab only allows 127 characters for the command, so cram stuff in
|
79
|
+
# a file. Writing to a file is gross, but so is using inittab so ¯\_(ツ)_/¯.
|
80
|
+
service_template("/sbin/poise_service_#{new_resource.service_name}", 'inittab.sh.erb') do
|
81
|
+
mode '755'
|
82
|
+
variables.update(
|
83
|
+
pid_file: pid_file_,
|
84
|
+
)
|
85
|
+
end
|
86
|
+
# Add to inittab.
|
87
|
+
edit_inittab do |content|
|
88
|
+
inittab_line = "#{service_id}:2345:respawn:/sbin/poise_service_#{new_resource.service_name}"
|
89
|
+
if content =~ /^# #{Regexp.escape(service_tag)}$/
|
90
|
+
# Existing line, update in place.
|
91
|
+
content.gsub!(/^(# #{Regexp.escape(service_tag)}\n)(.*)$/, "\\1#{inittab_line}")
|
92
|
+
else
|
93
|
+
# Add to the end.
|
94
|
+
content << "# #{service_tag}\n#{inittab_line}\n"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def destroy_service
|
100
|
+
# Remove from inittab.
|
101
|
+
edit_inittab do |content|
|
102
|
+
content.gsub!(/^# #{Regexp.escape(service_tag)}\n.*?\n$/, '')
|
103
|
+
end
|
104
|
+
|
105
|
+
file "/sbin/poise_service_#{new_resource.service_name}" do
|
106
|
+
action :delete
|
107
|
+
end
|
108
|
+
|
109
|
+
file pid_file do
|
110
|
+
action :delete
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# The shortened ID because sysvinit only allows 4 characters.
|
115
|
+
def service_id
|
116
|
+
# This is a terrible hash, but it should be good enough.
|
117
|
+
options['service_id'] || begin
|
118
|
+
sum = new_resource.service_name.sum(20).to_s(36)
|
119
|
+
if sum.length < 4
|
120
|
+
'p' + sum
|
121
|
+
else
|
122
|
+
sum
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Tag to put in a comment in inittab for tracking.
|
128
|
+
def service_tag
|
129
|
+
"poise_service(#{new_resource.service_name})"
|
130
|
+
end
|
131
|
+
|
132
|
+
def pid_file
|
133
|
+
options['pid_file'] || "/var/run/#{new_resource.service_name}.pid"
|
134
|
+
end
|
135
|
+
|
136
|
+
def edit_inittab(&block)
|
137
|
+
inittab = IO.read('/etc/inittab')
|
138
|
+
original_inittab = inittab.dup
|
139
|
+
block.call(inittab)
|
140
|
+
if inittab != original_inittab
|
141
|
+
file '/etc/inittab' do
|
142
|
+
content inittab
|
143
|
+
end
|
144
|
+
|
145
|
+
execute 'telinit q'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -24,6 +24,7 @@ end
|
|
24
24
|
if node['platform_family'] == 'rhel' && node['platform_version'].start_with?('7')
|
25
25
|
file '/no_sysvinit'
|
26
26
|
file '/no_upstart'
|
27
|
+
file '/no_inittab'
|
27
28
|
|
28
29
|
poise_service_test 'systemd' do
|
29
30
|
service_provider :systemd
|
@@ -39,7 +40,14 @@ else
|
|
39
40
|
|
40
41
|
if node['platform_family'] == 'rhel' && node['platform_version'].start_with?('5')
|
41
42
|
file '/no_upstart'
|
43
|
+
|
44
|
+
poise_service_test 'inittab' do
|
45
|
+
service_provider :inittab
|
46
|
+
base_port 10000
|
47
|
+
end
|
42
48
|
else
|
49
|
+
file '/no_inittab'
|
50
|
+
|
43
51
|
poise_service_test 'upstart' do
|
44
52
|
service_provider :upstart
|
45
53
|
base_port 7000
|
@@ -43,3 +43,7 @@ end
|
|
43
43
|
describe 'dummy provider' do
|
44
44
|
it_should_behave_like 'a poise_service_test', 'dummy', 9000, false
|
45
45
|
end
|
46
|
+
|
47
|
+
describe 'inittab provider', unless: File.exist?('/no_inittab') do
|
48
|
+
it_should_behave_like 'a poise_service_test', 'inittab', 10000, false
|
49
|
+
end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe PoiseService::ServiceProviders::Inittab do
|
20
|
+
service_provider('inittab')
|
21
|
+
step_into(:poise_service)
|
22
|
+
let(:inittab) { '' }
|
23
|
+
before do
|
24
|
+
allow(IO).to receive(:read).and_call_original
|
25
|
+
allow(IO).to receive(:read).with('/etc/inittab').and_return(inittab)
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with action :enable' do
|
29
|
+
recipe do
|
30
|
+
poise_service 'test' do
|
31
|
+
command 'myapp --serve'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it { is_expected.to render_file('/sbin/poise_service_test').with_content(<<-EOS) }
|
36
|
+
#!/bin/sh
|
37
|
+
exec /opt/chef/embedded/bin/ruby <<EOH
|
38
|
+
require 'etc'
|
39
|
+
IO.write("/var/run/test.pid", Process.pid)
|
40
|
+
Dir.chdir("/")
|
41
|
+
ent = Etc.getpwnam("root")
|
42
|
+
if Process.euid != ent.uid || Process.egid != ent.gid
|
43
|
+
Process.initgroups(ent.name, ent.gid)
|
44
|
+
Process::GID.change_privilege(ent.gid) if Process.egid != ent.gid
|
45
|
+
Process::UID.change_privilege(ent.uid) if Process.euid != ent.uid
|
46
|
+
end
|
47
|
+
(ENV["HOME"] = Dir.home("root")) rescue nil
|
48
|
+
|
49
|
+
exec(*["myapp", "--serve"])
|
50
|
+
EOH
|
51
|
+
EOS
|
52
|
+
|
53
|
+
context 'with an empty inittab' do
|
54
|
+
it { is_expected.to render_file('/etc/inittab').with_content(eq(<<-EOH)) }
|
55
|
+
# poise_service(test)
|
56
|
+
pcg:2345:respawn:/sbin/poise_service_test
|
57
|
+
EOH
|
58
|
+
end # /context with an empty inittab
|
59
|
+
|
60
|
+
context 'with a normal inittab' do
|
61
|
+
let(:inittab) { <<-EOH }
|
62
|
+
# Run gettys in standard runlevels
|
63
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
64
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
65
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
66
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
67
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
68
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
69
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
70
|
+
|
71
|
+
# Run xdm in runlevel 5
|
72
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
73
|
+
EOH
|
74
|
+
|
75
|
+
it { is_expected.to render_file('/etc/inittab').with_content(eq(<<-EOH)) }
|
76
|
+
# Run gettys in standard runlevels
|
77
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
78
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
79
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
80
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
81
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
82
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
83
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
84
|
+
|
85
|
+
# Run xdm in runlevel 5
|
86
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
87
|
+
# poise_service(test)
|
88
|
+
pcg:2345:respawn:/sbin/poise_service_test
|
89
|
+
EOH
|
90
|
+
end # /context with a normal inittab
|
91
|
+
|
92
|
+
context 'with an existing line' do
|
93
|
+
let(:inittab) { <<-EOH }
|
94
|
+
# Run gettys in standard runlevels
|
95
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
96
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
97
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
98
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
99
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
100
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
101
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
102
|
+
|
103
|
+
# Run xdm in runlevel 5
|
104
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
105
|
+
# poise_service(test)
|
106
|
+
pcg:2345:respawn:/sbin/poise_service_test2
|
107
|
+
EOH
|
108
|
+
|
109
|
+
it { is_expected.to render_file('/etc/inittab').with_content(eq(<<-EOH)) }
|
110
|
+
# Run gettys in standard runlevels
|
111
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
112
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
113
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
114
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
115
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
116
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
117
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
118
|
+
|
119
|
+
# Run xdm in runlevel 5
|
120
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
121
|
+
# poise_service(test)
|
122
|
+
pcg:2345:respawn:/sbin/poise_service_test
|
123
|
+
EOH
|
124
|
+
end # /context with an existing line
|
125
|
+
|
126
|
+
context 'with an existing line that matches' do
|
127
|
+
let(:inittab) { <<-EOH }
|
128
|
+
# Run gettys in standard runlevels
|
129
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
130
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
131
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
132
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
133
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
134
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
135
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
136
|
+
|
137
|
+
# Run xdm in runlevel 5
|
138
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
139
|
+
# poise_service(test)
|
140
|
+
pcg:2345:respawn:/sbin/poise_service_test
|
141
|
+
EOH
|
142
|
+
|
143
|
+
it { is_expected.to_not render_file('/etc/inittab') }
|
144
|
+
end # /context with an existing line that matches
|
145
|
+
|
146
|
+
context 'with a long service_id' do
|
147
|
+
recipe do
|
148
|
+
poise_service 'a'*1000 do
|
149
|
+
command 'myapp --serve'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
it { is_expected.to render_file('/etc/inittab').with_content(eq(<<-EOH)) }
|
153
|
+
# poise_service(#{'a'*1000})
|
154
|
+
22ug:2345:respawn:/sbin/poise_service_#{'a'*1000}
|
155
|
+
EOH
|
156
|
+
end # /context with a long service_id
|
157
|
+
end # /context with action :enable
|
158
|
+
|
159
|
+
context 'with action :disable' do
|
160
|
+
recipe do
|
161
|
+
poise_service 'test' do
|
162
|
+
action :disable
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it { is_expected.to delete_file('/sbin/poise_service_test') }
|
167
|
+
it { is_expected.to delete_file('/var/run/test.pid') }
|
168
|
+
|
169
|
+
context 'with an empty inittab' do
|
170
|
+
it { is_expected.to_not render_file('/etc/inittab') }
|
171
|
+
end # /context with an empty inittab
|
172
|
+
|
173
|
+
context 'with a normal inittab' do
|
174
|
+
let(:inittab) { <<-EOH }
|
175
|
+
# Run gettys in standard runlevels
|
176
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
177
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
178
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
179
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
180
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
181
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
182
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
183
|
+
|
184
|
+
# Run xdm in runlevel 5
|
185
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon=
|
186
|
+
EOH
|
187
|
+
|
188
|
+
it { is_expected.to_not render_file('/etc/inittab') }
|
189
|
+
end # /context with a normal inittab
|
190
|
+
|
191
|
+
context 'with an existing line' do
|
192
|
+
let(:inittab) { <<-EOH }
|
193
|
+
# Run gettys in standard runlevels
|
194
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
195
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
196
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
197
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
198
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
199
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
200
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
201
|
+
|
202
|
+
# Run xdm in runlevel 5
|
203
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
204
|
+
# poise_service(test)
|
205
|
+
pcg:2345:respawn:/sbin/poise_service_test2
|
206
|
+
EOH
|
207
|
+
|
208
|
+
it { is_expected.to render_file('/etc/inittab').with_content(eq(<<-EOH)) }
|
209
|
+
# Run gettys in standard runlevels
|
210
|
+
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
211
|
+
#1:2345:respawn:/sbin/mingetty tty1
|
212
|
+
#2:2345:respawn:/sbin/mingetty tty2
|
213
|
+
#3:2345:respawn:/sbin/mingetty tty3
|
214
|
+
#4:2345:respawn:/sbin/mingetty tty4
|
215
|
+
#5:2345:respawn:/sbin/mingetty tty5
|
216
|
+
#6:2345:respawn:/sbin/mingetty tty6
|
217
|
+
|
218
|
+
# Run xdm in runlevel 5
|
219
|
+
x:5:respawn:/etc/X11/prefdm -nodaemon
|
220
|
+
EOH
|
221
|
+
end # /context with an existing line
|
222
|
+
end # /context with action :disable
|
223
|
+
|
224
|
+
context 'with action :stop' do
|
225
|
+
recipe do
|
226
|
+
poise_service 'test' do
|
227
|
+
action :stop
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
it { expect { subject }.to raise_error NotImplementedError }
|
232
|
+
end # /context with action :stop
|
233
|
+
|
234
|
+
context 'with action :restart' do
|
235
|
+
recipe do
|
236
|
+
poise_service 'test' do
|
237
|
+
action :restart
|
238
|
+
end
|
239
|
+
end
|
240
|
+
before do
|
241
|
+
allow(File).to receive(:exist?).and_call_original
|
242
|
+
allow(File).to receive(:exist?).with('/var/run/test.pid').and_return(true)
|
243
|
+
allow(IO).to receive(:read).and_call_original
|
244
|
+
allow(IO).to receive(:read).with('/var/run/test.pid').and_return('100')
|
245
|
+
end
|
246
|
+
|
247
|
+
it do
|
248
|
+
expect(Process).to receive(:kill).with('TERM', 100)
|
249
|
+
run_chef
|
250
|
+
end
|
251
|
+
end # /context with action :restart
|
252
|
+
|
253
|
+
context 'with action :reload' do
|
254
|
+
recipe do
|
255
|
+
poise_service 'test' do
|
256
|
+
action :reload
|
257
|
+
end
|
258
|
+
end
|
259
|
+
before do
|
260
|
+
allow(File).to receive(:exist?).and_call_original
|
261
|
+
allow(File).to receive(:exist?).with('/var/run/test.pid').and_return(true)
|
262
|
+
allow(IO).to receive(:read).and_call_original
|
263
|
+
allow(IO).to receive(:read).with('/var/run/test.pid').and_return('100')
|
264
|
+
end
|
265
|
+
|
266
|
+
it do
|
267
|
+
expect(Process).to receive(:kill).with('HUP', 100)
|
268
|
+
run_chef
|
269
|
+
end
|
270
|
+
end # /context with action :reload
|
271
|
+
|
272
|
+
describe '#pid' do
|
273
|
+
subject { described_class.new(nil, nil) }
|
274
|
+
before do
|
275
|
+
allow(File).to receive(:exist?).and_call_original
|
276
|
+
allow(File).to receive(:exist?).with('/pid').and_return(true)
|
277
|
+
allow(IO).to receive(:read).and_call_original
|
278
|
+
allow(IO).to receive(:read).with('/pid').and_return('100')
|
279
|
+
expect(subject).to receive(:pid_file).and_return('/pid').at_least(:once)
|
280
|
+
end
|
281
|
+
its(:pid) { is_expected.to eq 100 }
|
282
|
+
end # /describe #pid
|
283
|
+
|
284
|
+
describe '#service_resource' do
|
285
|
+
subject { described_class.new(nil, nil).send(:service_resource) }
|
286
|
+
it { expect { subject }.to raise_error NotImplementedError }
|
287
|
+
end # /describe #service_resource
|
288
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poise-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Kantrowitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: halite
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- chef/attributes/default.rb
|
88
88
|
- chef/templates/default/dummy.json.erb
|
89
|
+
- chef/templates/default/inittab.sh.erb
|
89
90
|
- chef/templates/default/systemd.service.erb
|
90
91
|
- chef/templates/default/sysvinit.sh.erb
|
91
92
|
- chef/templates/default/upstart.conf.erb
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- lib/poise_service/service_providers.rb
|
101
102
|
- lib/poise_service/service_providers/base.rb
|
102
103
|
- lib/poise_service/service_providers/dummy.rb
|
104
|
+
- lib/poise_service/service_providers/inittab.rb
|
103
105
|
- lib/poise_service/service_providers/systemd.rb
|
104
106
|
- lib/poise_service/service_providers/sysvinit.rb
|
105
107
|
- lib/poise_service/service_providers/upstart.rb
|
@@ -121,6 +123,7 @@ files:
|
|
121
123
|
- test/spec/service_mixin_spec.rb
|
122
124
|
- test/spec/service_providers/base_spec.rb
|
123
125
|
- test/spec/service_providers/dummy_spec.rb
|
126
|
+
- test/spec/service_providers/inittab_spec.rb
|
124
127
|
- test/spec/service_providers/systemd_spec.rb
|
125
128
|
- test/spec/service_providers/sysvinit_spec.rb
|
126
129
|
- test/spec/service_providers/upstart_spec.rb
|
@@ -166,6 +169,7 @@ test_files:
|
|
166
169
|
- test/spec/service_mixin_spec.rb
|
167
170
|
- test/spec/service_providers/base_spec.rb
|
168
171
|
- test/spec/service_providers/dummy_spec.rb
|
172
|
+
- test/spec/service_providers/inittab_spec.rb
|
169
173
|
- test/spec/service_providers/systemd_spec.rb
|
170
174
|
- test/spec/service_providers/sysvinit_spec.rb
|
171
175
|
- test/spec/service_providers/upstart_spec.rb
|