diff --git a/files/RedHat/etc/init.d/splunk b/files/RedHat/etc/init.d/splunk index b2d069d..1b5d9b6 100644 --- a/files/RedHat/etc/init.d/splunk +++ b/files/RedHat/etc/init.d/splunk @@ -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 diff --git a/manifests/init.pp b/manifests/init.pp index 999ecf4..d497347 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 diff --git a/manifests/install.pp b/manifests/install.pp index f08c00a..73f6903 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -8,7 +8,11 @@ $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_system = $::splunk::init_system, + $init_confdir = $::splunk::init_confdir, ) { package { $pkgname: @@ -17,12 +21,13 @@ source => $package_source, }-> - file { '/etc/init.d/splunk': - ensure => present, - mode => '0700', - owner => 'root', - group => 'root', - source => "puppet:///modules/splunk/${::osfamily}/etc/init.d/${pkgname}" + file { "${splunkhome}/etc/splunk-launch.conf": + ensure => present, + mode => '0444', + owner => $user, + group => $group, + backup => true, + content => template('splunk/opt/splunk/etc/splunk-launch.conf.erb'), } -> # inifile @@ -54,8 +59,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'), } -> @@ -70,4 +75,42 @@ purge => false, source => 'puppet:///modules/splunk/noarch/opt/splunk/etc/auth', } + + # On operatingsystems that use init scripts, include the configuration file + # Separate from the above dependency chain because it might not exist + if $init_system == 'sysv_compat' { + file { "${init_confdir}/${pkgname}": + ensure => present, + mode => '0700', + owner => 'root', + group => 'root', + content => template('splunk/init_conf.erb'), + require => Package[$pkgname], + } -> + + file { '/etc/init.d/splunk': + ensure => present, + mode => '0700', + owner => 'root', + group => 'root', + source => "puppet:///modules/splunk/${::osfamily}/etc/init.d/${pkgname}" + } + } + elsif $init_system == 'smf' { + file { '/var/svc/manifest/site/splunk.smf.xml': + content => template('splunk/Solaris/splunk.smf.xml.erb'), + owner => 'root', + group => 'root', + mode => '0444', + require => Package[$pkgname], + notify => Exec['splunk-smf-importer']; + } + + exec { 'splunk-smf-importer': + refreshonly => true, + command => '/usr/sbin/svcadm restart manifest-import'; + + } + } + } diff --git a/manifests/params.pp b/manifests/params.pp index 42c6934..7de397e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -14,6 +14,19 @@ $purge = undef $version = 'installed' $replace_passwd = 'no' + $user = 'root' + $group = 'root' + + if $::osfamily == 'RedHat' { + $init_system = 'sysv_compat' + $init_confdir = '/etc/sysconfig' + } elsif $::osfamily == 'Debian' { + $init_system = 'sysv_compat' + $init_confdir = '/etc/default' + } elsif $::osfamily == 'Solaris' { + $init_system = 'smf' + $init_confdir = undef + } if $::mode == maintenance { $service_ensure = 'stopped' diff --git a/manifests/ulimit.pp b/manifests/ulimit.pp index c6a234f..bf8abcd 100644 --- a/manifests/ulimit.pp +++ b/manifests/ulimit.pp @@ -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", } } diff --git a/templates/Solaris/splunk.smf.xml.erb b/templates/Solaris/splunk.smf.xml.erb new file mode 100644 index 0000000..6a3f76a --- /dev/null +++ b/templates/Solaris/splunk.smf.xml.erb @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/init_conf.erb b/templates/init_conf.erb new file mode 100644 index 0000000..b845932 --- /dev/null +++ b/templates/init_conf.erb @@ -0,0 +1,2 @@ +USER="<%= @user %>" + diff --git a/templates/opt/splunk/etc/splunk-launch.conf.erb b/templates/opt/splunk/etc/splunk-launch.conf.erb index e6cf997..9fdce81 100644 --- a/templates/opt/splunk/etc/splunk-launch.conf.erb +++ b/templates/opt/splunk/etc/splunk-launch.conf.erb @@ -1,19 +1,33 @@ #### THIS FILE MANAGED BY PUPPET #### -# Copyright (C) 2005-2010 Splunk Inc. All Rights Reserved. Version 4.1.5 -# + # Modify the following line to suit the location of your Splunk install. # If unset, Splunk will use the parent of the directory this configuration # file was found in # -SPLUNK_HOME=/opt/splunk +SPLUNK_HOME="<%= @splunkhome %>" -# # By default, Splunk stores its indexes under SPLUNK_HOME in the # var/lib/splunk subdirectory. This can be overridden # here: # -# SPLUNK_DB=/opt/splunk/var/lib/splunk -http_proxy = <%= proxyserver -%>:3128 +# SPLUNK_DB=/home/build/build-home/ember/var/lib/splunk + +# Splunkd daemon name +SPLUNK_SERVER_NAME=Splunkd + +# Splunkweb daemon name +SPLUNK_WEB_NAME=splunkweb + +# If SPLUNK_OS_USER is set, then Splunk service will only start +# if the 'splunk [re]start [splunkd]' command is invoked by a user who +# is, or can effectively become via setuid(2), $SPLUNK_OS_USER. +# (This setting can be specified as username or as UID.) +# +# SPLUNK_OS_USER +SPLUNK_OS_USER="<%= @user %>" +<% if @proxyserver -%> +http_proxy="<%= @proxyserver %>" +<% end -%> #### THIS FILE MANAGED BY PUPPET ####