From 518f982af33225110d21813591603d00aa4bcd1f Mon Sep 17 00:00:00 2001 From: Ryan Hass Date: Thu, 16 Nov 2017 17:17:08 -0800 Subject: [PATCH 1/2] Properly support FreeBSD We now disable all sendmail services and periodic services on FreeBSD before attempting to start postfix. Additionally, this updates mailer.conf mappings to use postfix applications rather than sendmail. --- recipes/_common.rb | 41 +++++++++++++++++++++++++++++++++++++++++ templates/mailer.erb | 10 ++++++++++ 2 files changed, 51 insertions(+) create mode 100644 templates/mailer.erb diff --git a/recipes/_common.rb b/recipes/_common.rb index e738d39..8b7561b 100644 --- a/recipes/_common.rb +++ b/recipes/_common.rb @@ -69,6 +69,47 @@ when 'omnios' command "svccfg import #{manifest_path}" notifies :restart, 'service[postfix]' end +when 'freebsd' + # Actions are based on docs provided by FreeBSD: + # https://www.freebsd.org/doc/handbook/mail-changingmta.html + service 'sendmail' do + action :nothing + end + + template '/etc/mail/mailer.conf' do + source 'mailer.erb' + owner 'root' + group 0 + notifies :restart, 'service[postfix]' + end + + execute 'switch_mailer_to_postfix' do + command [ + 'sysrc', + 'sendmail_enable=NO', + 'sendmail_submit_enable=NO', + 'sendmail_outbound_enable=NO', + 'sendmail_msp_queue_enable=NO', + 'postfix_enable=YES', + ] + notifies :stop, 'service[sendmail]', :immediately + notifies :disable, 'service[sendmail]', :immediately + notifies :start, 'service[postfix]', :delayed + only_if "sysrc sendmail_enable sendmail_submit_enable sendmail_outbound_enable sendmail_msp_queue_enable | egrep -q '(YES|unknown variable)' || sysrc postfix_enable | egrep -q '(NO|unknown variable)'" + end + + execute 'disable_periodic' do + # rubocop:disable Lint/ParenthesesAsGroupedExpression + environment ({ 'RC_CONFS' => '/etc/periodic.conf' }) + command [ + 'sysrc', + 'daily_clean_hoststat_enable=NO', + 'daily_status_mail_rejects_enable=NO', + 'daily_status_include_submit_mailq=NO', + 'daily_submit_queuerun=NO', + ] + only_if "RC_CONFS=/etc/periodic.conf sysrc daily_clean_hoststat_enable daily_status_mail_rejects_enable daily_status_include_submit_mailq daily_submit_queuerun | egrep -q '(YES|unknown variable)'" + end end execute 'update-postfix-sender_canonical' do diff --git a/templates/mailer.erb b/templates/mailer.erb new file mode 100644 index 0000000..1865157 --- /dev/null +++ b/templates/mailer.erb @@ -0,0 +1,10 @@ +# +# Auto-generated by Chef. +# Local modifications will be overwritten. +# +# Execute the Postfix sendmail program, named /usr/local/sbin/sendmail +# +sendmail /usr/local/sbin/sendmail +send-mail /usr/local/sbin/sendmail +mailq /usr/local/sbin/sendmail +newaliases /usr/local/sbin/sendmail From 797e19dae957f50c7e750149d70b40ab2758a866 Mon Sep 17 00:00:00 2001 From: Jaymala Sinha Date: Wed, 22 Nov 2017 10:20:39 -0500 Subject: [PATCH 2/2] Do not run service restart for solaris Signed-off-by: Jaymala Sinha --- recipes/_common.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/recipes/_common.rb b/recipes/_common.rb index 8b7561b..37acc31 100644 --- a/recipes/_common.rb +++ b/recipes/_common.rb @@ -67,7 +67,7 @@ when 'omnios' execute 'load postfix manifest' do action :nothing command "svccfg import #{manifest_path}" - notifies :restart, 'service[postfix]' + notifies :restart, 'service[postfix]' unless platform_family?('solaris2') end when 'freebsd' # Actions are based on docs provided by FreeBSD: @@ -80,7 +80,7 @@ when 'freebsd' source 'mailer.erb' owner 'root' group 0 - notifies :restart, 'service[postfix]' + notifies :restart, 'service[postfix]' unless platform_family?('solaris2') end execute 'switch_mailer_to_postfix' do @@ -175,7 +175,10 @@ end owner 'root' group node['root_group'] mode '0644' - notifies :restart, 'service[postfix]' + # restart service for solaris on chef-client has a bug + # unless condition can be removed after + # https://github.com/chef/chef/pull/6596 merge/release + notifies :restart, 'service[postfix]' unless platform_family?('solaris2') variables( lazy { { settings: node['postfix'][cfg] } } ) @@ -185,5 +188,5 @@ end service 'postfix' do supports status: true, restart: true, reload: true - action :enable + action [:enable, :start] end