PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/runit/test/cookbooks/runit_test/recipes/service.rb

https://github.com/easybiblabs/easybib-cookbooks
Ruby | 230 lines | 129 code | 41 blank | 60 comment | 2 complexity | af6613e1de3dbba9ef2dba8754938145 MD5 | raw file
  1. #
  2. # Cookbook Name:: runit_test
  3. # Recipe:: service
  4. #
  5. # Copyright 2012, 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. include_recipe 'runit::default'
  20. link '/usr/local/bin/sv' do
  21. to '/usr/bin/sv'
  22. end
  23. package 'socat'
  24. package 'netcat' do
  25. package_name 'nc' if platform_family?('rhel', 'fedora')
  26. end
  27. package 'lsof' do
  28. package_name 'lsof' if platform_family?('rhel', 'fedora')
  29. end
  30. # Create a normal user to run services later
  31. group 'floyd'
  32. user 'floyd' do
  33. comment 'Floyd the App Runner'
  34. gid 'floyd'
  35. shell '/bin/bash'
  36. home '/home/floyd'
  37. manage_home true
  38. supports manage_home: true
  39. end
  40. %w(sv service).each do |dir|
  41. directory "/home/floyd/#{dir}" do
  42. owner 'floyd'
  43. group 'floyd'
  44. recursive true
  45. end
  46. end
  47. # Create a service with all the fixin's
  48. runit_service 'plain-defaults'
  49. # Create a service that doesn't use the svlog
  50. runit_service 'no-svlog' do
  51. log false
  52. end
  53. # Create a service that uses the default svlog
  54. runit_service 'default-svlog' do
  55. default_logger true
  56. log_size 10_000 # smallish 10k
  57. log_num 12
  58. log_processor 'gzip'
  59. end
  60. # Create a service that has a check script
  61. runit_service 'checker' do
  62. check true
  63. end
  64. # Create a service that has a finish script
  65. runit_service 'finisher' do
  66. finish true
  67. end
  68. # Create a service that uses env files
  69. runit_service 'env-files' do
  70. env('PATH' => '$PATH:/opt/chef/embedded/bin')
  71. end
  72. # Create a service that sets options for the templates
  73. runit_service 'template-options' do
  74. options(raspberry: 'delicious')
  75. end
  76. # Create a service that uses control signal files
  77. runit_service 'control-signals' do
  78. control ['u']
  79. end
  80. # Create a runsvdir service for a normal user
  81. runit_service 'runsvdir-floyd'
  82. # Create a service with different timeout
  83. runit_service 'timer' do
  84. sv_timeout 4
  85. check true
  86. end
  87. # Create a service with verbose enabled
  88. runit_service 'chatterbox' do
  89. sv_verbose true
  90. end
  91. # # Create a service running by a normal user in its runsvdir
  92. runit_service 'floyds-app' do
  93. sv_dir '/home/floyd/sv'
  94. service_dir '/home/floyd/service'
  95. owner 'floyd'
  96. group 'floyd'
  97. end
  98. # Create a service with differently named template files
  99. runit_service 'yerba' do
  100. log_template_name 'yerba-matte'
  101. check_script_template_name 'yerba-matte'
  102. finish_script_template_name 'yerba-matte'
  103. end
  104. # Create a service with differently named template file, using default logger with non-default log_dir
  105. runit_service 'yerba-alt' do
  106. run_template_name 'calabash'
  107. default_logger true
  108. log_dir '/var/log/yerba/matte/'
  109. end
  110. # Create a service with a template sourced from another cookbook
  111. runit_service 'ayahuasca' do
  112. run_template_name 'ayahuasca'
  113. default_logger true
  114. log_dir '/opt/ayahuasca/log'
  115. cookbook 'runit_other_test'
  116. end
  117. # Note: this won't update the run script for the above due to
  118. # http://tickets.chef.io/browse/COOK-2353
  119. # runit_service 'the other name for yerba-alt' do
  120. # service_name 'yerba-alt'
  121. # default_logger true
  122. # end
  123. runit_service 'exist-disabled' do
  124. action [:create, :disable]
  125. end
  126. # unless platform_family?('rhel', 'fedora')
  127. # # Create a service that has a package with its own service directory
  128. # package 'git-daemon-run'
  129. # runit_service 'git-daemon' do
  130. # sv_templates false
  131. # end
  132. # end
  133. # Despite waiting for runit to create supervise/ok, sometimes services
  134. # are supervised, but not actually fully started
  135. ruby_block 'sleep 5s to allow services to be fully started' do
  136. block do
  137. sleep 5
  138. end
  139. end
  140. # # Notify the plain defaults service as a normal service resource
  141. file '/tmp/notifier' do
  142. content Time.now.to_s
  143. notifies :restart, 'service[plain-defaults]', :immediately
  144. end
  145. file '/tmp/notifier-2' do
  146. content Time.now.to_s
  147. notifies :restart, 'runit_service[plain-defaults]', :immediately
  148. end
  149. # # Test for COOK-2867
  150. # link '/etc/init.d/cook-2867' do
  151. # to '/usr/bin/sv'
  152. # end
  153. # runit_service 'cook-2867' do
  154. # default_logger true
  155. # end
  156. # create a service using an alternate sv binary
  157. runit_service 'alternative-sv-bin' do
  158. sv_bin '/usr/local/bin/sv'
  159. end
  160. runit_service 'downed-service-6702' do
  161. start_down true
  162. end
  163. runit_service 'un-downed-service' do
  164. start_down true
  165. end
  166. runit_service 'un-downed-service remove down' do
  167. service_name 'un-downed-service'
  168. log_template_name 'un-downed-service'
  169. run_template_name 'un-downed-service'
  170. start_down false
  171. end
  172. runit_service 'un-downed-service-deleted' do
  173. start_down true
  174. end
  175. runit_service 'un-downed-service-deleted remove down' do
  176. service_name 'un-downed-service-deleted'
  177. log_template_name 'un-downed-service-deleted'
  178. run_template_name 'un-downed-service-deleted'
  179. start_down false
  180. delete_downfile true
  181. end
  182. # Use a service with all the fixin's to ensure all actions are
  183. # available and working
  184. actions = (runit_service('plain-defaults').allowed_actions - [:enable, :disable]) + [:disable, :enable]
  185. actions.each do |test_action|
  186. runit_service 'plain-defaults' do
  187. action test_action
  188. end
  189. end