from-scratch 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +2 -1
  3. data/Berksfile.lock +20 -1
  4. data/cookbooks/bluepill/CHANGELOG.md +93 -0
  5. data/cookbooks/bluepill/README.md +91 -0
  6. data/cookbooks/bluepill/attributes/default.rb +44 -0
  7. data/cookbooks/bluepill/metadata.json +1 -0
  8. data/cookbooks/bluepill/providers/service.rb +172 -0
  9. data/cookbooks/bluepill/recipes/default.rb +48 -0
  10. data/cookbooks/bluepill/recipes/rsyslog.rb +28 -0
  11. data/cookbooks/bluepill/resources/service.rb +27 -0
  12. data/cookbooks/bluepill/templates/default/bluepill_init.fedora.erb +34 -0
  13. data/cookbooks/bluepill/templates/default/bluepill_init.freebsd.erb +32 -0
  14. data/cookbooks/bluepill/templates/default/bluepill_init.lsb.erb +37 -0
  15. data/cookbooks/bluepill/templates/default/bluepill_init.rhel.erb +34 -0
  16. data/cookbooks/bluepill/templates/default/bluepill_rsyslog.conf.erb +1 -0
  17. data/cookbooks/nginx/CHANGELOG.md +435 -0
  18. data/cookbooks/nginx/README.md +521 -0
  19. data/cookbooks/nginx/attributes/auth_request.rb +23 -0
  20. data/cookbooks/nginx/attributes/default.rb +131 -0
  21. data/cookbooks/nginx/attributes/devel.rb +24 -0
  22. data/cookbooks/nginx/attributes/echo.rb +24 -0
  23. data/cookbooks/nginx/attributes/geoip.rb +31 -0
  24. data/cookbooks/nginx/attributes/headers_more.rb +24 -0
  25. data/cookbooks/nginx/attributes/lua.rb +28 -0
  26. data/cookbooks/nginx/attributes/naxsi.rb +24 -0
  27. data/cookbooks/nginx/attributes/openssl_source.rb +23 -0
  28. data/cookbooks/nginx/attributes/pagespeed.rb +9 -0
  29. data/cookbooks/nginx/attributes/passenger.rb +58 -0
  30. data/cookbooks/nginx/attributes/rate_limiting.rb +23 -0
  31. data/cookbooks/nginx/attributes/repo.rb +35 -0
  32. data/cookbooks/nginx/attributes/set_misc.rb +8 -0
  33. data/cookbooks/nginx/attributes/socketproxy.rb +13 -0
  34. data/cookbooks/nginx/attributes/source.rb +42 -0
  35. data/cookbooks/nginx/attributes/status.rb +22 -0
  36. data/cookbooks/nginx/attributes/syslog.rb +24 -0
  37. data/cookbooks/nginx/attributes/upload_progress.rb +26 -0
  38. data/cookbooks/nginx/definitions/nginx_site.rb +50 -0
  39. data/cookbooks/nginx/files/default/mime.types +78 -0
  40. data/cookbooks/nginx/files/default/naxsi_core.rules +82 -0
  41. data/cookbooks/nginx/libraries/matchers.rb +20 -0
  42. data/cookbooks/nginx/metadata.json +351 -0
  43. data/cookbooks/nginx/recipes/authorized_ips.rb +32 -0
  44. data/cookbooks/nginx/recipes/commons.rb +24 -0
  45. data/cookbooks/nginx/recipes/commons_conf.rb +42 -0
  46. data/cookbooks/nginx/recipes/commons_dir.rb +57 -0
  47. data/cookbooks/nginx/recipes/commons_script.rb +29 -0
  48. data/cookbooks/nginx/recipes/default.rb +31 -0
  49. data/cookbooks/nginx/recipes/headers_more_module.rb +50 -0
  50. data/cookbooks/nginx/recipes/http_auth_request_module.rb +52 -0
  51. data/cookbooks/nginx/recipes/http_echo_module.rb +46 -0
  52. data/cookbooks/nginx/recipes/http_geoip_module.rb +113 -0
  53. data/cookbooks/nginx/recipes/http_gzip_static_module.rb +30 -0
  54. data/cookbooks/nginx/recipes/http_mp4_module.rb +2 -0
  55. data/cookbooks/nginx/recipes/http_perl_module.rb +23 -0
  56. data/cookbooks/nginx/recipes/http_realip_module.rb +38 -0
  57. data/cookbooks/nginx/recipes/http_spdy_module.rb +23 -0
  58. data/cookbooks/nginx/recipes/http_ssl_module.rb +23 -0
  59. data/cookbooks/nginx/recipes/http_stub_status_module.rb +36 -0
  60. data/cookbooks/nginx/recipes/ipv6.rb +23 -0
  61. data/cookbooks/nginx/recipes/lua.rb +47 -0
  62. data/cookbooks/nginx/recipes/naxsi_module.rb +52 -0
  63. data/cookbooks/nginx/recipes/ngx_devel_module.rb +44 -0
  64. data/cookbooks/nginx/recipes/ngx_lua_module.rb +47 -0
  65. data/cookbooks/nginx/recipes/ohai_plugin.rb +35 -0
  66. data/cookbooks/nginx/recipes/openssl_source.rb +45 -0
  67. data/cookbooks/nginx/recipes/package.rb +52 -0
  68. data/cookbooks/nginx/recipes/pagespeed_module.rb +62 -0
  69. data/cookbooks/nginx/recipes/passenger.rb +56 -0
  70. data/cookbooks/nginx/recipes/repo.rb +41 -0
  71. data/cookbooks/nginx/recipes/repo_passenger.rb +39 -0
  72. data/cookbooks/nginx/recipes/set_misc.rb +30 -0
  73. data/cookbooks/nginx/recipes/socketproxy.rb +26 -0
  74. data/cookbooks/nginx/recipes/source.rb +205 -0
  75. data/cookbooks/nginx/recipes/syslog_module.rb +69 -0
  76. data/cookbooks/nginx/recipes/upload_progress_module.rb +53 -0
  77. data/cookbooks/nginx/templates/debian/nginx.init.erb +97 -0
  78. data/cookbooks/nginx/templates/default/default-site.erb +11 -0
  79. data/cookbooks/nginx/templates/default/modules/authorized_ip.erb +6 -0
  80. data/cookbooks/nginx/templates/default/modules/http_geoip.conf.erb +4 -0
  81. data/cookbooks/nginx/templates/default/modules/http_gzip_static.conf.erb +1 -0
  82. data/cookbooks/nginx/templates/default/modules/http_realip.conf.erb +7 -0
  83. data/cookbooks/nginx/templates/default/modules/nginx_status.erb +14 -0
  84. data/cookbooks/nginx/templates/default/modules/passenger.conf.erb +13 -0
  85. data/cookbooks/nginx/templates/default/modules/socketproxy.conf.erb +89 -0
  86. data/cookbooks/nginx/templates/default/modules/upload_progress.erb +4 -0
  87. data/cookbooks/nginx/templates/default/nginx-upstart.conf.erb +39 -0
  88. data/cookbooks/nginx/templates/default/nginx.conf.erb +103 -0
  89. data/cookbooks/nginx/templates/default/nginx.init.erb +111 -0
  90. data/cookbooks/nginx/templates/default/nginx.pill.erb +15 -0
  91. data/cookbooks/nginx/templates/default/nginx.sysconfig.erb +1 -0
  92. data/cookbooks/nginx/templates/default/nxdissite.erb +29 -0
  93. data/cookbooks/nginx/templates/default/nxensite.erb +38 -0
  94. data/cookbooks/nginx/templates/default/plugins/nginx.rb.erb +66 -0
  95. data/cookbooks/nginx/templates/default/sv-nginx-log-run.erb +2 -0
  96. data/cookbooks/nginx/templates/default/sv-nginx-run.erb +4 -0
  97. data/cookbooks/nginx/templates/gentoo/nginx.init.erb +87 -0
  98. data/cookbooks/nginx/templates/suse/nginx.init.erb +115 -0
  99. data/cookbooks/nginx/templates/ubuntu/nginx.init.erb +97 -0
  100. data/cookbooks/ohai/CHANGELOG.md +69 -0
  101. data/cookbooks/ohai/README.md +89 -0
  102. data/cookbooks/ohai/attributes/default.rb +31 -0
  103. data/cookbooks/ohai/files/default/plugins/README +1 -0
  104. data/cookbooks/ohai/libraries/matchers.rb +14 -0
  105. data/cookbooks/ohai/metadata.json +1 -0
  106. data/cookbooks/ohai/providers/hint.rb +38 -0
  107. data/cookbooks/ohai/recipes/default.rb +52 -0
  108. data/cookbooks/ohai/resources/hint.rb +5 -0
  109. data/cookbooks/packagecloud/CHANGELOG.md +12 -0
  110. data/cookbooks/packagecloud/README.md +80 -0
  111. data/cookbooks/packagecloud/attributes/default.rb +8 -0
  112. data/cookbooks/packagecloud/libraries/helper.rb +43 -0
  113. data/cookbooks/packagecloud/libraries/matcher.rb +7 -0
  114. data/cookbooks/packagecloud/metadata.json +1 -0
  115. data/cookbooks/packagecloud/providers/repo.rb +212 -0
  116. data/cookbooks/packagecloud/resources/repo.rb +10 -0
  117. data/cookbooks/packagecloud/templates/.kitchen/logs/kitchen.log +29 -0
  118. data/cookbooks/packagecloud/templates/default/apt.erb +2 -0
  119. data/cookbooks/packagecloud/templates/default/yum.erb +15 -0
  120. data/cookbooks/rsyslog/CHANGELOG.md +193 -0
  121. data/cookbooks/rsyslog/README.md +276 -0
  122. data/cookbooks/rsyslog/attributes/default.rb +131 -0
  123. data/cookbooks/rsyslog/libraries/helpers.rb +25 -0
  124. data/cookbooks/rsyslog/metadata.json +1 -0
  125. data/cookbooks/rsyslog/providers/file_input.rb +44 -0
  126. data/cookbooks/rsyslog/recipes/client.rb +87 -0
  127. data/cookbooks/rsyslog/recipes/default.rb +89 -0
  128. data/cookbooks/rsyslog/recipes/server.rb +44 -0
  129. data/cookbooks/rsyslog/resources/file_input.rb +28 -0
  130. data/cookbooks/rsyslog/templates/default/35-server-per-host.conf.erb +62 -0
  131. data/cookbooks/rsyslog/templates/default/49-relp.conf.erb +10 -0
  132. data/cookbooks/rsyslog/templates/default/49-remote.conf.erb +30 -0
  133. data/cookbooks/rsyslog/templates/default/50-default.conf.erb +6 -0
  134. data/cookbooks/rsyslog/templates/default/file-input.conf.erb +15 -0
  135. data/cookbooks/rsyslog/templates/default/omnios-manifest.xml.erb +30 -0
  136. data/cookbooks/rsyslog/templates/default/rsyslog.conf.erb +117 -0
  137. data/cookbooks/rsyslog/templates/smartos/50-default.conf.erb +18 -0
  138. data/cookbooks/runit/.kitchen.cloud.yml +103 -0
  139. data/cookbooks/runit/.kitchen.yml +38 -0
  140. data/cookbooks/runit/.rspec +3 -0
  141. data/cookbooks/runit/.rubocop.yml +45 -0
  142. data/cookbooks/runit/Berksfile.disabled +11 -0
  143. data/cookbooks/runit/CHANGELOG.md +226 -0
  144. data/cookbooks/runit/CONTRIBUTING.md +266 -0
  145. data/cookbooks/runit/Cheffile +11 -0
  146. data/cookbooks/runit/Gemfile +17 -0
  147. data/cookbooks/runit/LICENSE +201 -0
  148. data/cookbooks/runit/README.md +435 -0
  149. data/cookbooks/runit/Rakefile +23 -0
  150. data/cookbooks/runit/TESTING.md +26 -0
  151. data/cookbooks/runit/attributes/default.rb +62 -0
  152. data/cookbooks/runit/files/default/runit.seed +1 -0
  153. data/cookbooks/runit/files/default/runsvdir +0 -0
  154. data/cookbooks/runit/files/ubuntu-6.10/runsvdir +6 -0
  155. data/cookbooks/runit/files/ubuntu-7.04/runsvdir +7 -0
  156. data/cookbooks/runit/files/ubuntu-7.10/runsvdir +7 -0
  157. data/cookbooks/runit/files/ubuntu-8.04/runsvdir +7 -0
  158. data/cookbooks/runit/libraries/default.rb +0 -0
  159. data/cookbooks/runit/libraries/helpers.rb +190 -0
  160. data/cookbooks/runit/libraries/matchers.rb +69 -0
  161. data/cookbooks/runit/libraries/provider_runit_service.rb +326 -0
  162. data/cookbooks/runit/libraries/resource_runit_service.rb +267 -0
  163. data/cookbooks/runit/metadata.json +50 -0
  164. data/cookbooks/runit/recipes/default.rb +91 -0
  165. data/cookbooks/runit/templates/debian/init.d.erb +66 -0
  166. data/cookbooks/runit/templates/default/log-config.erb +24 -0
  167. data/cookbooks/runit/templates/gentoo/runit-start.sh.erb +32 -0
  168. data/cookbooks/scratchify/Berksfile +2 -1
  169. data/cookbooks/scratchify/Berksfile.lock +20 -1
  170. data/cookbooks/scratchify/lib/from-scratch.rb +1 -4
  171. data/cookbooks/scratchify/lib/from-scratch/version.rb +1 -1
  172. data/cookbooks/scratchify/metadata.json +5 -2
  173. data/cookbooks/scratchify/recipes/default.rb +15 -1
  174. data/cookbooks/scratchify/recipes/nginx_site.rb +4 -0
  175. data/cookbooks/scratchify/recipes/pre_rvm.rb +5 -0
  176. data/cookbooks/scratchify/templates/nginx.erb +31 -0
  177. data/cookbooks/scratchify/templates/node.json.erb +21 -6
  178. data/cookbooks/yum-epel/CHANGELOG.md +84 -0
  179. data/cookbooks/yum-epel/README.md +172 -0
  180. data/cookbooks/yum-epel/attributes/default.rb +1 -0
  181. data/cookbooks/yum-epel/attributes/epel-debuginfo.rb +28 -0
  182. data/cookbooks/yum-epel/attributes/epel-source.rb +28 -0
  183. data/cookbooks/yum-epel/attributes/epel-testing-debuginfo.rb +28 -0
  184. data/cookbooks/yum-epel/attributes/epel-testing-source.rb +28 -0
  185. data/cookbooks/yum-epel/attributes/epel-testing.rb +28 -0
  186. data/cookbooks/yum-epel/attributes/epel.rb +28 -0
  187. data/cookbooks/yum-epel/metadata.json +1 -0
  188. data/cookbooks/yum-epel/recipes/default.rb +61 -0
  189. data/cookbooks/yum/CHANGELOG.md +294 -0
  190. data/cookbooks/yum/README.md +285 -0
  191. data/cookbooks/yum/attributes/main.rb +100 -0
  192. data/cookbooks/yum/libraries/matchers.rb +27 -0
  193. data/cookbooks/yum/metadata.json +1 -0
  194. data/cookbooks/yum/providers/globalconfig.rb +41 -0
  195. data/cookbooks/yum/providers/repository.rb +106 -0
  196. data/cookbooks/yum/recipes/default.rb +26 -0
  197. data/cookbooks/yum/resources/globalconfig.rb +109 -0
  198. data/cookbooks/yum/resources/repository.rb +69 -0
  199. data/cookbooks/yum/templates/default/main.erb +276 -0
  200. data/cookbooks/yum/templates/default/repo.erb +125 -0
  201. data/lib/from-scratch.rb +1 -0
  202. data/lib/from-scratch/version.rb +1 -1
  203. data/metadata.rb +5 -1
  204. data/recipes/default.rb +15 -1
  205. data/recipes/nginx_site.rb +4 -0
  206. data/recipes/pre_rvm.rb +5 -0
  207. data/templates/nginx.erb +31 -0
  208. data/templates/node.json.erb +21 -6
  209. metadata +194 -1
