Commit 05326139 authored by Dan Buch's avatar Dan Buch Committed by Seth Vargo
Browse files

[COOK-3600] Add SmartOS support


Signed-off-by: default avatarSeth Vargo <sethvargo@gmail.com>
parent 083be068
......@@ -32,12 +32,15 @@ default['rsyslog']['preserve_fqdn'] = 'off'
default['rsyslog']['high_precision_timestamps'] = false
default['rsyslog']['repeated_msg_reduction'] = 'on'
default['rsyslog']['logs_to_forward'] = '*.*'
default['rsyslog']['enable_imklog'] = true
default['rsyslog']['config_prefix'] = '/etc'
# The most likely platform-specific attributes
default['rsyslog']['service_name'] = 'rsyslog'
default['rsyslog']['user'] = 'root'
default['rsyslog']['group'] = 'adm'
default['rsyslog']['priv_seperation'] = false
default['rsyslog']['modules'] = %w(imuxsock imklog)
case node['platform']
when 'ubuntu'
......@@ -49,4 +52,8 @@ when 'ubuntu'
end
when 'arch'
default['rsyslog']['service_name'] = 'rsyslogd'
when 'smartos'
default['rsyslog']['config_prefix'] = '/opt/local/etc'
default['rsyslog']['modules'] = %w(immark imsolaris imtcp imudp)
default['rsyslog']['group'] = 'root'
end
......@@ -41,17 +41,17 @@ end
remote_type = node['rsyslog']['use_relp'] ? 'relp' : 'remote'
template '/etc/rsyslog.d/49-remote.conf' do
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/49-remote.conf" do
source "49-#{remote_type}.conf.erb"
owner 'root'
group 'root'
mode '0644'
variables :servers => rsyslog_servers
variables(:servers => rsyslog_servers)
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
only_if { node['rsyslog']['remote_logs'] }
end
file '/etc/rsyslog.d/server.conf' do
file "#{node['rsyslog']['config_prefix']}/rsyslog.d/server.conf" do
action :delete
notifies :reload, "service[#{node['rsyslog']['service_name']}]"
end
......@@ -20,7 +20,7 @@
package 'rsyslog'
package 'rsyslog-relp' if node['rsyslog']['use_relp']
directory '/etc/rsyslog.d' do
directory "#{node['rsyslog']['config_prefix']}/rsyslog.d" do
owner 'root'
group 'root'
mode '0755'
......@@ -34,7 +34,7 @@ end
# Our main stub which then does its own rsyslog-specific
# include of things in /etc/rsyslog.d/*
template '/etc/rsyslog.conf' do
template "#{node['rsyslog']['config_prefix']}/rsyslog.conf" do
source 'rsyslog.conf.erb'
owner 'root'
group 'root'
......@@ -42,7 +42,7 @@ template '/etc/rsyslog.conf' do
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
template '/etc/rsyslog.d/50-default.conf' do
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/50-default.conf" do
source '50-default.conf.erb'
owner 'root'
group 'root'
......@@ -55,6 +55,11 @@ if platform_family?('rhel') && node['platform_version'].to_i < 6
service 'syslog' do
action [:stop, :disable]
end
# syslog needs to be stopped before rsyslog can be started on SmartOS
elsif platform_family?('smartos')
service 'system-log' do
action :disable
end
end
service node['rsyslog']['service_name'] do
......
......@@ -29,7 +29,7 @@ directory node['rsyslog']['log_dir'] do
recursive true
end
template '/etc/rsyslog.d/35-server-per-host.conf' do
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/35-server-per-host.conf" do
source '35-server-per-host.conf.erb'
owner 'root'
group 'root'
......@@ -37,8 +37,8 @@ template '/etc/rsyslog.d/35-server-per-host.conf' do
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
file '/etc/rsyslog.d/remote.conf' do
file "#{node['rsyslog']['config_prefix']}/rsyslog.d/remote.conf" do
action :delete
notifies :reload, "service[#{node['rsyslog']['service_name']}]"
only_if { ::File.exists?('/etc/rsyslog.d/remote.conf') }
only_if { ::File.exists?("#{node['rsyslog']['config_prefix']}/rsyslog.d/remote.conf") }
end
......@@ -14,10 +14,13 @@ describe 'rsyslog::client' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04') do |node|
node.set['rsyslog']['server_ip'] = '10.0.0.50'
node.set['rsyslog']['server_ip'] = server_ip
end.converge('rsyslog::client')
end
let(:server_ip) { "10.#{rand(1..9)}.#{rand(1..9)}.50" }
let(:service_resource) { 'service[rsyslog]' }
it 'includes the default recipe' do
expect(chef_run).to include_recipe('rsyslog::default')
end
......@@ -26,7 +29,7 @@ describe 'rsyslog::client' do
let(:template) { chef_run.template('/etc/rsyslog.d/49-remote.conf') }
it 'creates the template' do
expect(chef_run).to create_file_with_content('/etc/rsyslog.d/49-remote.conf', '*.* @@10.0.0.50:514')
expect(chef_run).to create_file_with_content(template.path, "*.* @@#{server_ip}:514")
end
it 'is owned by root:root' do
......@@ -39,7 +42,34 @@ describe 'rsyslog::client' do
end
it 'notifies restarting the service' do
expect(template).to notify('service[rsyslog]', :restart)
expect(template).to notify(service_resource, :restart)
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z') do |node|
node.set['rsyslog']['server_ip'] = server_ip
end.converge('rsyslog::client')
end
let(:template) { chef_run.template('/opt/local/etc/rsyslog.d/49-remote.conf') }
it 'creates the template' do
expect(chef_run).to create_file_with_content(template.path, "*.* @@#{server_ip}:514")
end
it 'is owned by root:root' do
expect(template.owner).to eq('root')
expect(template.group).to eq('root')
end
it 'has 0644 permissions' do
expect(template.mode).to eq('0644')
end
it 'notifies restarting the service' do
expect(template).to notify(service_resource, :restart)
end
end
end
......@@ -47,11 +77,29 @@ describe 'rsyslog::client' do
let(:file) { chef_run.file('/etc/rsyslog.d/server.conf') }
it 'deletes the file' do
expect(chef_run).to delete_file('/etc/rsyslog.d/server.conf')
expect(chef_run).to delete_file(file.path)
end
it 'notifies restarting the service' do
expect(file).to notify('service[rsyslog]', :reload)
expect(file).to notify(service_resource, :reload)
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z') do |node|
node.set['rsyslog']['server_ip'] = server_ip
end.converge('rsyslog::client')
end
let(:file) { chef_run.file('/opt/local/etc/rsyslog.d/server.conf') }
it 'deletes the file' do
expect(chef_run).to delete_file(file.path)
end
it 'notifies restarting the service' do
expect(file).to notify(service_resource, :reload)
end
end
end
end
......@@ -5,6 +5,8 @@ describe 'rsyslog::default' do
ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04').converge('rsyslog::default')
end
let(:service_resource) { 'service[rsyslog]' }
it 'installs the rsyslog part' do
expect(chef_run).to install_package('rsyslog')
end
......@@ -25,7 +27,7 @@ describe 'rsyslog::default' do
let(:directory) { chef_run.directory('/etc/rsyslog.d') }
it 'creates the directory' do
expect(chef_run).to create_directory('/etc/rsyslog.d')
expect(chef_run).to create_directory(directory.path)
end
it 'is owned by root:root' do
......@@ -36,6 +38,27 @@ describe 'rsyslog::default' do
it 'has 0755 permissions' do
expect(directory.mode).to eq('0755')
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z').converge('rsyslog::default')
end
let(:directory) { chef_run.directory('/opt/local/etc/rsyslog.d') }
it 'creates the directory' do
expect(chef_run).to create_directory(directory.path)
end
it 'is owned by root:root' do
expect(directory.owner).to eq('root')
expect(directory.group).to eq('root')
end
it 'has 0755 permissions' do
expect(directory.mode).to eq('0755')
end
end
end
context '/var/spool/rsyslog directory' do
......@@ -57,9 +80,10 @@ describe 'rsyslog::default' do
context '/etc/rsyslog.conf template' do
let(:template) { chef_run.template('/etc/rsyslog.conf') }
let(:modules) { %w(imuxsock imklog) }
it 'creates the template' do
expect(chef_run).to create_file_with_content('/etc/rsyslog.conf', 'Configuration file for rsyslog v3')
expect(chef_run).to create_file_with_content(template.path, 'Configuration file for rsyslog v3')
end
it 'is owned by root:root' do
......@@ -72,7 +96,45 @@ describe 'rsyslog::default' do
end
it 'notifies restarting the service' do
expect(template).to notify('service[rsyslog]', :restart)
expect(template).to notify(service_resource, :restart)
end
it 'includes the right modules' do
modules.each do |mod|
expect(chef_run).to create_file_with_content(template.path, /^\$ModLoad #{mod}/)
end
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z').converge('rsyslog::default')
end
let(:template) { chef_run.template('/opt/local/etc/rsyslog.conf') }
let(:modules) { %w(immark imsolaris imtcp imudp) }
it 'creates the template' do
expect(chef_run).to create_file_with_content(template.path, 'Configuration file for rsyslog v3')
end
it 'is owned by root:root' do
expect(template.owner).to eq('root')
expect(template.group).to eq('root')
end
it 'has 0644 permissions' do
expect(template.mode).to eq('0644')
end
it 'notifies restarting the service' do
expect(template).to notify(service_resource, :restart)
end
it 'includes the right modules' do
modules.each do |mod|
expect(chef_run).to create_file_with_content(template.path, /^\$ModLoad #{mod}/)
end
end
end
end
......@@ -80,7 +142,7 @@ describe 'rsyslog::default' do
let(:template) { chef_run.template('/etc/rsyslog.d/50-default.conf') }
it 'creates the template' do
expect(chef_run).to create_file_with_content('/etc/rsyslog.d/50-default.conf', 'Default rules for rsyslog.')
expect(chef_run).to create_file_with_content(template.path, 'Default rules for rsyslog.')
end
it 'is owned by root:root' do
......@@ -93,7 +155,36 @@ describe 'rsyslog::default' do
end
it 'notifies restarting the service' do
expect(template).to notify('service[rsyslog]', :restart)
expect(template).to notify(service_resource, :restart)
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z').converge('rsyslog::default')
end
let(:template) { chef_run.template('/opt/local/etc/rsyslog.d/50-default.conf') }
it 'creates the template' do
expect(chef_run).to create_file_with_content(template.path, 'Default rules for rsyslog.')
end
it 'is owned by root:root' do
expect(template.owner).to eq('root')
expect(template.group).to eq('root')
end
it 'has 0644 permissions' do
expect(template.mode).to eq('0644')
end
it 'notifies restarting the service' do
expect(template).to notify(service_resource, :restart)
end
it 'uses the SmartOS-specific template' do
expect(chef_run).to create_file_with_content(template.path, %r{/var/adm/messages$})
end
end
end
......@@ -102,12 +193,22 @@ describe 'rsyslog::default' do
ChefSpec::ChefRunner.new(platform: 'redhat', version: '5.8').converge('rsyslog::default')
end
it 'stops and starts the syslog service on REHL' do
it 'stops and starts the syslog service on RHEL' do
expect(chef_run).to stop_service('syslog')
expect(chef_run).to disable_service('syslog')
end
end
context 'system-log service' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z').converge('rsyslog::default')
end
it 'stops the system-log service on SmartOS' do
expect(chef_run).to disable_service('system-log')
end
end
context 'rsyslog service' do
it 'starts and enables the service' do
expect(chef_run).to set_service_to_start_on_boot('rsyslog')
......
......@@ -7,6 +7,8 @@ describe 'rsyslog::server' do
end.converge('rsyslog::server')
end
let(:service_resource) { 'service[rsyslog]' }
it "sets node['rsyslog']['server'] to true" do
expect(chef_run.node['rsyslog']['server']).to be_true
end
......@@ -36,7 +38,7 @@ describe 'rsyslog::server' do
let(:template) { chef_run.template('/etc/rsyslog.d/35-server-per-host.conf') }
it 'creates the template' do
expect(chef_run).to create_file_with_content('/etc/rsyslog.d/35-server-per-host.conf', '/srv/rsyslog/%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%/auth.log')
expect(chef_run).to create_file_with_content(template.path, '/srv/rsyslog/%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%/auth.log')
end
it 'is owned by root:root' do
......@@ -49,7 +51,34 @@ describe 'rsyslog::server' do
end
it 'notifies restarting the service' do
expect(template).to notify('service[rsyslog]', :restart)
expect(template).to notify(service_resource, :restart)
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z') do |node|
node.set['rsyslog']['server'] = false
end.converge('rsyslog::server')
end
let(:template) { chef_run.template('/opt/local/etc/rsyslog.d/35-server-per-host.conf') }
it 'creates the template' do
expect(chef_run).to create_file_with_content(template.path, '/srv/rsyslog/%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%/auth.log')
end
it 'is owned by root:root' do
expect(template.owner).to eq('root')
expect(template.group).to eq('root')
end
it 'has 0644 permissions' do
expect(template.mode).to eq('0644')
end
it 'notifies restarting the service' do
expect(template).to notify(service_resource, :restart)
end
end
end
......@@ -57,11 +86,29 @@ describe 'rsyslog::server' do
let(:file) { chef_run.file('/etc/rsyslog.d/remote.conf') }
it 'deletes the file' do
expect(chef_run).to delete_file('/etc/rsyslog.d/remote.conf')
expect(chef_run).to delete_file(file.path)
end
it 'notifies restarting the service' do
expect(file).to notify('service[rsyslog]', :reload)
expect(file).to notify(service_resource, :reload)
end
context 'on SmartOS' do
let(:chef_run) do
ChefSpec::ChefRunner.new(platform: 'smartos', version: 'joyent_20130111T180733Z') do |node|
node.set['rsyslog']['server'] = false
end.converge('rsyslog::server')
end
let(:file) { chef_run.file('/opt/local/etc/rsyslog.d/remote.conf') }
it 'deletes the file' do
expect(chef_run).to delete_file(file.path)
end
it 'notifies restarting the service' do
expect(file).to notify(service_resource, :reload)
end
end
end
end
# Default rules for rsyslog.
#
# For more information see rsyslog.conf(5) and /etc/rsyslog.conf
# For more information see rsyslog.conf(5) and <%= node['rsyslog']['config_prefix'] %>/rsyslog.conf
#
# First some standard log files. Log by facility.
......
......@@ -17,9 +17,11 @@ $PreserveFQDN <%= node['rsyslog']['preserve_fqdn'] %>
#### MODULES ####
#################
$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides --MARK-- message capability
<% if node['rsyslog']['modules'] && !node['rsyslog']['modules'].empty? %>
<% [*node['rsyslog']['modules']].each do |mod| %>
$ModLoad <%= mod %>
<% end %>
<% end %>
<% if node['rsyslog']['server'] -%>
# Provide <%= node['rsyslog']['protocol'].upcase %> log reception
......@@ -66,6 +68,6 @@ $PrivDropToUser <%= node['rsyslog']['user'] %>
$PrivDropToGroup <%= node['rsyslog']['group'] %>
<% end %>
#
# Include all config files in /etc/rsyslog.d/
# Include all config files in <%= node['rsyslog']['config_prefix'] %>/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
$IncludeConfig <%= node['rsyslog']['config_prefix'] %>/rsyslog.d/*.conf
# Dropped of by Chef. Modifications will be lost.
#
# Default rules for rsyslog.
#
# For more information see rsyslog.conf(5) and <%= node['rsyslog']['config_prefix'] %>/rsyslog.conf
*.err;kern.notice;auth.notice /dev/sysmsg
*.err;kern.debug;daemon.notice;mail.crit /var/adm/messages
*.alert;kern.err;daemon.err operator
*.alert root
*.emerg *
mail.debug /var/log/syslog
auth.info /var/log/auth.log
mail.info /var/log/postfix.log
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment