summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app-admin/logstash-forwarder/files/logstash-forwarder.initd')
-rw-r--r--app-admin/logstash-forwarder/files/logstash-forwarder.initd63
1 files changed, 63 insertions, 0 deletions
diff --git a/app-admin/logstash-forwarder/files/logstash-forwarder.initd b/app-admin/logstash-forwarder/files/logstash-forwarder.initd
new file mode 100644
index 000000000000..38e09b65ab68
--- /dev/null
+++ b/app-admin/logstash-forwarder/files/logstash-forwarder.initd
@@ -0,0 +1,63 @@
+#!/sbin/runscript
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+create_tmpdir() {
+ local tmpdir="$(mktemp -d -p /tmp logstash-forwarder.XXXXXXXXXX)"
+
+ chown logstash:logstash "${tmpdir}" || return 1
+ chmod 0750 "${tmpdir}" || return 1
+
+ echo "${tmpdir}"
+}
+
+remove_tmpdir() {
+ local d=''
+ local tmpdir=''
+
+ for d in /tmp/logstash-forwarder.??????????; do
+ [[ -e ${d} ]] || return 0
+ [[ -d ${d} ]] || continue
+
+ if ! [[ ${tmpdir} ]]; then
+ tmpdir="${d}"
+ else
+ # There are more directories like that, so better keep them all.
+ return 1
+ fi
+ done
+
+ rm -r "${tmpdir}"
+}
+
+start() {
+ local config_file=/etc/logstash-forwarder/logstash-forwarder.conf
+ local tmpdir="$(create_tmpdir)"
+
+ if ! [[ -d ${tmpdir} ]]; then
+ eend 1 "Failed to create tmp directory for logstash-forwarder"
+ return 1
+ fi
+
+ ebegin "Starting logstash-forwarder"
+ start-stop-daemon --start --exec /usr/bin/logstash-forwarder \
+ --make-pidfile --pidfile /run/logstash-forwarder.pid \
+ --background --wait 100 --chdir "${tmpdir}" \
+ --user logstash --group logstash \
+ -- -config="${config_file}" ${LOGSTASH_FORWARDER_ARGS}
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping logstash-forwarder"
+ start-stop-daemon --stop --exec /usr/bin/logstash-forwarder \
+ --pidfile /run/logstash-forwarder.pid --user logstash --group logstash
+ local rc=$?
+
+ if ! remove_tmpdir; then
+ ewarn "Failed to remove logstash-forwarder tmp directory"
+ fi
+
+ eend ${rc}
+}