default.rb 2.98 KB
Newer Older
jtimberman's avatar
jtimberman committed
1
#
2
# Cookbook:: rsyslog
jtimberman's avatar
jtimberman committed
3 4
# Recipe:: default
#
5
# Copyright:: 2009-2016, Chef Software, Inc.
jtimberman's avatar
jtimberman committed
6 7 8 9
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
10
#
jtimberman's avatar
jtimberman committed
11
#     http://www.apache.org/licenses/LICENSE-2.0
12
#
jtimberman's avatar
jtimberman committed
13 14 15 16 17 18 19
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Aivaras Laimikis's avatar
Aivaras Laimikis committed
20 21
package node['rsyslog']['package_name']
package "#{node['rsyslog']['package_name']}-relp" if node['rsyslog']['use_relp']
22

23
if node['rsyslog']['enable_tls'] && node['rsyslog']['tls_ca_file']
Tim Smith's avatar
Tim Smith committed
24
  raise "Recipe rsyslog::default can not use 'enable_tls' with protocol '#{node['rsyslog']['protocol']}' (requires 'tcp')" unless node['rsyslog']['protocol'] == 'tcp'
Aivaras Laimikis's avatar
Aivaras Laimikis committed
25
  package "#{node['rsyslog']['package_name']}-gnutls"
26 27
end

Dan Buch's avatar
Dan Buch committed
28
directory "#{node['rsyslog']['config_prefix']}/rsyslog.d" do
29 30 31
  owner 'root'
  group 'root'
  mode  '0755'
jtimberman's avatar
jtimberman committed
32 33
end

Mihai Petracovici's avatar
Mihai Petracovici committed
34
directory node['rsyslog']['working_dir'] do
35 36
  owner node['rsyslog']['user']
  group node['rsyslog']['group']
37
  mode  '0700'
38 39
end

Jennifer Davis's avatar
Jennifer Davis committed
40 41 42 43 44
execute 'validate_config' do
  command "rsyslogd -N 1 -f #{node['rsyslog']['config_prefix']}/rsyslog.conf"
  action  :nothing
end

45 46
# Our main stub which then does its own rsyslog-specific
# include of things in /etc/rsyslog.d/*
Dan Buch's avatar
Dan Buch committed
47
template "#{node['rsyslog']['config_prefix']}/rsyslog.conf" do
48 49 50 51
  source  'rsyslog.conf.erb'
  owner   'root'
  group   'root'
  mode    '0644'
Jennifer Davis's avatar
Jennifer Davis committed
52
  notifies :run, 'execute[validate_config]'
53
  notifies :restart, "service[#{node['rsyslog']['service_name']}]"
jtimberman's avatar
jtimberman committed
54
end
55

Dan Buch's avatar
Dan Buch committed
56
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/50-default.conf" do
57 58 59 60
  source  '50-default.conf.erb'
  owner   'root'
  group   'root'
  mode    '0644'
Jennifer Davis's avatar
Jennifer Davis committed
61
  notifies :run, 'execute[validate_config]'
62
  notifies :restart, "service[#{node['rsyslog']['service_name']}]"
63
end
64

65 66
# syslog needs to be stopped before rsyslog can be started on RHEL versions before 6.0
if platform_family?('rhel') && node['platform_version'].to_i < 6
67
  service 'syslog' do
68 69
    action [:stop, :disable]
  end
70 71
elsif platform_family?('smartos', 'omnios')
  # syslog needs to be stopped before rsyslog can be started on SmartOS, OmniOS
Dan Buch's avatar
Dan Buch committed
72 73 74
  service 'system-log' do
    action :disable
  end
75 76
end

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
if platform_family?('omnios')
  # manage the SMF manifest on OmniOS
  template '/var/svc/manifest/system/rsyslogd.xml' do
    source 'omnios-manifest.xml.erb'
    owner 'root'
    group 'root'
    mode '0644'
    notifies :run, 'execute[import rsyslog manifest]', :immediately
  end

  execute 'import rsyslog manifest' do
    action :nothing
    command 'svccfg import /var/svc/manifest/system/rsyslogd.xml'
    notifies :restart, "service[#{node['rsyslog']['service_name']}]"
  end
end

94 95 96 97
service node['rsyslog']['service_name'] do
  supports restart: true, status: true
  action [:enable, :start]
end