Skip to content

Commit baa734f

Browse files
committed
clean up pidfiles to sort out issue #8
1 parent 6391132 commit baa734f

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ RUN mkdir ${LOGSTASH_HOME} \
4141
&& rm -f ${LOGSTASH_PACKAGE} \
4242
&& groupadd -r logstash \
4343
&& useradd -r -s /usr/sbin/nologin -d ${LOGSTASH_HOME} -c "Logstash service user" -g logstash logstash \
44-
&& chown -R logstash:logstash ${LOGSTASH_HOME} \
45-
&& mkdir -p /var/log/logstash /etc/logstash/conf.d
44+
&& mkdir -p /var/log/logstash /etc/logstash/conf.d \
45+
&& chown -R logstash:logstash ${LOGSTASH_HOME} /var/log/logstash
4646

4747
ADD ./logstash-init /etc/init.d/logstash
4848
RUN sed -i -e 's#^LS_HOME=$#LS_HOME='$LOGSTASH_HOME'#' /etc/init.d/logstash \

logstash-init

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ stop() {
8888
echo "$name stop failed; still running."
8989
else
9090
echo "$name stopped."
91+
rm -f $pidfile
9192
fi
9293
fi
9394
}
@@ -114,6 +115,7 @@ force_stop() {
114115
if status; then
115116
stop
116117
status && kill -KILL $(cat "$pidfile")
118+
rm -f $pidfile
117119
fi
118120
}
119121

start.sh

+35-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,43 @@
33
# /usr/local/bin/start.sh
44
# Start Elasticsearch, Logstash and Kibana services
55
#
6+
# spujadas 2015-10-09; added initial pidfile removal and graceful termination
7+
8+
# WARNING - This script assumes that the ELK services are not running, and is
9+
# only expected to be run once, when the container is started.
10+
# Do not attempt to run this script if the ELK services are running (or be
11+
# prepared to reap zombie processes).
12+
13+
14+
## handle termination gracefully
15+
16+
_term() {
17+
echo "Terminating ELK"
18+
service elasticsearch stop
19+
service logstash stop
20+
service kibana stop
21+
exit 0
22+
}
23+
24+
trap _term SIGTERM
25+
26+
27+
## remove pidfiles in case previous graceful termination failed
28+
# NOTE - This is the reason for the WARNING at the top - it's a bit hackish,
29+
# but if it's good enough for Fedora (https://goo.gl/88eyXJ), it's good
30+
# enough for me :)
31+
32+
rm -f /var/run/elasticsearch/elasticsearch.pid /var/run/logstash.pid \
33+
/var/run/kibana4.pid
34+
35+
36+
## start services
637

738
service elasticsearch start
839
service logstash start
940

10-
# wait for elasticsearch to start up - https://github.com/elasticsearch/kibana/issues/3077
41+
# wait for elasticsearch to start up
42+
# - https://github.com/elasticsearch/kibana/issues/3077
1143
counter=0
1244
while [ ! "$(curl localhost:9200 2> /dev/null)" -a $counter -lt 30 ]; do
1345
sleep 1
@@ -17,4 +49,5 @@ done
1749

1850
service kibana start
1951

20-
tail -f /var/log/elasticsearch/elasticsearch.log
52+
tail -f /var/log/elasticsearch/elasticsearch.log &
53+
wait

0 commit comments

Comments
 (0)