poise-service 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.kitchen.travis.yml +4 -0
  4. data/.kitchen.yml +9 -0
  5. data/.travis.yml +23 -0
  6. data/.yardopts +6 -0
  7. data/Berksfile +27 -0
  8. data/Gemfile +33 -0
  9. data/LICENSE +201 -0
  10. data/README.md +381 -0
  11. data/Rakefile +17 -0
  12. data/chef/attributes/default.rb +19 -0
  13. data/chef/templates/systemd.service.erb +13 -0
  14. data/chef/templates/sysvinit.sh.erb +177 -0
  15. data/chef/templates/upstart.conf.erb +37 -0
  16. data/lib/poise_service.rb +25 -0
  17. data/lib/poise_service/cheftie.rb +18 -0
  18. data/lib/poise_service/error.rb +20 -0
  19. data/lib/poise_service/resources.rb +28 -0
  20. data/lib/poise_service/resources/poise_service.rb +161 -0
  21. data/lib/poise_service/resources/poise_service_test.rb +200 -0
  22. data/lib/poise_service/resources/poise_service_user.rb +136 -0
  23. data/lib/poise_service/service_mixin.rb +192 -0
  24. data/lib/poise_service/service_providers.rb +37 -0
  25. data/lib/poise_service/service_providers/base.rb +193 -0
  26. data/lib/poise_service/service_providers/dummy.rb +100 -0
  27. data/lib/poise_service/service_providers/systemd.rb +63 -0
  28. data/lib/poise_service/service_providers/sysvinit.rb +86 -0
  29. data/lib/poise_service/service_providers/upstart.rb +117 -0
  30. data/lib/poise_service/utils.rb +45 -0
  31. data/lib/poise_service/version.rb +19 -0
  32. data/poise-service.gemspec +41 -0
  33. data/test/cookbooks/poise-service_test/metadata.rb +18 -0
  34. data/test/cookbooks/poise-service_test/providers/mixin.rb +43 -0
  35. data/test/cookbooks/poise-service_test/recipes/default.rb +47 -0
  36. data/test/cookbooks/poise-service_test/recipes/mixin.rb +34 -0
  37. data/test/cookbooks/poise-service_test/resources/mixin.rb +26 -0
  38. data/test/gemfiles/chef-12.gemfile +19 -0
  39. data/test/gemfiles/master.gemfile +22 -0
  40. data/test/integration/default/serverspec/Gemfile +19 -0
  41. data/test/integration/default/serverspec/default_spec.rb +45 -0
  42. data/test/integration/default/serverspec/mixin_spec.rb +37 -0
  43. data/test/spec/resources/poise_service_spec.rb +235 -0
  44. data/test/spec/resources/poise_service_user_spec.rb +119 -0
  45. data/test/spec/service_mixin_spec.rb +164 -0
  46. data/test/spec/service_providers/base_spec.rb +231 -0
  47. data/test/spec/service_providers/dummy_spec.rb +91 -0
  48. data/test/spec/service_providers/systemd_spec.rb +98 -0
  49. data/test/spec/service_providers/sysvinit_spec.rb +96 -0
  50. data/test/spec/service_providers/upstart_spec.rb +300 -0
  51. data/test/spec/spec_helper.rb +50 -0
  52. data/test/spec/utils_spec.rb +44 -0
  53. metadata +172 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92c813d92c8af7d4c18ec212f0c9539a535abc42
