Description
Hey guys,
I've just started filebeat deployment on my local Vagrant machine and it turned out approach to start in init script file is a little bit controversial in my opinion.
Deployment details:
[root@vagrant-filebeat ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@vagrant-filebeat ~]# rpm -qa | grep filebeat
filebeat-1.1.2-1.x86_64
[root@vagrant-filebeat ~]# cat /etc/filebeat/filebeat.yml
filebeat:
prospectors: []
registry_file: "/var/lib/filebeat/registry"
config_dir: "/etc/filebeat/conf.d"
output:
redis:
host: localhost
port: 6379
logging:
level: info
to_syslog: true
The case is that you guys do a config test before start, which is perfectly fine and absolutely expected, but the options that have been used to execute that may cause some issues.
Here's the relevant code from /etc/init.d/filebeat
:
[ -f /etc/sysconfig/filebeat ] && . /etc/sysconfig/filebeat
pidfile=${PIDFILE-/var/run/filebeat.pid}
agent=${PB_AGENT-/usr/bin/filebeat}
args="-c /etc/filebeat/filebeat.yml"
test_args="-e -configtest"
wrapper="filebeat-god"
wrapperopts="-r / -n -p $pidfile"
RETVAL=0
test() {
$agent $args $test_args
}
start() {
echo -n $"Starting filebeat: "
test
if [ $? -ne 0 ]; then
echo
exit 1
fi
daemon $daemonopts $wrapper $wrapperopts -- $agent $args
RETVAL=$?
echo
return $RETVAL
}
In my case before start /usr/bin/filebeat -c /etc/filebeat/filebeat.yml -e -configtest
is executed. The problem is that:
-e
means file/syslog logging settings from YML file are completely ignored and all output goes tostderr
, so script won't start in background and will just hang forever (ignore redis warnings for a while, explained in next point)
[root@vagrant-filebeat ~]# /etc/init.d/filebeat start
Starting filebeat: 2016/03/23 13:10:02.597246 geolite.go:24: INFO GeoIP disabled: No paths were set under output.geoip.paths
2016/03/23 13:10:02.597273 redis.go:72: WARN Redis Output is deprecated. Please use the Redis Output Plugin from Logstash instead.
2016/03/23 13:10:02.597294 redis.go:100: INFO Reconnect Interval set to: 1s
2016/03/23 13:10:02.597301 redis.go:117: INFO [RedisOutput] Using Redis server localhost:6379
2016/03/23 13:10:02.597308 redis.go:121: INFO [RedisOutput] Redis connection timeout 5s
2016/03/23 13:10:02.597315 redis.go:122: INFO [RedisOutput] Redis reconnect interval 1s
2016/03/23 13:10:02.597320 redis.go:123: INFO [RedisOutput] Using index pattern filebeat
2016/03/23 13:10:02.597324 redis.go:124: INFO [RedisOutput] Topology expires after 15s
2016/03/23 13:10:02.597328 redis.go:125: INFO [RedisOutput] Using db 0 for storing events
2016/03/23 13:10:02.597331 redis.go:126: INFO [RedisOutput] Using db 1 for storing topology
2016/03/23 13:10:02.597336 redis.go:127: INFO [RedisOutput] Using 0 data type
2016/03/23 13:10:02.597953 redis.go:183: WARN Error connecting to Redis (dial tcp [::1]:6379: getsockopt: connection refused). Retrying in 1s
2016/03/23 13:10:03.598405 redis.go:183: WARN Error connecting to Redis (dial tcp [::1]:6379: getsockopt: connection refused). Retrying in 1s
2016/03/23 13:10:04.599630 redis.go:183: WARN Error connecting to Redis (dial tcp [::1]:6379: getsockopt: connection refused). Retrying in 1s
- even if I removed
-e
fromtest_args
variable it doesn't really change much (it still hangs, but is just less verbose):
[root@vagrant-filebeat ~]# /etc/init.d/filebeat start
Starting filebeat:
My expectation was that -configtest
flag is quite fast and returns 0 when everything is fine when it comes to config file and non-zero exit code otherwise. By fine I mean not terribly broken (i.e. lack of output, wrong values, etc). I definitely didn't expect that output I defined (Redis in my case) needs to be up and running upfront. It's not ideal approach in my opinion. I'd expect a warning message in log file, but it shouldn't stop filebeat
daemon from starting, as there's no reason to do so. I create dozens of machines at the same time (terraform + Chef) and have no idea when Redis or Logstash will become available. All I know is that eventually these services will be online.
Cheers,
Jakub