Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow splunk to run as a non-root user on RedHat #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions files/RedHat/etc/init.d/splunk
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,47 @@ RETVAL=0

. /etc/init.d/functions

test -f /etc/sysconfig/splunk && . /etc/sysconfig/splunk

CMD=${CMD-/opt/splunk/bin/splunk}
USER="${USER-root}"

CURRENT_USER=`id -nu`

run_splunk() {
if [[ $CURRENT_USER == $USER ]]; then
$CMD "$@"
else
if [[ "${CURRENT_USER}" != "root" ]]; then
echo "Script must be run from $USER or root. You are '${CURRENT_USER}'"
exit 1
fi

su ${USER} --command="$CMD $*"
fi
}

splunk_start() {
echo Starting Splunk...
"/opt/splunk/bin/splunk" start --accept-license --no-prompt --answer-yes
run_splunk start --accept-license --no-prompt --answer-yes
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/splunk
}
splunk_stop() {
echo Stopping Splunk...
"/opt/splunk/bin/splunk" stop
run_splunk stop
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/splunk
}
splunk_restart() {
echo Restarting Splunk...
"/opt/splunk/bin/splunk" restart --accept-license --no-prompt --answer-yes
run_splunk restart --accept-license --no-prompt --answer-yes
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/splunk
}
splunk_status() {
echo Splunk status:
"/opt/splunk/bin/splunk" status
run_splunk status
RETVAL=$?
}
case "$1" in
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
$package_provider = undef,
$version = $::splunk::params::version,
$replace_passwd = $::splunk::params::replace_passwd,
$user = $::splunk::params::user,
$group = $::splunk::params::group,
) inherits splunk::params {

# Added the preseed hack after getting the idea from very cool
Expand Down
17 changes: 14 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
$version = $::splunk::version,
$package_source = $::splunk::package_source,
$package_provider = $::splunk::package_provider,
$replace_passwd = $::splunk::replace_passwd
$replace_passwd = $::splunk::replace_passwd,
$user = $::splunk::user,
$group = $::splunk::group,
$init_confdir = $::splunk::init_confdir,
) {

package { $pkgname:
Expand All @@ -17,6 +20,14 @@
source => $package_source,
}->

file { "${init_confdir}/${pkgname}":
ensure => present,
mode => '0700',
owner => 'root',
group => 'root',
content => template('splunk/init_conf.erb'),
} ->

file { '/etc/init.d/splunk':
ensure => present,
mode => '0700',
Expand Down Expand Up @@ -54,8 +65,8 @@
ensure => present,
replace => $replace_passwd,
mode => '0600',
owner => 'root',
group => 'root',
owner => $user,
group => $group,
backup => true,
content => template('splunk/opt/splunk/etc/passwd.erb'),
} ->
Expand Down
8 changes: 8 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
$purge = undef
$version = 'installed'
$replace_passwd = 'no'
$user = 'root'
$group = 'root'

if $::osfamily == 'RedHat' {
$init_confdir = '/etc/sysconfig'
} else {
$init_confdir = '/etc/default'
}

if $::mode == maintenance {
$service_ensure = 'stopped'
Expand Down
12 changes: 6 additions & 6 deletions manifests/ulimit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
# value => '16384',
# }
#
define splunk::ulimit ( $value = '40960' ) {
define splunk::ulimit ( $user = 'root', $value = '40960' ) {
augeas { "set splunk ${name} ulimit":
context => '/files/etc/security/limits.conf/',
changes => [
"set \"domain[last()]\" root",
"set \"domain[.='root']/type\" -",
"set \"domain[.='root']/item\" ${name}",
"set \"domain[.='root']/value\" ${value}",
"set \"domain[last()]\" ${user}",
"set \"domain[.='${user}']/type\" -",
"set \"domain[.='${user}']/item\" ${name}",
"set \"domain[.='${user}']/value\" ${value}",
],
onlyif => "match domain[.='root'][type='-'][item='${name}'][value='${value}'] size == 0",
onlyif => "match domain[.='${user}'][type='-'][item='${name}'][value='${value}'] size == 0",
}
}
2 changes: 2 additions & 0 deletions templates/init_conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USER="<%= @user %>"