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 f0ba5e5077)

Conflicts:
	deployment_scripts/puppet/modules/heka/spec/classes/heka_spec.rb

Change-Id: Idbfab2de92b993d1e5124de5bff44c4b09a88bb4
This commit is contained in:
Guillaume Thouvenin 2016-03-23 15:17:53 +01:00
parent a18563ffe6
commit f2999dc559
3 changed files with 38 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -6,4 +6,4 @@ HEKAD="/usr/bin/hekad"
<%= @pre_script %>
<% end -%>
$HEKAD -config=<%= @config_dir %>
exec $HEKAD -config=<%= @config_dir %>