app-admin/logstash-forwarder: Allow to specify user/group for service
authorAmadeusz Żołnowski <aidecoe@gentoo.org>
Sat, 22 Aug 2015 15:27:24 +0000 (16:27 +0100)
committerAmadeusz Żołnowski <aidecoe@gentoo.org>
Sat, 22 Aug 2015 15:32:56 +0000 (16:32 +0100)
logstash-forwarder is running as logstash user in Gentoo by default.  It
might be desired to run it as other user who has access to log files,
presumably as root.  The other solution for accessing logs would be
adding logstash user to groups as which services are run and make logs
readable by that group.  It is also possible in some cases to change
group for log files, e.g. in syslog-ng.

Thanks to Tomas Mozes <hydrapolic@gmail.com> for submitting patch.

Gentoo-Bug: 557462

Package-Manager: portage-2.2.20.1

app-admin/logstash-forwarder/files/logstash-forwarder.confd
app-admin/logstash-forwarder/files/logstash-forwarder.initd

index e49ed1dc295eb1856dd4ded30c4d6322b33ee9d8..089b0c6ba2c22e2b6d21842624474f66a3fb3853 100644 (file)
@@ -1 +1,3 @@
 LOGSTASH_FORWARDER_ARGS="-quiet -syslog=true"
+#LOGSTASH_FORWARDER_USER=""
+#LOGSTASH_FORWARDER_GROUP=""
index 263ea8c7bd07ac82c7e1b9023128a17f8cfd1363..ecfc5ccecfb392f61b927d4e5bfa948d0606ad16 100644 (file)
@@ -3,11 +3,14 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
+LOGSTASH_FORWARDER_USER="${LOGSTASH_FORWARDER_USER:-logstash}"
+LOGSTASH_FORWARDER_GROUP="${LOGSTASH_FORWARDER_GROUP:-logstash}"
+
 start() {
        local config_file=/etc/logstash-forwarder/logstash-forwarder.conf
        local statedir=/var/lib/logstash-forwarder
 
-       if ! [[ -d ${statedir} ]]; then
+       if ! [ -d ${statedir} ]; then
                eend 1 "logstash state directory is missing: ${statedir}"
                return 1
        fi
@@ -16,7 +19,8 @@ start() {
        start-stop-daemon --start --exec /usr/bin/logstash-forwarder \
                --make-pidfile --pidfile /run/logstash-forwarder.pid \
                --background --wait 100 --chdir "${statedir}" \
-               --user logstash --group logstash \
+               --user ${LOGSTASH_FORWARDER_USER} \
+               --group ${LOGSTASH_FORWARDER_GROUP} \
                -- -config="${config_file}" ${LOGSTASH_FORWARDER_ARGS}
        eend $?
 }
@@ -24,7 +28,9 @@ start() {
 stop() {
        ebegin "Stopping logstash-forwarder"
        start-stop-daemon --stop --exec /usr/bin/logstash-forwarder \
-               --pidfile /run/logstash-forwarder.pid --user logstash --group logstash
+               --pidfile /run/logstash-forwarder.pid \
+               --user ${LOGSTASH_FORWARDER_USER} \
+               --group ${LOGSTASH_FORWARDER_GROUP}
        local rc=$?
 
        eend ${rc}