| 1 |
#!/bin/sh |
| 2 |
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing. |
| 3 |
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then |
| 4 |
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script |
| 5 |
fi |
| 6 |
### BEGIN INIT INFO |
| 7 |
# Provides: mtail |
| 8 |
# Required-Start: $remote_fs |
| 9 |
# Required-Stop: $remote_fs |
| 10 |
# Default-Start: 2 3 4 5 |
| 11 |
# Default-Stop: 0 1 6 |
| 12 |
# Short-Description: Extract monitoring data from logs |
| 13 |
# Description: mtail is a tool for extracting metrics from application |
| 14 |
# logs to be exported into a timeseries database or |
| 15 |
# timeseries calculator for alerting and dashboarding. |
| 16 |
# It aims to fill a niche between applications that do not |
| 17 |
# export their own internal state, and existing monitoring |
| 18 |
# systems, without patching those applications or rewriting |
| 19 |
# the same framework for custom extraction glue code. |
| 20 |
# Metrics are exported for scraping by a collector as JSON |
| 21 |
# or Prometheus format over HTTP, or can be periodically |
| 22 |
# sent to a collectd, StatsD, or Graphite collector socket. |
| 23 |
### END INIT INFO |
| 24 |
|
| 25 |
# Author: Martina Ferrari <[email protected]> |
| 26 |
# Author: Guillem Jover <[email protected]> |
| 27 |
|
| 28 |
DESC="monitoring data extractor from application logs" |
| 29 |
NAME=mtail |
| 30 |
USER=mtail |
| 31 |
GROUP=$USER |
| 32 |
DAEMON=/usr/bin/$NAME |
| 33 |
PIDFILE=/run/$NAME/$NAME.pid |
| 34 |
LOGFILE=/var/log/$NAME/$NAME.log |
| 35 |
|
| 36 |
START_ARGS="--no-close --background --make-pidfile" |
| 37 |
STOP_ARGS="--remove-pidfile" |
| 38 |
|
| 39 |
ARGS="-progs /etc/mtail -logtostderr" |
| 40 |
[ -n "$HOST" ] && ARGS="${ARGS} -address $HOST" |
| 41 |
[ -n "$PORT" ] && ARGS="${ARGS} -port $PORT" |
| 42 |
|
| 43 |
# Deprecated options, left for backwards-compatibility. |
| 44 |
[ -n "$COLLECTD_SOCKETPATH" ] && \ |
| 45 |
ARGS="${ARGS} -collectd_socketpath $COLLECTD_SOCKETPATH" |
| 46 |
[ -n "$GRAPHITE_HOSTPORT" ] && \ |
| 47 |
ARGS="${ARGS} -graphite_host_port $GRAPHITE_HOSTPORT" |
| 48 |
[ -n "$STATSD_HOSTPORT" ] && ARGS="${ARGS} -statsd_hostport $STATSD_HOSTPORT" |
| 49 |
[ -n "$METRIC_PUSH_INTERVAL" ] && \ |
| 50 |
ARGS="${ARGS} -metric_push_interval_seconds $METRIC_PUSH_INTERVAL" |
| 51 |
|
| 52 |
do_start_prepare() |
| 53 |
{ |
| 54 |
mkdir -p $(dirname $PIDFILE) |
| 55 |
if [ -z "${LOGS}" ]; then |
| 56 |
log_failure_msg |
| 57 |
echo "Missing mandatory parameter LOGS in /etc/default/mtail" >&2 |
| 58 |
exit 1 |
| 59 |
fi |
| 60 |
} |
| 61 |
|
| 62 |
do_start_cmd_override() |
| 63 |
{ |
| 64 |
start-stop-daemon --start --quiet --oknodo \ |
| 65 |
--exec $DAEMON --pidfile $PIDFILE --user $USER --group $GROUP \ |
| 66 |
--chuid $USER:$GROUP $START_ARGS -- $ARGS -logs "$LOGS" $EXTRA_ARGS \ |
| 67 |
>>$LOGFILE 2>&1 |
| 68 |
} |
| 69 |
|
| 70 |
do_stop_cmd_override() |
| 71 |
{ |
| 72 |
start-stop-daemon --stop --quiet --oknodo --retry=TERM/30/KILL/5 \ |
| 73 |
--exec $DAEMON --pidfile $PIDFILE --user $USER $STOP_ARGS |
| 74 |
} |
| 75 |
|
| 76 |
alias do_reload=do_reload_sigusr1 |