Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit a873316

Browse files
committed
Chef 12 support
This commit adds Chef 12 support and changes some of the properties of the resources. Configuration is more automatic. See README for notes on resource changes.
1 parent b6616da commit a873316

11 files changed

+68
-29
lines changed

.rubocop.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Metrics/LineLength:
2+
Max: 150
3+
4+
Metrics/BlockLength:
5+
Exclude:
6+
- 'resources/config.rb'

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
This file is used to list changes made in each version of the gamegos-supervisor cookbook.
44

5+
# 1.0.0
6+
7+
Update
8+
9+
- Add Chef 12 support
10+
- Add tests
11+
- Testing Ubuntu and CentOS
12+
- Update documentation
13+
- Fixes some bugs
14+
15+
516
# 0.1.0
617

718
Initial release.
819

920
- change 0
1021
- change 1
11-

README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This cookbook installs and configures [Supervisor](https://github.com/Supervisor
1212

1313
## Chef
1414

15-
- Chef 13+
15+
- Chef 12+
1616

1717
## Cookbooks
1818

@@ -82,6 +82,7 @@ Define configurations of supervisord.
8282
- `unix_http_server_chown` - (is: String)
8383
- `unix_http_server_username` - (is: String)
8484
- `unix_http_server_password` - (is: String)
85+
- `supervisord_config_directory` - (is: String)
8586
- `supervisord_log_directory` - (is: String)
8687
- `supervisord_logfile` - (is: String)
8788
- `supervisord_logfile_maxbytes` - (is: String)
@@ -105,7 +106,9 @@ Define configurations of supervisord.
105106
#### Examples
106107

107108
```ruby
108-
supervisor_config '/etc/supervisor' do
109+
# Create a custom config
110+
supervisor_config 'supervisor' do
111+
supervisord_config_directory '/etc/supervisor'
109112
socket_file '/run/supervisor.sock'
110113
inet_port '0.0.0.0:9010'
111114
inet_username 'randy'
@@ -117,9 +120,14 @@ end
117120
```
118121

119122
```ruby
120-
supervisor_config '/home/rudy/supervisor'
123+
# Create a default config
124+
supervisor_config 'supervisor'
121125
```
122126

127+
#### Notes
128+
129+
The name property of the resource should always just be `supervisor`.
130+
123131
### supervisor_process
124132

125133
Creates a process for supervisor. The process may be a 'program', 'eventlistener' or 'fcgi-program'.
@@ -221,5 +229,9 @@ Creates Supervisor service for your systems.
221229
#### Examples
222230

223231
```ruby
224-
supervisor_service 'not_important'
232+
supervisor_service 'supervisor'
225233
```
234+
235+
#### Note
236+
237+
The name property of the resource should always just be `supervisor`.

attributes/default.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
default['supervisor']['supervisord_default_path'] = if platform_family?('rhel')
2+
'/usr/bin'
3+
else
4+
'/usr/local/bin'
5+
end

metadata.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
license 'GPL-3.0'
55
description 'Installs/Configures supervisor'
66
long_description 'Installs/Configures supervisor'
7-
version '0.1.0'
8-
chef_version '>= 13.0'
7+
chef_version '>= 12.0'
8+
%w[amazon centos debian redhat ubuntu].each do |os|
9+
supports os
10+
end
11+
version '1.0.0'
912

1013
# The `issues_url` points to the location where issues for this cookbook are
1114
# tracked. A `View Issues` link will be displayed on this cookbook's page when

recipes/default.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# Copyright:: 2018, The Authors, All Rights Reserved.
66
supervisor_install '3.3'
77

8-
supervisor_config '/etc/supervisor' do
9-
action :create
10-
end
8+
supervisor_config 'supervisor'
119

1210
supervisor_service 'supervisor'

resources/config.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# To learn more about Custom Resources, see https://docs.chef.io/custom_resources.html
22
resource_name :supervisor_config
33

4-
property :supervisor_directory, String, name_property: true
4+
property :name, String, name_property: true
5+
property :supervisord_config_directory, String, default: '/etc/supervisor'
56
property :socket_file, String, default: '/var/run/supervisor.sock'
67

78
property :unix_http_server_chmod, String, default: '700'
@@ -32,13 +33,13 @@
3233
property :inet_password, [String, NilClass], default: nil
3334

3435
property :include_files, [String, Array], default: lazy {
35-
"#{supervisor_directory}/*.conf"
36+
"#{supervisord_config_directory}/*.conf"
3637
}
3738

3839
property :template, String, default: 'gamegos-supervisor'
3940

4041
action :create do
41-
supervisor_config_directory = new_resource.supervisor_directory
42+
supervisor_config_directory = new_resource.supervisord_config_directory
4243
supervisor_config_file = "#{supervisor_config_directory}/supervisord.conf"
4344
with_run_context :root do
4445
node.run_state['supervisor'] ||= {}
@@ -63,14 +64,14 @@
6364
recursive true
6465
end
6566

66-
template 'supervisord_config_file' do
67+
declare_resource(:template, 'supervisord_config_file') do
6768
cookbook new_resource.template
6869
path supervisor_config_file
6970
source 'supervisord.conf.erb'
7071
owner 'root'
7172
group 'root'
7273
mode '644'
7374
variables config: new_resource
74-
notifies :reload, 'supervisor_service[supervisor]', :delayed
75+
notifies :reload, find_resource(:supervisor_service, 'supervisor'), :delayed
7576
end
7677
end

resources/group.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
property :template, String, default: 'gamegos-supervisor'
88

99
action :create do
10-
template "supervisor_group_#{new_resource.name}" do
10+
declare_resource(:template, "supervisor_group_#{new_resource.name}") do
1111
cookbook new_resource.template
1212
path lazy { "#{node.run_state['supervisor']['directory']}/group_#{new_resource.name}.conf" }
1313
source 'group.conf.erb'
1414
owner 'root'
1515
group 'root'
1616
mode '644'
1717
variables group: new_resource
18-
notifies :reload, 'supervisor_service[supervisor]', :delayed
18+
notifies :reload, find_resource(:supervisor_service, 'supervisor'), :delayed
1919
end
2020
end
2121

2222
action :delete do
2323
file 'delete specific group configuration file' do
2424
path lazy { "#{node.run_state['supervisor']['directory']}/group_#{new_resource.name}.conf" }
2525
action :delete
26-
notifies :reload, 'supervisor_service[supervisor]', :delayed
26+
notifies :reload, find_resource(:supervisor_service, 'supervisor'), :delayed
2727
end
2828
end

resources/install.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
property :version, String, name_property: true
55

66
action :create do
7-
node.override['poise-python']['options']['pip_version'] = '18.0'
8-
9-
python_runtime '2'
7+
python_runtime 'supervisor' do
8+
provider :system
9+
version '2'
10+
pip_version '18.0'
11+
end
1012

1113
python_package 'supervisor' do
1214
version new_resource.version

resources/process.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
action :create do
5151
clean_name = new_resource.name.downcase.tr(' ', '_')
5252
unique_name_for_process = "#{new_resource.type}_#{clean_name}"
53-
template "supervisor_#{unique_name_for_process}" do
53+
declare_resource(:template, "supervisor_#{unique_name_for_process}") do
5454
cookbook new_resource.template
5555
path lazy { "#{node.run_state['supervisor']['directory']}/#{unique_name_for_process}.conf" }
5656
source 'process.conf.erb'
@@ -61,7 +61,7 @@
6161
name: clean_name,
6262
service: new_resource
6363
)
64-
notifies :reload, 'supervisor_service[supervisor]', :delayed
64+
notifies :reload, find_resource(:supervisor_service, 'supervisor'), :delayed
6565
end
6666
end
6767

