chef-container 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/chef-container.gemspec +23 -0
- data/lib/chef/container.rb +23 -0
- data/lib/chef/container/runit.rb +106 -0
- data/lib/chef/container/version.rb +5 -0
- data/lib/chef/provider/service/chef_container.rb +100 -0
- data/spec/container_init_recipe_spec.rb +61 -0
- data/spec/container_init_resource_spec.rb +0 -0
- data/spec/data/cookbooks/foo/metadata.rb +1 -0
- data/spec/data/cookbooks/foo/recipes/default.rb +10 -0
- data/spec/spec_helper.rb +23 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6fc12321d54dbb1a3a9900f6ff3c413b37abde82
|
4
|
+
data.tar.gz: 3ec5ee8c121b5004b3d9921f3d6ba450664817e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b250a250bbbe7acf170c889f109eedbab47a2c5260d496c71087d09e0dd6e35aa5fab4f074159902110e1d893c215a8e8cfc94cb868086d7fa678b230f9c06a
|
7
|
+
data.tar.gz: 411b0a469251abdf85f89bf2adf201235bb921f32b6f94c5a108d6e921779e77f4278289c1b420491e7982203b7b56dde6f90e4ffd9ebebb5ada6102cc0ef2b9
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tom Duffield
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Chef::Container
|
2
|
+
|
3
|
+
A library for controlling services using Chef's chef-container package.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'chef-container'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install chef-container
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/chef-container/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chef/container/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chef-container"
|
8
|
+
spec.version = Chef::Container::VERSION
|
9
|
+
spec.authors = ["Tom Duffield"]
|
10
|
+
spec.email = ["tom@getchef.com"]
|
11
|
+
spec.summary = %q{A library for controlling services using Chef's chef-container package.}
|
12
|
+
spec.description = %q{This library adds the `container_init` Chef resource. Using this resource allows you to hijack service resources and use the runit installation included with chef-container.}
|
13
|
+
spec.homepage = "https://github.com/opscode/chef-container"
|
14
|
+
spec.license = "Apache 2.0"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'chef/container/version'
|
2
|
+
require 'chef/provider/service/chef_container'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Recipe
|
6
|
+
def container_init(name, &block)
|
7
|
+
begin
|
8
|
+
# Find the corresponding `service` resource and override the provider
|
9
|
+
@service_resource = resources("service[#{name}]")
|
10
|
+
@orig_provider = @service_resource.provider
|
11
|
+
@service_resource.provider = Chef::Provider::Service::ChefContainer
|
12
|
+
rescue Chef::Exceptions::ResourceNotFound => e
|
13
|
+
Chef::Log.info "Resource service[#{@service_name}] not found."
|
14
|
+
raise e
|
15
|
+
else
|
16
|
+
# other exception
|
17
|
+
ensure
|
18
|
+
# always executed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
class Chef
|
19
|
+
module Container
|
20
|
+
module Runit
|
21
|
+
attr_reader :sv_bin
|
22
|
+
attr_reader :sv_dir
|
23
|
+
attr_reader :service_dir
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@sv_bin = '/opt/chef/embedded/bin/sv'
|
27
|
+
@sv_dir = '/opt/chef/embedded/sv'
|
28
|
+
@service_dir = '/opt/chef/embedded/service'
|
29
|
+
|
30
|
+
Chef::Log.debug "Creating sv_dir for #{new_resource.name}"
|
31
|
+
sv_dir.run_action(:create)
|
32
|
+
|
33
|
+
Chef::Log.debug "Creating run_script for #{new_resource.name}"
|
34
|
+
run_script.run_action(:create)
|
35
|
+
|
36
|
+
Chef::Log.debug "Setting up svlog for #{new_resource.name}"
|
37
|
+
default_log_dir.run_action(:create)
|
38
|
+
log_dir.run_action(:create)
|
39
|
+
log_run_script.run_action(:create)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Helper Resource Methods
|
44
|
+
#
|
45
|
+
def sv_dir_name
|
46
|
+
::File.join(@service_resource.sv_dir, new_resource.service_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def service_dir_name
|
50
|
+
::File.join(new_resource.service_dir, new_resource.service_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def run_script_content(command)
|
54
|
+
"#!/bin/sh\n#{command} 2&>1"
|
55
|
+
end
|
56
|
+
|
57
|
+
def log_run_script_content
|
58
|
+
"#!/bin/sh\nexec svlogd -tt /var/log/#{new_resource.service_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Helper Resources
|
63
|
+
#
|
64
|
+
def sv_dir
|
65
|
+
return @sv_dir unless @sv_dir.nil?
|
66
|
+
@sv_dir = Chef::Resource::Directory.new(sv_dir_name, run_context)
|
67
|
+
@sv_dir.recursive(true)
|
68
|
+
@sv_dir.mode(00755)
|
69
|
+
@sv_dir
|
70
|
+
end
|
71
|
+
|
72
|
+
def run_script
|
73
|
+
return @run_script unless @run_script.nil?
|
74
|
+
@run_script = Chef::Resource::File.new(::File.join(sv_dir_name, 'run'), run_context)
|
75
|
+
@run_script.content(run_script_content(new_resource.command))
|
76
|
+
@run_script.mode(00755)
|
77
|
+
@run_script
|
78
|
+
end
|
79
|
+
|
80
|
+
def default_log_dir
|
81
|
+
return @default_log_dir unless @default_log_dir.nil?
|
82
|
+
@default_log_dir = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context)
|
83
|
+
@default_log_dir.recursive(true)
|
84
|
+
@default_log_dir.mode(00755)
|
85
|
+
@default_log_dir
|
86
|
+
end
|
87
|
+
|
88
|
+
def log_dir
|
89
|
+
return @log_dir unless @log_dir.nil?
|
90
|
+
@log_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context)
|
91
|
+
@log_dir.recursive(true)
|
92
|
+
@log_dir.mode(00755)
|
93
|
+
@log_dir
|
94
|
+
end
|
95
|
+
|
96
|
+
def log_run_script
|
97
|
+
return @log_run_script unless @log_run_script.nil?
|
98
|
+
@log_run_script = Chef::Resource::File.new(::File.join(sv_dir_name, 'log', 'run'))
|
99
|
+
@log_run_script.content(log_run_script_content)
|
100
|
+
@log_run_script.mode(00755)
|
101
|
+
@log_run_script
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef/provider'
|
19
|
+
require 'chef/provider/service'
|
20
|
+
require 'chef/provider/link'
|
21
|
+
require 'chef/resource/link'
|
22
|
+
require 'chef/mixin/shell_out'
|
23
|
+
require 'chef/mixin/language'
|
24
|
+
require 'chef/container/runit'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Provider
|
28
|
+
class Service
|
29
|
+
class ChefContainer < Chef::Provider::Service
|
30
|
+
include Chef::Container::Runit
|
31
|
+
|
32
|
+
#
|
33
|
+
# Override Service Actions
|
34
|
+
#
|
35
|
+
|
36
|
+
def enable_service
|
37
|
+
Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}")
|
38
|
+
service_link.run_action(:create)
|
39
|
+
|
40
|
+
Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.")
|
41
|
+
until ::FileTest.pipe?("#{service_dir_name}/supervise/ok")
|
42
|
+
sleep 1
|
43
|
+
Chef::Log.debug('.')
|
44
|
+
end
|
45
|
+
|
46
|
+
Chef::Log.debug("waiting until named pipe #{service_dir_name}/log/supervise/ok exists.")
|
47
|
+
until ::FileTest.pipe?("#{service_dir_name}/log/supervise/ok")
|
48
|
+
sleep 1
|
49
|
+
Chef::Log.debug('.')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def disable_service
|
54
|
+
shell_out("#{@sv_bin} down #{service_dir_name}")
|
55
|
+
Chef::Log.debug("#{new_resource} down")
|
56
|
+
FileUtils.rm(service_dir_name)
|
57
|
+
Chef::Log.debug("#{new_resource} service symlink removed")end
|
58
|
+
|
59
|
+
def start_service
|
60
|
+
shell_out!("#{@sv_bin} start #{service_dir_name}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def stop_service
|
64
|
+
shell_out!("#{@sv_bin} stop #{service_dir_name}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def restart_service
|
68
|
+
shell_out!("#{@sv_bin} restart #{service_dir_name}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def reload_service
|
72
|
+
shell_out!("#{@sv_bin} force-reload #{service_dir_name}")
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
#
|
77
|
+
# Helper Resource Methods
|
78
|
+
#
|
79
|
+
def sv_dir_name
|
80
|
+
::File.join(@sv_dir, new_resource.service_name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def service_dir_name
|
84
|
+
::File.join(@service_dir, new_resource.service_name)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
#
|
89
|
+
# Helper Resources
|
90
|
+
#
|
91
|
+
def service_link
|
92
|
+
return @service_link unless @service_link.nil?
|
93
|
+
@service_link = Chef::Resource::Link.new(::File.join(service_dir_name), run_context)
|
94
|
+
@service_link.to(sv_dir_name)
|
95
|
+
@service_link
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
require 'chef/container'
|
20
|
+
|
21
|
+
describe Chef::Recipe do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
@cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
|
25
|
+
cl = Chef::CookbookLoader.new(@cookbook_repo)
|
26
|
+
cl.load_cookbooks
|
27
|
+
@cookbook_collection = Chef::CookbookCollection.new(cl)
|
28
|
+
@node = Chef::Node.new
|
29
|
+
@node.normal[:tags] = Array.new
|
30
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
31
|
+
@run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
|
32
|
+
@recipe = Chef::Recipe.new("foo", "bar", @run_context)
|
33
|
+
|
34
|
+
# Stubs
|
35
|
+
sv_bin = '/opt/chef/embedded/bin/sv'
|
36
|
+
File.stub(:exist?).with(sv_bin).and_return(true)
|
37
|
+
File.stub(:executable?).with(sv_bin).and_return(true)
|
38
|
+
Chef::Mixin::ShellOut.stub(:shell_out).with("#{sv_bin} status /opt/chef/embedded/service/apache2")
|
39
|
+
|
40
|
+
|
41
|
+
# Shell/ext.rb is on the run path, and it defines
|
42
|
+
# Chef::Recipe#resources to call pp, which we don't want when
|
43
|
+
# we're running tests.
|
44
|
+
@recipe.stub(:pp)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "container_init" do
|
48
|
+
it "replaces the provider of the corresponding service resource with Chef::Provider::Service::ChefContainer" do
|
49
|
+
@recipe.service "apache2" do
|
50
|
+
action [:enable, :start]
|
51
|
+
end
|
52
|
+
|
53
|
+
@recipe.container_init "apache2" do
|
54
|
+
action :enable
|
55
|
+
end
|
56
|
+
|
57
|
+
service_resource = @run_context.resource_collection.find("service[apache2]")
|
58
|
+
expect(service_resource.provider).to eql(Chef::Provider::Service::ChefContainer)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
name 'foo'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
require 'chef'
|
18
|
+
require 'chef/recipe'
|
19
|
+
|
20
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
21
|
+
$:.unshift(File.expand_path("../lib", __FILE__))
|
22
|
+
$:.unshift(File.dirname(__FILE__))
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-container
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Duffield
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This library adds the `container_init` Chef resource. Using this resource
|
42
|
+
allows you to hijack service resources and use the runit installation included with
|
43
|
+
chef-container.
|
44
|
+
email:
|
45
|
+
- tom@getchef.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- chef-container.gemspec
|
57
|
+
- lib/chef/container.rb
|
58
|
+
- lib/chef/container/runit.rb
|
59
|
+
- lib/chef/container/version.rb
|
60
|
+
- lib/chef/provider/service/chef_container.rb
|
61
|
+
- spec/container_init_recipe_spec.rb
|
62
|
+
- spec/container_init_resource_spec.rb
|
63
|
+
- spec/data/cookbooks/foo/metadata.rb
|
64
|
+
- spec/data/cookbooks/foo/recipes/default.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/opscode/chef-container
|
67
|
+
licenses:
|
68
|
+
- Apache 2.0
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: A library for controlling services using Chef's chef-container package.
|
90
|
+
test_files:
|
91
|
+
- spec/container_init_recipe_spec.rb
|
92
|
+
- spec/container_init_resource_spec.rb
|
93
|
+
- spec/data/cookbooks/foo/metadata.rb
|
94
|
+
- spec/data/cookbooks/foo/recipes/default.rb
|
95
|
+
- spec/spec_helper.rb
|