@@ -0,0 +1,26 @@
1
+ Testing
2
+ =======
3
+ This cookbook has tests in the GitHub repository. To run the tests:
4
+
5
+ git clone git://github.com/hw-cookbooks/runit.git
6
+ cd runit
7
+ bundle install
8
+
9
+ There are two kinds of tests, unit tests and integration tests.
10
+
11
+ ## Unit Tests
12
+
13
+ The resource/provider code is unit tested with rspec. To run these
14
+ tests, use rake:
15
+
16
+ bundle exec rake spec
17
+
18
+ ## Integration Tests
19
+
20
+ Integration tests are setup to run under minitest-chef. They are
21
+ automatically run under test kitchen.
22
+
23
+ bundle exec kitchen test
24
+
25
+ This tests the default recipe ("default" configuration), and various
26
+ uses of the `runit_service` resource ("service" configuration).
@@ -0,0 +1,62 @@
1
+ #
2
+ # Cookbook Name:: runit
3
+ # Attribute File:: sv_bin
4
+ #
5
+ # Copyright 2008-2009, Chef Software, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the 'License');
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an 'AS IS' BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ case node['platform_family']
21
+ when 'debian'
22
+ default['runit']['sv_bin'] = '/usr/bin/sv'
23
+ default['runit']['chpst_bin'] = '/usr/bin/chpst'
24
+ default['runit']['service_dir'] = '/etc/service'
25
+ default['runit']['sv_dir'] = '/etc/sv'
26
+ default['runit']['lsb_init_dir'] = '/etc/init.d'
27
+ default['runit']['executable'] = '/sbin/runit'
28
+
29
+ if node['platform'] == 'debian'
30
+ default['runit']['start'] = 'runsvdir-start'
31
+ default['runit']['stop'] = ''
32
+ default['runit']['reload'] = ''
33
+ elsif node['platform'] == 'ubuntu'
34
+ default['runit']['start'] = 'start runsvdir'
35
+ default['runit']['stop'] = 'stop runsvdir'
36
+ default['runit']['reload'] = 'reload runsvdir'
37
+ end
38
+
39
+ when 'rhel', 'fedora'
40
+ default['runit']['sv_bin'] = '/sbin/sv'
41
+ default['runit']['chpst_bin'] = '/sbin/chpst'
42
+ default['runit']['service_dir'] = '/etc/service'
43
+ default['runit']['sv_dir'] = '/etc/sv'
44
+ default['runit']['lsb_init_dir'] = '/etc/init.d'
45
+ default['runit']['executable'] = '/sbin/runit'
46
+ default['runit']['prefer_local_yum'] = node['runit']['use_package_from_yum'] || false
47
+ default['runit']['start'] = '/etc/init.d/runit-start start'
48
+ default['runit']['stop'] = '/etc/init.d/runit-start stop'
49
+ default['runit']['reload'] = '/etc/init.d/runit-start reload'
50
+
51
+ when 'gentoo'
52
+ default['runit']['sv_bin'] = '/usr/bin/sv'
53
+ default['runit']['chpst_bin'] = '/usr/bin/chpst'
54
+ default['runit']['service_dir'] = '/var/service'
55
+ default['runit']['sv_dir'] = '/etc/sv'
56
+ default['runit']['lsb_init_dir'] = '/etc/init.d'
57
+ default['runit']['executable'] = '/sbin/runit'
58
+ default['runit']['start'] = '/etc/init.d/runit-start start'
59
+ default['runit']['stop'] = '/etc/init.d/runit-start stop'
60
+ default['runit']['reload'] = '/etc/init.d/runit-start reload'
61
+
62
+ end
@@ -0,0 +1 @@
1
+ runit runit/signalinit boolean true
File without changes
@@ -0,0 +1,6 @@
1
+ start on runlevel-2
2
+ start on runlevel-3
3
+ start on runlevel-4
4
+ start on runlevel-5
5
+ stop on shutdown
6
+ respawn /usr/sbin/runsvdir-start
@@ -0,0 +1,7 @@
1
+ start on runlevel 2
2
+ start on runlevel 3
3
+ start on runlevel 4
4
+ start on runlevel 5
5
+ stop on shutdown
6
+ respawn
7
+ exec /usr/sbin/runsvdir-start
@@ -0,0 +1,7 @@
1
+ start on runlevel 2
2
+ start on runlevel 3
3
+ start on runlevel 4
4
+ start on runlevel 5
5
+ stop on shutdown
6
+ respawn
7
+ exec /usr/sbin/runsvdir-start
@@ -0,0 +1,7 @@
1
+ start on runlevel 2
2
+ start on runlevel 3
3
+ start on runlevel 4
4
+ start on runlevel 5
5
+ stop on shutdown
6
+ respawn
7
+ exec /usr/sbin/runsvdir-start
File without changes
@@ -0,0 +1,190 @@
1
+ #
2
+ # Cookbook:: runit
3
+ # Libraries:: helpers
4
+ #
5
+ # Author: Joshua Timberman <joshua@chef.io>
6
+ # Author: Sean OMeara <sean@chef.io>
7
+ # Copyright 2008-2015, Chef Software, Inc. <legal@chef.io>
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ module RunitCookbook
23
+ module Helpers
24
+ # include Chef::Mixin::ShellOut if it is not already included in the calling class
25
+ def self.included(klass)
26
+ unless klass.ancestors.include?(Chef::Mixin::ShellOut)
27
+ klass.class_eval { include Chef::Mixin::ShellOut }
28
+ end
29
+ end
30
+
31
+ # Default settings for resource properties.
32
+ def parsed_sv_bin
33
+ return new_resource.sv_bin if new_resource.sv_bin
34
+ '/usr/bin/sv'
35
+ end
36
+
37
+ def parsed_sv_dir
38
+ return new_resource.sv_dir if new_resource.sv_dir
39
+ '/etc/sv'
40
+ end
41
+
42
+ def parsed_service_dir
43
+ return new_resource.service_dir if new_resource.service_dir
44
+ '/etc/service'
45
+ end
46
+
47
+ def parsed_lsb_init_dir
48
+ return new_resource.lsb_init_dir if new_resource.lsb_init_dir
49
+ '/etc/init.d'
50
+ end
51
+
52
+ # misc helper functions
53
+ def inside_docker?
54
+ results = `cat /proc/1/cgroup`.strip.split("\n")
55
+ results.any? { |val| /docker/ =~ val }
56
+ end
57
+
58
+ def down_file
59
+ "#{sv_dir_name}/down"
60
+ end
61
+
62
+ def env_dir
63
+ "#{sv_dir_name}/env"
64
+ end
65
+
66
+ def extra_env_files?
67
+ files = []
68
+ Dir.glob("#{sv_dir_name}/env/*").each do |f|
69
+ files << File.basename(f)
70
+ end
71
+ return true if files.sort != new_resource.env.keys.sort
72
+ false
73
+ end
74
+
75
+ def zap_extra_env_files
76
+ Dir.glob("#{sv_dir_name}/env/*").each do |f|
77
+ unless new_resource.env.key?(File.basename(f))
78
+ File.unlink(f)
79
+ Chef::Log.info("removing file #{f}")
80
+ end
81
+ end
82
+ end
83
+
84
+ def wait_for_service
85
+ unless inside_docker?
86
+ sleep 1 until ::FileTest.pipe?("#{service_dir_name}/supervise/ok")
87
+
88
+ if new_resource.log
89
+ sleep 1 until ::FileTest.pipe?("#{service_dir_name}/log/supervise/ok")
90
+ end
91
+ end
92
+ end
93
+
94
+ def runit_sv_works?
95
+ sv = shell_out("#{sv_bin} --help")
96
+ sv.exitstatus == 100 && sv.stderr =~ /usage: sv .* command service/
97
+ end
98
+
99
+ def runit_send_signal(signal, friendly_name = nil)
100
+ friendly_name ||= signal
101
+ converge_by("send #{friendly_name} to #{new_resource}") do
102
+ shell_out!("#{sv_bin} #{sv_args}#{signal} #{service_dir_name}")
103
+ Chef::Log.info("#{new_resource} sent #{friendly_name}")
104
+ end
105
+ end
106
+
107
+ def running?
108
+ cmd = shell_out("#{sv_bin} #{sv_args}status #{service_dir_name}")
109
+ (cmd.stdout =~ /^run:/ && cmd.exitstatus == 0)
110
+ end
111
+
112
+ def log_running?
113
+ cmd = shell_out("#{sv_bin} #{sv_args}status #{service_dir_name}/log")
114
+ (cmd.stdout =~ /^run:/ && cmd.exitstatus == 0)
115
+ end
116
+
117
+ def enabled?
118
+ ::File.exist?("#{service_dir_name}/run")
119
+ end
120
+
121
+ def log_service_name
122
+ "#{new_resource.service_name}/log"
123
+ end
124
+
125
+ def sv_dir_name
126
+ "#{parsed_sv_dir}/#{new_resource.service_name}"
127
+ end
128
+
129
+ def sv_args
130
+ sv_args = ''
131
+ sv_args += "-w '#{new_resource.sv_timeout}' " unless new_resource.sv_timeout.nil?
132
+ sv_args += '-v ' if new_resource.sv_verbose
133
+ sv_args
134
+ end
135
+
136
+ def sv_bin
137
+ parsed_sv_bin
138
+ end
139
+
140
+ def service_dir_name
141
+ "#{new_resource.service_dir}/#{new_resource.service_name}"
142
+ end
143
+
144
+ def log_dir_name
145
+ "#{new_resource.service_dir}/#{new_resource.service_name}/log"
146
+ end
147
+
148
+ def template_cookbook
149
+ new_resource.cookbook.nil? ? new_resource.cookbook_name.to_s : new_resource.cookbook
150
+ end
151
+
152
+ def default_logger_content
153
+ <<-EOS
154
+ #!/bin/sh
155
+ exec svlogd -tt #{new_resource.log_dir}
156
+ EOS
157
+ end
158
+
159
+ def disable_service
160
+ shell_out("#{new_resource.sv_bin} #{sv_args}down #{service_dir_name}")
161
+ FileUtils.rm(service_dir_name)
162
+ end
163
+
164
+ def start_service
165
+ shell_out!("#{new_resource.sv_bin} #{sv_args}start #{service_dir_name}")
166
+ end
167
+
168
+ def stop_service
169
+ shell_out!("#{new_resource.sv_bin} #{sv_args}stop #{service_dir_name}")
170
+ end
171
+
172
+ def restart_service
173
+ shell_out!("#{new_resource.sv_bin} #{sv_args}restart #{service_dir_name}")
174
+ end
175
+
176
+ def restart_log_service
177
+ shell_out!("#{new_resource.sv_bin} #{sv_args}restart #{service_dir_name}/log")
178
+ end
179
+
180
+ def reload_service
181
+ shell_out!("#{new_resource.sv_bin} #{sv_args}force-reload #{service_dir_name}")
182
+ end
183
+
184
+ def reload_log_service
185
+ if log_running?
186
+ shell_out!("#{new_resource.sv_bin} #{sv_args}force-reload #{service_dir_name}/log")
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,69 @@
1
+ if defined?(ChefSpec)
2
+
3
+ ChefSpec.define_matcher(:runit_service)
4
+
5
+ def start_runit_service(service)
6
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :start, service)
7
+ end
8
+
9
+ def stop_runit_service(service)
10
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :stop, service)
11
+ end
12
+
13
+ def enable_runit_service(service)
14
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :enable, service)
15
+ end
16
+
17
+ def disable_runit_service(service)
18
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :disable, service)
19
+ end
20
+
21
+ def restart_runit_service(service)
22
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :restart, service)
23
+ end
24
+
25
+ def reload_runit_service(service)
26
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :reload, service)
27
+ end
28
+
29
+ def status_runit_service(service)
30
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :status, service)
31
+ end
32
+
33
+ def once_runit_service(service)
34
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :once, service)
35
+ end
36
+
37
+ def hup_runit_service(service)
38
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :hup, service)
39
+ end
40
+
41
+ def cont_runit_service(service)
42
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :cont, service)
43
+ end
44
+
45
+ def term_runit_service(service)
46
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :term, service)
47
+ end
48
+
49
+ def kill_runit_service(service)
50
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :kill, service)
51
+ end
52
+
53
+ def up_runit_service(service)
54
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :up, service)
55
+ end
56
+
57
+ def down_runit_service(service)
58
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :down, service)
59
+ end
60
+
61
+ def usr1_runit_service(service)
62
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :usr1, service)
63
+ end
64
+
65
+ def usr2_runit_service(service)
66
+ ChefSpec::Matchers::ResourceMatcher.new(:runit_service, :usr2, service)
67
+ end
68
+
69
+ end
@@ -0,0 +1,326 @@
1
+ #
2
+ # Cookbook Name:: runit
3
+ # Provider:: service
4
+ #
5
+ # Author:: Joshua Timberman <jtimberman@chef.io>
6
+ # Author:: Sean OMeara <sean@chef.io>
7
+ # Copyright 2011-2015, Chef Software, Inc.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ class Chef
23
+ class Provider
24
+ class RunitService < Chef::Provider::LWRPBase
25
+ unless defined?(VALID_SIGNALS)
26
+ # Mapping of valid signals with optional friendly name
27
+ VALID_SIGNALS = Mash.new(
28
+ :down => nil,
29
+ :hup => nil,
30
+ :int => nil,
31
+ :term => nil,
32
+ :kill => nil,
33
+ :quit => nil,
34
+ :up => nil,
35
+ :once => nil,
36
+ :cont => nil,
37
+ 1 => :usr1,
38
+ 2 => :usr2
39
+ )
40
+ end
41
+
42
+ use_inline_resources if defined?(use_inline_resources)
43
+
44
+ def whyrun_supported?
45
+ true
46
+ end
47
+
48
+ # Mix in helpers from libraries/helpers.rb
49
+ include RunitCookbook::Helpers
50
+
51
+ # actions
52
+ action :create do
53
+ # sv_templates
54
+ if new_resource.sv_templates
55
+
56
+ directory sv_dir_name do
57
+ owner new_resource.owner
58
+ group new_resource.group
59
+ mode '0755'
60
+ recursive true
61
+ action :create
62
+ end
63
+
64
+ template "#{sv_dir_name}/run" do
65
+ owner new_resource.owner
66
+ group new_resource.group
67
+ source "sv-#{new_resource.run_template_name}-run.erb"
68
+ cookbook template_cookbook
69
+ mode '0755'
70
+ variables(options: new_resource.options)
71
+ action :create
72
+ end
73
+
74
+ # log stuff
75
+ if new_resource.log
76
+ directory "#{sv_dir_name}/log" do
77
+ owner new_resource.owner
78
+ group new_resource.group
79
+ recursive true
80
+ action :create
81
+ end
82
+
83
+ directory "#{sv_dir_name}/log/main" do
84
+ owner new_resource.owner
85
+ group new_resource.group
86
+ mode '0755'
87
+ recursive true
88
+ action :create
89
+ end
90
+
91
+ directory new_resource.log_dir do
92
+ owner new_resource.owner
93
+ group new_resource.group
94
+ mode '00755'
95
+ recursive true
96
+ action :create
97
+ end
98
+
99
+ template "#{sv_dir_name}/log/config" do
100
+ owner new_resource.owner
101
+ group new_resource.group
102
+ mode '00644'
103
+ cookbook 'runit'
104
+ source 'log-config.erb'
105
+ variables(config: new_resource)
106
+ action :create
107
+ end
108
+
109
+ link "#{new_resource.log_dir}/config" do
110
+ to "#{sv_dir_name}/log/config"
111
+ end
112
+
113
+ if new_resource.default_logger
114
+ file "#{sv_dir_name}/log/run" do
115
+ content default_logger_content
116
+ owner new_resource.owner
117
+ group new_resource.group
118
+ mode '00755'
119
+ action :create
120
+ end
121
+ else
122
+ template "#{sv_dir_name}/log/run" do
123
+ owner new_resource.owner
124
+ group new_resource.group
125
+ mode '00755'
126
+ source "sv-#{new_resource.log_template_name}-log-run.erb"
127
+ cookbook template_cookbook
128
+ variables(options: new_resource.options)
129
+ action :create
130
+ end
131
+ end
132
+
133
+ end
134
+
135
+ # environment stuff
136
+ directory "#{sv_dir_name}/env" do
137
+ owner new_resource.owner
138
+ group new_resource.group
139
+ mode '00755'
140
+ action :create
141
+ end
142
+
143
+ new_resource.env.map do |var, value|
144
+ file "#{sv_dir_name}/env/#{var}" do
145
+ owner new_resource.owner
146
+ group new_resource.group
147
+ content value
148
+ mode 00640
149
+ action :create
150
+ end
151
+ end
152
+
153
+ ruby_block "zap extra env files for #{new_resource.name} service" do
154
+ block { zap_extra_env_files }
155
+ only_if { extra_env_files? }
156
+ not_if { new_resource.env.empty? }
157
+ action :run
158
+ end
159
+
160
+ if new_resource.check
161
+ template "#{sv_dir_name}/check" do
162
+ owner new_resource.owner
163
+ group new_resource.group
164
+ mode '00755'
165
+ cookbook template_cookbook
166
+ source "sv-#{new_resource.check_script_template_name}-check.erb"
167
+ variables(options: new_resource.options)
168
+ action :create
169
+ end
170
+ end
171
+
172
+ if new_resource.finish
173
+ template "#{sv_dir_name}/finish" do
174
+ owner new_resource.owner
175
+ group new_resource.group
176
+ mode '00755'
177
+ source "sv-#{new_resource.finish_script_template_name}-finish.erb"
178
+ cookbook template_cookbook
179
+ variables(options: new_resource.options) if new_resource.options.respond_to?(:has_key?)
180
+ action :create
181
+ end
182
+ end
183
+
184
+ directory "#{sv_dir_name}/control" do
185
+ owner new_resource.owner
186
+ group new_resource.group
187
+ mode '00755'
188
+ action :create
189
+ end
190
+
191
+ new_resource.control.map do |signal|
192
+ template "#{sv_dir_name}/control/#{signal}" do
193
+ owner new_resource.owner
194
+ group new_resource.group
195
+ mode '0755'
196
+ source "sv-#{new_resource.control_template_names[signal]}-#{signal}.erb"
197
+ cookbook template_cookbook
198
+ variables(options: new_resource.options)
199
+ action :create
200
+ end
201
+ end
202
+
203
+ # lsb_init
204
+ if node['platform'] == 'debian'
205
+ ruby_block "unlink #{parsed_lsb_init_dir}/#{new_resource.service_name}" do
206
+ block { ::File.unlink("#{parsed_lsb_init_dir}/#{new_resource.service_name}") }
207
+ only_if { ::File.symlink?("#{parsed_lsb_init_dir}/#{new_resource.service_name}") }
208
+ end
209
+
210
+ template "#{parsed_lsb_init_dir}/#{new_resource.service_name}" do
211
+ owner 'root'
212
+ group 'root'
213
+ mode '00755'
214
+ cookbook 'runit'
215
+ source 'init.d.erb'
216
+ variables(
217
+ name: new_resource.service_name,
218
+ sv_bin: new_resource.sv_bin,
219
+ init_dir: ::File.join(parsed_lsb_init_dir, '')
220
+ )
221
+ action :create
222
+ end
223
+ else
224
+ link "#{parsed_lsb_init_dir}/#{new_resource.service_name}" do
225
+ to sv_bin
226
+ action :create
227
+ end
228
+ end
229
+
230
+ # Create/Delete service down file
231
+ # To prevent unexpected behavior, require users to explicitly set
232
+ # delete_downfile to remove any down file that may already exist
233
+ df_action = :nothing
234
+ if new_resource.start_down
235
+ df_action = :create
236
+ elsif new_resource.delete_downfile
237
+ df_action = :delete
238
+ end
239
+
240
+ file down_file do
241
+ mode 00644
242
+ backup false
243
+ content '# File created and managed by chef!'
244
+ action df_action
245
+ end
246
+ end
247
+ end
248
+
249
+ action :disable do
250
+ ruby_block "disable #{new_resource.service_name}" do
251
+ block { disable_service }
252
+ only_if { enabled? }
253
+ end
254
+ end
255
+
256
+ action :enable do
257
+ # FIXME: remove action_create in next major version
258
+ action_create
259
+
260
+ directory new_resource.service_dir
261
+
262
+ link "#{service_dir_name}" do
263
+ to sv_dir_name
264
+ action :create
265
+ end
266
+
267
+ ruby_block "wait for #{new_resource.service_name} service socket" do
268
+ block do
269
+ wait_for_service
270
+ end
271
+ action :run
272
+ end
273
+ end
274
+
275
+ # signals
276
+ VALID_SIGNALS.each do |signal, signal_name|
277
+ action(signal_name || signal) do
278
+ if running?
279
+ Chef::Log.info "#{new_resource} signalled (#{(signal_name || signal).to_s.upcase})"
280
+ runit_send_signal(signal, signal_name)
281
+ else
282
+ Chef::Log.debug "#{new_resource} not running - nothing to do"
283
+ end
284
+ end
285
+ end
286
+
287
+ action :nothing do
288
+ end
289
+
290
+ action :restart do
291
+ restart_service
292
+ end
293
+
294
+ action :start do
295
+ if running?
296
+ Chef::Log.debug "#{new_resource} already running - nothing to do"
297
+ else
298
+ start_service
299
+ Chef::Log.info "#{new_resource} started"
300
+ end
301
+ end
302
+
303
+ action :stop do
304
+ if running?
305
+ stop_service
306
+ Chef::Log.info "#{new_resource} stopped"
307
+ else
308
+ Chef::Log.debug "#{new_resource} already stopped - nothing to do"
309
+ end
310
+ end
311
+
312
+ action :reload do
313
+ if running?
314
+ reload_service
315
+ Chef::Log.info "#{new_resource} reloaded"
316
+ else
317
+ Chef::Log.debug "#{new_resource} not running - nothing to do"
318
+ end
319
+ end
320
+
321
+ action :status do
322
+ running?
323
+ end
324
+ end
325
+ end
326
+ end