From f2999dc55970ddccaa07ffc4e3c318ff5f172fef Mon Sep 17 00:00:00 2001 From: Guillaume Thouvenin Date: Wed, 23 Mar 2016 15:17:53 +0100 Subject: [PATCH] Avoid forks when starting hekad We must avoid to fork process when starting the Heka daemon because if we kill the wrapper, the Heka daemon is detached and re-attach to the init process. This can create several Heka daemon. To avoid this we need to use exec and avoid the usage of sudo. Fixes-bug: #1561109 (cherry picked from commit f0ba5e5077cdb63e7a4d2ccdd395465ee29fe34a) Conflicts: deployment_scripts/puppet/modules/heka/spec/classes/heka_spec.rb Change-Id: Idbfab2de92b993d1e5124de5bff44c4b09a88bb4 --- .../modules/heka/spec/classes/heka_spec.rb | 36 +++++++++++++++++++ .../heka/templates/hekad.upstart.conf.erb | 2 +- .../modules/heka/templates/hekad_wrapper.erb | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 deployment_scripts/puppet/modules/heka/spec/classes/heka_spec.rb diff --git a/deployment_scripts/puppet/modules/heka/spec/classes/heka_spec.rb b/deployment_scripts/puppet/modules/heka/spec/classes/heka_spec.rb new file mode 100644 index 000000000..a1984e894 --- /dev/null +++ b/deployment_scripts/puppet/modules/heka/spec/classes/heka_spec.rb @@ -0,0 +1,36 @@ +# Copyright 2015 Mirantis, Inc. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +require 'spec_helper' + +describe 'heka' do + let(:facts) do + {:kernel => 'Linux', :operatingsystem => 'Ubuntu', + :osfamily => 'Debian'} + end + + describe 'with defaults' do + it { is_expected.to contain_user('heka') } + it { is_expected.to contain_file('/etc/init/hekad.conf') \ + .with_content(/--user heka/) } + end + + describe 'with user => "root"' do + let(:params) do + {:run_as_root => true} + end + it { is_expected.to contain_file('/etc/init/hekad.conf') } + it { is_expected.not_to contain_file('/etc/init/hekad.conf') \ + .with_content(/--user/) } + end +end diff --git a/deployment_scripts/puppet/modules/heka/templates/hekad.upstart.conf.erb b/deployment_scripts/puppet/modules/heka/templates/hekad.upstart.conf.erb index 601e455c8..6b6930722 100644 --- a/deployment_scripts/puppet/modules/heka/templates/hekad.upstart.conf.erb +++ b/deployment_scripts/puppet/modules/heka/templates/hekad.upstart.conf.erb @@ -17,5 +17,5 @@ end script script # https://bugs.launchpad.net/lma-toolchain/+bug/1543289 ulimit -n 102400 - exec <%= @run_as_root ? "" : "sudo -u #{ @heka_user }" %> <%= @hekad_wrapper %> 2>><%= @log_file %> + exec start-stop-daemon --start <%= @run_as_root ? "" : " --user #{ @heka_user }" %> --exec <%= @hekad_wrapper %> 2>><%= @log_file %> end script diff --git a/deployment_scripts/puppet/modules/heka/templates/hekad_wrapper.erb b/deployment_scripts/puppet/modules/heka/templates/hekad_wrapper.erb index e233e751a..9a93d092c 100644 --- a/deployment_scripts/puppet/modules/heka/templates/hekad_wrapper.erb +++ b/deployment_scripts/puppet/modules/heka/templates/hekad_wrapper.erb @@ -6,4 +6,4 @@ HEKAD="/usr/bin/hekad" <%= @pre_script %> <% end -%> -$HEKAD -config=<%= @config_dir %> +exec $HEKAD -config=<%= @config_dir %>