4
+ data.tar.gz: 655fd28e30903b194a92ca42d68a3c810bf132fe
5
+ SHA512:
6
+ metadata.gz: b3d0af699173014347e5518144b66ea8d89570cb0039c989b3a9ad0fb43612bc72b5c9516ab89e61e9f0f6af8bba92c4a3a29565649cccf74f8b4d48557b7c44
7
+ data.tar.gz: 5b59948c6fe65b14f7904a1c2783a977e31ec3f2fb46b273c1ee3d625ae2eaabec74693da9420b4e0c428b79d0d317045a5c18d98f8495f6203efe2f76a23e80
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .kitchen/
2
+ .kitchen.local.yml
3
+ .vagrant/
4
+ test/docker/
5
+ Gemfile.lock
6
+ Berksfile.lock
7
+ coverage/
8
+ .yardoc/
9
+ doc/
10
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ driver:
3
+ name: rackspace
4
+ flavor_id: general1-1
data/.kitchen.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ #<% require 'poise_boiler' %>
3
+ <%= PoiseBoiler.kitchen(platforms: 'linux') %>
4
+
5
+ suites:
6
+ - name: default
7
+ run_list:
8
+ - recipe[poise-service_test]
9
+ - recipe[poise-service_test::mixin]
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ addons:
5
+ apt:
6
+ packages:
7
+ - libgecode-dev
8
+ rvm:
9
+ - 2.1.4
10
+ env:
11
+ global:
12
+ - USE_SYSTEM_GECODE=true
13
+ - KITCHEN_LOCAL_YAML=.kitchen.travis.yml
14
+ - RACKSPACE_USERNAME=coderanger
15
+ - secure: XpFA4AwBW5v4o3IuwKVSCTeVr6jXsW13T6ShGPpru4q+W2Zpcwh1qyBbxkkIWlkNjbhAT7G0HzQOqYcvUssYLEUYUNSlN10hxjpTZxvVj5sGjjhS3iTXbSop0NXzQthNRHfVZeK9ZWc+zP1MHGImjGCkErkin1+vu/SwMfIl2/8=
16
+ - secure: k36byJyrxjPXKqMjlhojJJwA3iTgVcy1z8zJzUMf0v6JGLsbLbMLfOxkTwIhuLZ3mFEQHvv0TZ8rm84Mg8pYb95fChF2rZNHasRDDB5rFBd++HaYirSC0kndXpZ5gLBhSZXggDv8ROANgKwgWmI0PDDZz96rR/tPDD7edZIvgfc=
17
+ - secure: OZhgvnu2op+rxg6ECSYlWGwaD1xIyOhzQtxqwzA4F/59RiR667JWaSTAmdEDN6SKmrqphxmZatzDEVXLaidbzAC0yAVv7zt4JbkLLZwmLFpq0YL+128sjgI4iUXomJhLxFqZyl8xmDhbu2pZLVyIR0S5Y0VUnu4kTmKDpvBwYsA=
18
+ bundler_args: "--binstubs=$PWD/bin --jobs 3 --retry 3"
19
+ script:
20
+ - "./bin/rake travis"
21
+ gemfile:
22
+ - test/gemfiles/chef-12.gemfile
23
+ - test/gemfiles/master.gemfile
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --plugin classmethods
2
+ --markup markdown
3
+ --hide-api private
4
+ --hide-void-return
5
+ --tag provides:Provides
6
+ --tag action:Actions
data/Berksfile ADDED
@@ -0,0 +1,27 @@
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
+ source 'https://supermarket.chef.io/'
18
+ extension 'halite'
19
+
20
+ # Force the rebuild every time for development.
21
+ cookbook 'poise', gem: 'poise'
22
+ cookbook 'poise-service', gem: 'poise-service'
23
+
24
+ group :test do
25
+ cookbook 'poise-service_test', path: 'test/cookbooks/poise-service_test'
26
+ cookbook 'apt'
27
+ end
data/Gemfile ADDED
@@ -0,0 +1,33 @@
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
+ source 'https://rubygems.org/'
18
+
19
+ gemspec path: File.expand_path('..', __FILE__)
20
+
21
+ def dev_gem(name, path: File.join('..', name))
22
+ path = File.expand_path(File.join('..', path), __FILE__)
23
+ if File.exist?(path)
24
+ gem name, path: path
25
+ end
26
+ end
27
+
28
+ dev_gem 'halite'
29
+ dev_gem 'poise'
30
+ dev_gem 'poise-boiler'
31
+
32
+ # Pending https://github.com/acrmp/foodcritic/pull/312 in a release.
33
+ gem 'foodcritic', github: 'acrmp/foodcritic'
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/README.md ADDED
@@ -0,0 +1,381 @@
1
+ # Poise-Service Cookbook
2
+
3
+ [![Build Status](https://img.shields.io/travis/poise/poise-service.svg)](https://travis-ci.org/poise/poise-service)
4
+ [![Gem Version](https://img.shields.io/gem/v/poise-service.svg)](https://rubygems.org/gems/poise-service)
5
+ [![Cookbook Version](https://img.shields.io/cookbook/v/poise-service.svg)](https://supermarket.chef.io/cookbooks/poise-service)
6
+ [![Coverage](https://img.shields.io/codecov/c/github/poise/poise-service.svg)](https://codecov.io/github/poise/poise-service)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/poise/poise-service.svg)](https://gemnasium.com/poise/poise-service)
8
+ [![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
9
+
10
+ A [Chef](https://www.chef.io/) cookbook to provide a unified interface for
11
+ services.
12
+
13
+ ### What is poise-service?
14
+
15
+ Poise-service is a tool for developers of "library cookbooks" to define a
16
+ service without forcing the end-user of the library to adhere to their choice of
17
+ service management framework. The `poise_service` resource represents an
18
+ abstract service to be run, which can then be customized by node attributes and
19
+ the `poise_service_options` resource. This is a technique called [dependency
20
+ injection](https://en.wikipedia.org/wiki/Dependency_injection), and allows a
21
+ measure of decoupling between the library and application cookbooks.
22
+
23
+ ### Why would I use poise-service?
24
+
25
+ Poise-service is most useful for authors of library-style cookbooks, for example
26
+ the `apache2`, `mysql`, or `application` cookbooks. When using other service
27
+ management options with Chef, the author of the library cookbook has to add
28
+ specific code for each service management framework they want to support, often
29
+ resulting in a cookbook only supporting the favorite framework of the author or
30
+ depending on distribution packages for their init scripts. The `poise_service`
31
+ resource allows library cookbook authors a way to write generic code for all
32
+ service management frameworks while still allowing users of that cookbook to
33
+ choose which service management framework best fits their needs.
34
+
35
+ ### How is this different from the built-in service resource?
36
+
37
+ Chef includes a `service` resource which allows interacting with certain
38
+ service management frameworks such as SysV, Upstart, and systemd.
39
+ `poise-service` goes further in that it actually generates the configuration
40
+ files needed for the requested service management framework, as well as offering
41
+ a dependency injection system for application cookbooks to customize which
42
+ framework is used.
43
+
44
+ ### What service management frameworks are supported?
45
+
46
+ * SysV (aka /etc/init.d)
47
+ * Upstart
48
+ * systemd
49
+ * [Runit](https://github.com/poise/poise-service-runit)
50
+ * *Supervisor (coming soon!)*
51
+
52
+
53
+ ## Quick Start
54
+
55
+ To create a service user and a service to run Apache2:
56
+
57
+ ```ruby
58
+ poise_service_user 'www-data'
59
+
60
+ poise_service 'apache2' do
61
+ command '/usr/sbin/apache2 -f /etc/apache2/apache2.conf -DFOREGROUND'
62
+ stop_signal 'WINCH'
63
+ reload_signal 'USR1'
64
+ end
65
+ ```
66
+
67
+ or for a hypothetical Rails web application:
68
+
69
+ ```ruby
70
+ poise_service_user 'myapp'
71
+
72
+ poise_service 'myapp-web' do
73
+ command 'bundle exec unicorn -p 8080'
74
+ user 'myapp'
75
+ directory '/srv/myapp'
76
+ environment RAILS_ENV: 'production'
77
+ end
78
+ ```
79
+
80
+ ## Resources
81
+
82
+ ### `poise_service`
83
+
84
+ The `poise_service` resource is the abstract definition of a service.
85
+
86
+ ```ruby
87
+ poise_service 'myapp' do
88
+ command 'myapp --serve'
89
+ environment RAILS_ENV: 'production'
90
+ end
91
+ ```
92
+
93
+ #### Actions
94
+
95
+ * `:enable` – Create, enable and start the service. *(default)*
96
+ * `:disable` – Stop, disable, and destroy the service.
97
+ * `:start` – Start the service.
98
+ * `:stop` – Stop the service.
99
+ * `:restart` – Stop and then start the service.
100
+ * `:reload` – Send the configured reload signal to the service.
101
+
102
+ #### Attributes
103
+
104
+ * `service_name` – Name of the service. *(name attribute)*
105
+ * `command` – Command to run for the service. This command must stay in the
106
+ foreground and not daemonize itself. *(required)*
107
+ * `user` – User to run the service as. See
108
+ [`poise_service_user`](#poise_service_user) for any easy way to create service
109
+ users. *(default: root)*
110
+ * `directory` – Working directory for the service. *(default: home directory for
111
+ user, or / if not found)*
112
+ * `environment` – Environment variables for the service.
113
+ * `stop_signal` – Signal to use to stop the service. Some systems will fall back
114
+ to SIGKILL if this signal fails to stop the process. *(default: TERM)*
115
+ * `reload_signal` – Signal to use to reload the service. *(default: HUP)*
116
+ * `restart_on_update` – If true, the service will be restarted if the service
117
+ definition or configuration changes. If `'immediately'`, the notification will
118
+ happen in immediate mode. *(default: true)*
119
+
120
+ #### Service Options
121
+
122
+ The `poise-service` library offers an additional way to pass configuration
123
+ information to the final service called "options". Options are key/value pairs
124
+ that are passed down to the service provider and can be used to control how it
125
+ creates and manages the service. These can be set in the `poise_service`
126
+ resource using the `options` method, in node attributes or via the
127
+ `poise_service_options` resource. The options from all sources are merged
128
+ together into a single hash based.
129
+
130
+ When setting options in the resource you can either set them for all providers:
131
+
132
+ ```ruby
133
+ poise_service 'myapp' do
134
+ command 'myapp --serve'
135
+ options status_port: 8000
136
+ end
137
+ ```
138
+
139
+ or for a single provider:
140
+
141
+ ```ruby
142
+ poise_service 'myapp' do
143
+ command 'myapp --serve'
144
+ options :systemd, after_target: 'network'
145
+ end
146
+ ```
147
+
148
+ Setting via node attributes is generally how an end-user or application cookbook
149
+ will set options to customize services in the library cookbooks they are using.
150
+ You can set options for all services or for a single service, by service name
151
+ or by resource name:
152
+
153
+ ```ruby
154
+ # Global, for all services.
155
+ override['poise-service']['options']['after_target'] = 'network'
156
+ # Single service.
157
+ override['poise-service']['myapp']['template'] = 'myapp.erb'
158
+ ```
159
+
160
+ The `poise_service_options` resource is also available to set node attributes
161
+ for a specific service in a DSL-friendly way:
162
+
163
+ ```ruby
164
+ poise_service_options 'myapp' do
165
+ template 'myapp.erb'
166
+ restart_on_update false
167
+ end
168
+ ```
169
+
170
+ Unlike resource attributes, service options can be different for each provide.
171
+ Not all providers support the same options so make sure to the check the
172
+ documentation for each provider to see what options the use.
173
+
174
+ ### `poise_service_options`
175
+
176
+ The `poise_service_options` resource allows setting per-service options in a
177
+ DSL-friendly way. See [the Service Options](#service-options) section for more
178
+ information about service options overall.
179
+
180
+ ```ruby
181
+ poise_service_options 'myapp' do
182
+ template 'myapp.erb'
183
+ restart_on_update false
184
+ end
185
+ ```
186
+
187
+ #### Actions
188
+
189
+ * `:run` – Apply the service options. *(default)*
190
+
191
+ #### Attributes
192
+
193
+ * `service_name` – Name of the service. *(name attribute)*
194
+ * `for_provider` – Provider to set options for. If set, the resource must be
195
+ defined and reachable before the `poise_service_options` resource.
196
+
197
+ All other attribute keys will be used as options data.
198
+
199
+ ### `poise_service_user`
200
+
201
+ The `poise_service_user` resource is an easy way to create service users. It is
202
+ not required to use `poise_service`, it is only a helper.
203
+
204
+ ```ruby
205
+ poise_service_user 'myapp' do
206
+ home '/srv/myapp'
207
+ end
208
+ ```
209
+
210
+ #### Actions
211
+
212
+ * `:create` – Create the user and group. *(default)*
213
+ * `:remove` – Remove the user and group.
214
+
215
+ #### Attributes
216
+
217
+ * `user` – Name of the user. *(name attribute)*
218
+ * `group` – Name of the group. Set to `false` to disable group creation. *(name attribute)*
219
+ * `uid` – UID of the user. If unspecified it will be automatically allocated.
220
+ * `gid` – GID of the group. If unspecified it will be automatically allocated.
221
+ * `home` – Home directory of the user.
222
+
223
+ ## Providers
224
+
225
+ ### `sysvinit`
226
+
227
+ The `sysvinit` provider supports SystemV-style init systems on Debian-family and
228
+ RHEL-family platforms. It will create the `/etc/init.d/<service_name>` script
229
+ and enable/disable the service using the platform-specific service resource.
230
+
231
+ ```ruby
232
+ poise_service 'myapp' do
233
+ provider :sysvinit
234
+ command 'myapp --serve'
235
+ end
236
+ ```
237
+
238
+ By default a PID file will be created in `/var/run/service_name.pid`. You can
239
+ use the `pid_file` option detailed below to override this and rely on your
240
+ process creating a PID file in the given path. This is highly recommended on
241
+ RHEL-family platforms as automatic PID detection there is more finicky.
242
+
243
+ #### Options
244
+
245
+ * `pid_file` – Path to PID file that the service command will create.
246
+ * `template` – Override the default script template. If you want to use a
247
+ template in a different cookbook use `'cookbook:template'`.
248
+ * `command` – Override the service command.
249
+ * `directory` – Override the service directory.
250
+ * `environment` – Override the service environment variables.
251
+ * `reload_signal` – Override the service reload signal.
252
+ * `stop_signal` – Override the service stop signal.
253
+ * `user` – Override the service user.
254
+ * `never_restart` – Never try to restart the service.
255
+ * `never_reload` – Never try to reload the service.
256
+
257
+ ### `upstart`
258
+
259
+ The `upstart` provider supports [Upstart](http://upstart.ubuntu.com/). It will
260
+ create the `/etc/init/service_name.conf` configuration.
261
+
262
+ ```ruby
263
+ poise_service 'myapp' do
264
+ provider :upstart
265
+ command 'myapp --serve'
266
+ end
267
+ ```
268
+
269
+ As a wide variety of versions of Upstart are in use in various Linux
270
+ distributions, the provider does its best to identify which features are
271
+ available and provide shims as appropriate. Most of these should be invisible
272
+ however Upstart older than 1.10 does not support setting a `reload signal` so
273
+ only SIGHUP can be used. You can set a `reload_shim` option to enable an
274
+ internal implementaion of reloading to be used for signals other than SIGHUP,
275
+ however as this is implemented inside Chef code, running `initctl reload` would
276
+ still result in SIGHUP being sent. For this reason, the feature is disabled by
277
+ default and will throw an error if a reload signal other than SIGHUP is used.
278
+
279
+ #### Options
280
+
281
+ * `reload_shim` – Enable the reload signal shim. See above for a warning about
282
+ this feature.
283
+ * `template` – Override the default configuration template. If you want to use a
284
+ template in a different cookbook use `'cookbook:template'`.
285
+ * `command` – Override the service command.
286
+ * `directory` – Override the service directory.
287
+ * `environment` – Override the service environment variables.
288
+ * `reload_signal` – Override the service reload signal.
289
+ * `stop_signal` – Override the service stop signal.
290
+ * `user` – Override the service user.
291
+ * `never_restart` – Never try to restart the service.
292
+ * `never_reload` – Never try to reload the service.
293
+
294
+ ### `systemd`
295
+
296
+ The `systemd` provider supports [systemd](http://www.freedesktop.org/wiki/Software/systemd/).
297
+ It will create the `/etc/systemd/system/service_name.service` configuration.
298
+
299
+
300
+ ```ruby
301
+ poise_service 'myapp' do
302
+ provider :systemd
303
+ command 'myapp --serve'
304
+ end
305
+ ```
306
+
307
+ #### Options
308
+
309
+ * `template` – Override the default configuration template. If you want to use a
310
+ template in a different cookbook use `'cookbook:template'`.
311
+ * `command` – Override the service command.
312
+ * `directory` – Override the service directory.
313
+ * `environment` – Override the service environment variables.
314
+ * `reload_signal` – Override the service reload signal.
315
+ * `stop_signal` – Override the service stop signal.
316
+ * `user` – Override the service user.
317
+ * `never_restart` – Never try to restart the service.
318
+ * `never_reload` – Never try to reload the service.
319
+
320
+ ## ServiceMixin
321
+
322
+ For the common case of a resource (LWRP or plain Ruby) that roughly maps to
323
+ "some config files and a service" poise-service provides a mixin module,
324
+ `PoiseService::ServiceMixin`. This mixin adds the standard service actions
325
+ (`enable`, `disable`, `start`, `stop`, `restart`, and `reload`) with basic
326
+ implementations that call those actions on a `poise_service` resource for you.
327
+ You customize the service by defining a `service_options` method on your
328
+ provider class:
329
+
330
+ ```ruby
331
+ def service_options(service)
332
+ # service is the PoiseService::Resource object instance.
333
+ service.command "/usr/sbin/#{new_resource.name} -f /etc/#{new_resource.name}/conf/httpd.conf -DFOREGROUND"
334
+ service.stop_signal 'WINCH'
335
+ service.reload_signal 'USR1'
336
+ end
337
+ ```
338
+
339
+ You will generally want to override the `enable` action to install things
340
+ related to the service like packages, users and configuration files:
341
+
342
+ ```ruby
343
+ def action_enable
344
+ notifying_block do
345
+ package 'apache2'
346
+ poise_service_user 'www-data'
347
+ template "/etc/#{new_resource.name}/conf/httpd.conf" do
348
+ # ...
349
+ end
350
+ end
351
+ # This super call will run the normal service enable,
352
+ # creating the service and starting it.
353
+ super
354
+ end
355
+ ```
356
+
357
+ See [the poise_service_test_mixin resource](test/cookbooks/poise-service_test/resources/mixin.rb)
358
+ and [provider](test/cookbooks/poise-service_test/resources/mixin.rb) for
359
+ examples of using `ServiceMixin` in an LWRP.
360
+
361
+ ## Sponsors
362
+
363
+ Development sponsored by [Bloomberg](http://www.bloomberg.com/company/technology/).
364
+
365
+ The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
366
+
367
+ ## License
368
+
369
+ Copyright 2015, Noah Kantrowitz
370
+
371
+ Licensed under the Apache License, Version 2.0 (the "License");
372
+ you may not use this file except in compliance with the License.
373
+ You may obtain a copy of the License at
374
+
375
+ http://www.apache.org/licenses/LICENSE-2.0
376
+
377
+ Unless required by applicable law or agreed to in writing, software
378
+ distributed under the License is distributed on an "AS IS" BASIS,
379
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
380
+ See the License for the specific language governing permissions and
381
+ limitations under the License.