When trying to kill a daemon, keep its pid in a variable instead of
retrieving it from the pidfile multiple times. It prevents the following
race condition:
* try to kill ceph-mon
* ceph-mon is in the process of dying and removed its pidfile
* try to kill ceph-mon fails because the pidfile is not found
* another ceph-mon is spawned and fails to bind the port
because the previous ceph-mon is still holding it
Signed-off-by: Loic Dachary <loic@dachary.org>
function kill_daemons() {
for pidfile in $(find $DIR | grep pidfile) ; do
+ pid=$(cat $pidfile)
for try in 0 1 1 1 2 3 ; do
- kill $(cat $pidfile) || break
+ kill $pid || break
sleep $try
done
done
function kill_daemons() {
for pidfile in $(find $DIR -name pidfile) ; do
+ pid=$(cat $pidfile)
for try in 0 1 1 1 2 3 ; do
- kill $(cat $pidfile) || break
+ kill $pid || break
sleep $try
done
done
function kill_daemons() {
local dir=$1
for pidfile in $(find $dir | grep pidfile) ; do
+ pid=$(cat $pidfile)
for try in 0 1 1 1 2 3 ; do
- kill -9 $(cat $pidfile 2> /dev/null) 2> /dev/null || break
+ kill -9 $pid 2> /dev/null || break
sleep $try
done
done