Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions documentation/nginx_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
| `group` | String | `root` | Nginx run-as/file/folder group. |
| `mode` | String | `0640` | Nginx configuration file mode. |
| `folder_mode` | String | `0750` | Nginx configuration folder mode. |
| `log_dir_mode` | String | `0755` | Nginx log directory mode. |
| `log_dir_owner` | String | `root` | Nginx log directory owner. |
| `log_dir_group` | String | `root` | Nginx log directory group. |
| `process_user` | String | `www-data` (Debian) or `nginx` | Nginx run-as user. |
| `process_group` | String | `www-data` (Debian) or `nginx` | Nginx run-as group. |
| `worker_processes` | Integer, String | `auto` | The number of worker processes. |
Expand All @@ -43,3 +46,15 @@ nginx_config 'nginx' do
notifies :reload, 'nginx_service[nginx]', :delayed
end
```

### Using custom log directory permissions

```ruby
nginx_config 'nginx' do
log_dir_mode '0750'
log_dir_owner 'nginx'
log_dir_group 'nginx'
action :create
notifies :reload, 'nginx_service[nginx]', :delayed
end
```
18 changes: 15 additions & 3 deletions resources/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
description: 'Folder mode',
default: '0750'

property :log_dir_mode, String,
description: 'Log directory mode',
default: lazy { platform_family?('debian') ? '0755' : '0750' }

property :log_dir_owner, String,
description: 'Log directory owner',
default: lazy { owner }

property :log_dir_group, String,
description: 'Log directory group',
default: lazy { group }

property :process_user, String,
description: 'Nginx process user',
default: lazy { nginx_user }
Expand Down Expand Up @@ -146,9 +158,9 @@ def default_site_enabled?
end

directory nginx_log_dir do
owner new_resource.owner
group new_resource.group
mode new_resource.folder_mode
owner new_resource.log_dir_owner
group new_resource.log_dir_group
mode new_resource.log_dir_mode
end

%w(default.conf example_ssl.conf).each do |config|
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/resources/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,32 @@
it { is_expected.to create_directory('/etc/nginx/conf.d').with_mode('0750') }
it { is_expected.to create_directory('/etc/nginx/conf.http.d').with_mode('0750') }
end

context 'with custom log directory properties' do
recipe do
nginx_install 'distro'
nginx_config 'default' do
log_dir_mode '0750'
log_dir_owner 'nginx'
log_dir_group 'nginx'
end
end

it { is_expected.to create_directory('/var/log/nginx').with_mode('0750').with_owner('nginx').with_group('nginx') }
it { is_expected.to create_directory('/etc/nginx/conf.d').with_mode('0750') }
it { is_expected.to create_directory('/etc/nginx/conf.http.d').with_mode('0750') }
end

context 'on debian platform' do
platform 'ubuntu'

recipe do
nginx_install 'distro'
nginx_config 'default'
end

it { is_expected.to create_directory('/var/log/nginx').with_mode('0755').with_owner('root') }
it { is_expected.to create_directory('/etc/nginx/conf.d').with_mode('0750') }
it { is_expected.to create_directory('/etc/nginx/conf.http.d').with_mode('0750') }
end
end