@@ -71,6 +71,6 @@
7171
file 'delete specific program configuration file' do
7272
path lazy { "#{node.run_state['supervisor']['directory']}/#{unique_name_for_process}.conf" }
7373
action :delete
74-
notifies :reload, 'supervisor_service[supervisor]', :delayed
74+
notifies :reload, find_resource(:supervisor_service, 'supervisor'), :delayed
7575
end
7676
end

resources/service.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# To learn more about Custom Resources, see https://docs.chef.io/custom_resources.html
22
resource_name :supervisor_service
3-
property :supervisord_executable_path, String, default: '/usr/local/bin/supervisord'
3+
property :supervisord_executable_path, String, default: lazy { node['supervisor']['supervisord_default_path'] }
4+
property :name, String, name_property: true
45

56
action :create do
67
poise_service 'supervisor' do
7-
command lazy { "#{new_resource.supervisord_executable_path} -n -c #{node.run_state['supervisor']['config_file']}" }
8+
command lazy { "#{new_resource.supervisord_executable_path}/supervisord -n -c #{node.run_state['supervisor']['config_file']}" }
89
end
910
end
1011

1112
action :reload do
12-
with_run_context :root do
13-
find_resource(:poise_service, 'supervisor') do
14-
end.run_action(:reload)
13+
execute 'supervisorctl reread' do
14+
command lazy { "#{new_resource.supervisord_executable_path}/supervisorctl -c #{node.run_state['supervisor']['config_file']} reread" }
15+
action :run
16+
only_if "#{new_resource.supervisord_executable_path}/supervisorctl -c #{node.run_state['supervisor']['config_file']} avail"
1517
end
1618
end

0 commit comments

Comments
 (0)