forked from sous-chefs/nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a921767
commit 70eb1b7
Showing
17 changed files
with
226 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ bin | |
coverage/ | ||
doc/ | ||
Gemfile.lock | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
AllCops: | ||
Exclude: | ||
- spec/libraries_specs/helpers_spec.rb | ||
- Guardfile | ||
- 'vendor/**/*' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class Chef | ||
class Provider | ||
class NginxService | ||
# Provider actions for platforms using Systemd | ||
# | ||
# @since 3.0.0 | ||
# @author Miguel Ferreira <[email protected]> | ||
class NginxServiceSystemd < Chef::Provider::NginxServiceBase | ||
provides :nginx_service, os: 'linux' do | ||
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) | ||
end if defined?(provides) | ||
|
||
action :start do | ||
template "#{res_name} :create /etc/systemd/system/#{nginx_instance_name}" do | ||
path "/etc/systemd/system/#{nginx_instance_name}.service" | ||
cookbook 'nginx' | ||
source 'systemd/nginx.erb' | ||
owner 'root' | ||
group 'root' | ||
mode 00744 | ||
variables(nginx_instance_name: nginx_instance_name) | ||
action :create | ||
notifies :run, 'execute[systemctl daemon-reload]', :immediately | ||
end | ||
|
||
execute 'systemctl daemon-reload' do | ||
action :nothing | ||
end | ||
|
||
service "#{nginx_instance_name} :start" do | ||
service_name nginx_instance_name | ||
provider Chef::Provider::Service::Systemd | ||
supports status: true, restart: true | ||
action [:start, :enable] | ||
end | ||
end | ||
|
||
action :stop do | ||
service "#{nginx_instance_name} :stop" do | ||
service_name nginx_instance_name | ||
provider Chef::Provider::Service::Systemd | ||
supports status: true, restart: true | ||
action [:stop, :disable] | ||
end | ||
end | ||
|
||
action :delete do | ||
file "#{res_name} :delete /etc/systemd/system/#{nginx_instance_name}" do | ||
path "/etc/systemd/system/#{nginx_instance_name}.service" | ||
action :delete | ||
end | ||
|
||
service "#{res_name} :delete #{nginx_instance_name}" do | ||
service_name nginx_instance_name | ||
provider Chef::Provider::Service::Systemd | ||
supports status: true | ||
action [:stop, :disable] | ||
notifies :run, 'execute[systemctl daemon-reload]', :immediately | ||
end | ||
|
||
execute 'systemctl daemon-reload' do | ||
action :nothing | ||
end | ||
end | ||
|
||
action :restart do | ||
# @todo create recipes and tests for this | ||
service "#{res_name} :restart #{nginx_instance_name}" do | ||
service_name nginx_instance_name | ||
supports status: true, restart: true | ||
provider Chef::Provider::Service::Systemd | ||
action :restart | ||
end | ||
end | ||
|
||
action :reload do | ||
# @todo create recipes and tests for this | ||
service "#{res_name} :reload #{nginx_instance_name}" do | ||
service_name nginx_instance_name | ||
provider Chef::Provider::Service::Systemd | ||
supports status: true, reload: true | ||
action :reload | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
spec/libraries_specs/resource/nginx_service/create/centos_7_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe 'resource_nginx_service :create on centos 7' do | ||
before do | ||
allow(Chef::Platform::ServiceHelpers).to receive(:service_resource_providers).and_return([:systemd]) | ||
end | ||
|
||
cached(:chef_run) do | ||
ChefSpec::SoloRunner.new( | ||
step_into: 'nginx_service', | ||
platform: 'centos', | ||
version: '7.0' | ||
).converge('nginx::example') | ||
end | ||
|
||
it_behaves_like 'create a named nginx_service', 'example' | ||
|
||
it_behaves_like 'nginx_service :create', 'example' | ||
it_behaves_like 'nginx_service :start', 'example' | ||
it_behaves_like 'nginx_service #upstart', 'example' | ||
|
||
it_behaves_like 'nginx_config :create', 'example' | ||
end |
18 changes: 18 additions & 0 deletions
18
spec/libraries_specs/resource/nginx_service/delete/centos_7_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
describe 'resource_nginx_service :delete on centos 7' do | ||
cached(:chef_run) do | ||
ChefSpec::SoloRunner.new( | ||
step_into: 'nginx_service', | ||
platform: 'centos', | ||
version: '7.0' | ||
).converge('nginx_service_test::single', 'nginx_service_test::delete') | ||
end | ||
|
||
it_behaves_like 'create a named nginx_service', 'single' | ||
|
||
it_behaves_like 'nginx_service :create', 'single' | ||
it_behaves_like 'nginx_service :start', 'single' | ||
|
||
xit 'stops the service' do | ||
expect(chef_run).to stop_service('nginx-single') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Dynamically generated by Chef - local modifications will be overwritten | ||
|
||
[Unit] | ||
Description=The nginx HTTP and reverse proxy server for <%= @nginx_instance_name %> | ||
After=network.target remote-fs.target nss-lookup.target | ||
|
||
[Service] | ||
Type=forking | ||
PIDFile=/run/<%= @nginx_instance_name %>.pid | ||
ExecStartPre=/usr/sbin/nginx -t | ||
ExecStart=/usr/sbin/nginx -c /etc/<%= @nginx_instance_name %>/nginx.conf | ||
ExecReload=/bin/kill -s HUP $MAINPID | ||
KillMode=process | ||
KillSignal=SIGQUIT | ||
TimeoutStopSec=5 | ||
PrivateTmp=true | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
version '0.1.0' | ||
|
||
depends 'apt' | ||
depends 'yum-epel' | ||
depends 'nginx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters