aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/logstash/files/logstash.in
blob: fedec80b52f02ae3732477a0e15e2ecb60fe58e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh

# $FreeBSD$
#
# PROVIDE: logstash
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
#
# Configuration settings for logstash in /etc/rc.conf:
#
# logstash_enable (bool):
#   Set to "NO" by default.
#   Set it to "YES" to enable logstash
#
# logstash_mode :
#   Set to "standalone" by default.
#   Valid options:
#     "standalone": agent, web & elasticsearch
#     "web": Starts logstash as a web ui
#     "agent": Justs works as a log shipper 
#
# logstash_logging (bool):
#   Set to "NO" by default.
#   Set it to "YES" to enable logstash logging to file
#   Default output to /var/log/logstash.log
#

. /etc/rc.subr

name=logstash
rcvar=logstash_enable

load_rc_config ${name}

: ${logstash_enable="NO"}
: ${logstash_home="%%LOGSTASH_HOME%%"}
: ${logstash_config="%%PREFIX%%/etc/${name}/${name}.conf"}
: ${logstash_jar="%%LOGSTASH_HOME%%/%%LOGSTASH_JAR%%"}
: ${logstash_java_home="%%JAVA_HOME%%"}
: ${logstash_log="NO"}
: ${logstash_mode="standalone"}
: ${logstash_port="9292"}
: ${logstash_elastic_backend=""}
: ${logstash_log_file="${logdir}/${name}.log"}
: ${logstash_elastic_datadir="%%LOGSTASH_DATA_DIR%%"}

piddir=/var/run/${name}
pidfile=${piddir}/${name}.pid

if [ -d $piddir ]; then
    mkdir -p $piddir
fi

logdir="/var/log"
command="/usr/sbin/daemon"

java_cmd="${logstash_java_home}/bin/java"
procname="${java_cmd}"

logstash_chdir=${logstash_home}
logstash_log_options=""
logstash_elastic_options=""

if checkyesno logstash_log; then
    logstash_log_options=" --log ${logstash_log_file}" 
fi

if [ ${logstash_mode} = "standalone" ]; then
    logstash_args="agent -f ${logstash_config} -- web --port ${logstash_port} --backend elasticsearch:///?local ${logstash_log_options}"
    logstash_elastic_options="-Des.path.data=${logstash_elastic_datadir}"
elif [ ${logstash_mode} = "agent" ]; then
    logstash_args="agent -f ${logstash_config} ${logstash_log_options}"
elif [ ${logstash_mode} = "web" ]; then
    logstash_args="web --port ${logstash_port} --backend elasticsearch://${logstash_elastic_backend}/ ${logstash_log_options}"
fi

command_args="-f -p ${pidfile} ${java_cmd} ${logstash_elastic_options} -jar ${logstash_jar} ${logstash_args}"
required_files="${java_cmd} ${logstash_config}"

run_rc_command "$1"