When running Logstash as a service, there is no option to run the --configtest flag. Here's how to add it to the logstash service.
When making changes to the logstash config, if you were to start the Logstash service using service logstash start, the service will start up (it takes a while to do so) and then crash silently if there are errors in the configuration files. It is possible to check the config files beforehand and get a verbose output by using the --configtest flag when starting logstash.
Service Method
Find the logstash service file at /etc/init.d/logstash and add the function configtest after the force_stop function and change the case switch:
...
force_stop() {
if status ; then
stop
status && kill -KILL `cat "$pidfile"`
fi
}
configtest() {
args="$args --configtest"
nice -n ${LS_NICE} chroot --userspec $LS_USER:$LS_GROUP / sh -c "
cd $LS_HOME
exec \"$program\" $args
"
}
case "$1" in
start)
status
code=$?
if [ $code -eq 0 ]; then
echo "$name is already running"
else
start
code=$?
fi
exit $code
;;
stop) stop ;;
force-stop) force_stop ;;
status)
status
code=$?
if [ $code -eq 0 ] ; then
echo "$name is running"
else
echo "$name is not running"
fi
exit $code
;;
restart)
stop && start
;;
configtest)
configtest
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|force-stop|status|restart|configtest}" >&2
exit 3
;;
esac
exit $?
This will allow you to run a configuration test without starting the logstash program. Use service logstash configtest to run a config test. It takes a while, so be patient. You might need to prefix it with sudo.
Alternative Method — Direct Run
For completeness, it is possible to run the logstash binary directly to run a config test. The method above simplifies the process.
Use this command to run it directly (you may need to prefix it with sudo):
/opt/logstash/bin/logstash agent -f /etc/logstash/conf.d --configtest
No comments:
Post a Comment