CLICKHOUSE-3887 Debian init: Service stop timeout (#5522)

This commit is contained in:
proller 2019-06-04 16:03:22 +03:00 committed by GitHub
parent 64924f5ef3
commit a063517091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -26,14 +26,13 @@ CLICKHOUSE_CRONFILE=/etc/cron.d/clickhouse-server
CLICKHOUSE_CONFIG=$CLICKHOUSE_CONFDIR/config.xml
LOCKFILE=$LOCALSTATEDIR/$PROGRAM
RETVAL=0
CLICKHOUSE_PIDDIR=/var/run/$PROGRAM
CLICKHOUSE_PIDFILE="$CLICKHOUSE_PIDDIR/$PROGRAM.pid"
# CLICKHOUSE_STOP_TIMEOUT=60 # Disabled by default. Place to /etc/default/clickhouse if you need.
# Some systems lack "flock"
command -v flock >/dev/null && FLOCK=flock
# Override defaults from optional config file
test -f /etc/default/clickhouse && . /etc/default/clickhouse
@ -76,7 +75,13 @@ is_running()
wait_for_done()
{
timeout=$1
attempts=0
while is_running; do
attempts=$(($attempts + 1))
if [ -n "$timeout" ] && [ $attempts -gt $timeout ]; then
return 1
fi
sleep 1
done
}
@ -175,7 +180,7 @@ start()
if [ $EXIT_STATUS -eq 0 ]; then
attempts=0
while ! is_running && [ $attempts -le 10 ]; do
while ! is_running && [ $attempts -le ${CLICKHOUSE_START_TIMEOUT:=10} ]; do
attempts=$(($attempts + 1))
sleep 1
done
@ -194,7 +199,7 @@ start()
stop()
{
local EXIT_STATUS
#local EXIT_STATUS
EXIT_STATUS=0
if [ -f $CLICKHOUSE_PIDFILE ]; then
@ -203,9 +208,13 @@ stop()
kill -TERM $(cat "$CLICKHOUSE_PIDFILE")
wait_for_done
if ! wait_for_done ${CLICKHOUSE_STOP_TIMEOUT}; then
EXIT_STATUS=2
echo "TIMEOUT"
else
echo "DONE"
fi
echo "DONE"
fi
return $EXIT_STATUS
}
@ -214,8 +223,12 @@ stop()
restart()
{
check_config
stop
start
if stop; then
if start; then
return 0
fi
fi
return 1
}
@ -295,13 +308,14 @@ main()
start && enable_cron
;;
stop)
disable_cron && stop
# disable_cron returns false if cron disabled (with systemd) - not checking return status
disable_cron
stop
;;
restart)
restart && enable_cron
;;
forcestop)
# disable_cron returns false if cron disabled (with systemd) - not checking return status
disable_cron
forcestop
;;

View File

@ -12,6 +12,10 @@ if [ -n "$CCACHE_DIR" ]; then
chmod -R a+rwx $CCACHE_DIR $DISTCC_DIR ||:
fi
[ $CCACHE_PREFIX = 'distcc' ] && mkdir -p ~/.distcc && echo "localhost/`nproc`" >> ~/.distcc/hosts
# [ $CCACHE_PREFIX = 'distcc' ] && mkdir -p /etc/distcc/ && echo "localhost/`nproc`" >> /etc/distcc/hosts
# distcc --show-hosts
df -h
ccache --show-stats
ccache --zero-stats