[opt] stop script opt (#11183)

This commit is contained in:
Dongyang Li
2022-07-27 11:32:26 +08:00
committed by GitHub
parent d663497230
commit e210db426c
3 changed files with 97 additions and 40 deletions

View File

@ -281,7 +281,8 @@ int main(int argc, char** argv) {
// open pid file, obtain file lock and save pid
string pid_file = string(getenv("PID_DIR")) + "/be.pid";
int fd = open(pid_file.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
int fd = open(pid_file.c_str(), O_RDWR | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (fd < 0) {
fprintf(stderr, "fail to create pid file.");
exit(-1);

View File

@ -16,11 +16,20 @@
# specific language governing permissions and limitations
# under the License.
curdir=`dirname "$0"`
curdir=`cd "$curdir"; pwd`
curdir=$(dirname "$0")
curdir=$(
cd "$curdir"
pwd
)
export DORIS_HOME=`cd "$curdir/.."; pwd`
export PID_DIR=`cd "$curdir"; pwd`
export DORIS_HOME=$(
cd "$curdir/.."
pwd
)
export PID_DIR=$(
cd "$curdir"
pwd
)
signum=9
if [ "x"$1 = "x--grace" ]; then
@ -28,37 +37,47 @@ if [ "x"$1 = "x--grace" ]; then
fi
while read line; do
envline=`echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*="`
envline=`eval "echo $envline"`
envline=$(echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*=")
envline=$(eval "echo $envline")
if [[ $envline == *"="* ]]; then
eval 'export "$envline"'
fi
done < $DORIS_HOME/conf/be.conf
done <$DORIS_HOME/conf/be.conf
pidfile=$PID_DIR/be.pid
if [ -f $pidfile ]; then
pid=`cat $pidfile`
pidcomm=`ps -p $pid -o comm=`
pid=$(cat $pidfile)
#check if pid valid
if test -z "$pid"; then
echo "ERROR: invalid pid."
exit 1
fi
#check if pid process exist
if ! kill -0 $pid; then
echo "ERROR: be process $pid does not exist."
exit 1
fi
pidcomm=$(ps -p $pid -o comm=)
#check if pid process is backend process
if [ "doris_be"x != "$pidcomm"x ]; then
echo "ERROR: pid process may not be be. "
exit 1
fi
if kill -0 $pid; then
if kill -${signum} $pid > /dev/null 2>&1; then
echo "stop $pidcomm, and remove pid file. "
rm $pidfile
exit 0
else
exit 1
fi
else
echo "Backend already exit, remove pid file. "
# kill
if kill -${signum} $pid >/dev/null 2>&1; then
echo "stop $pidcomm, and remove pid file. "
rm $pidfile
exit 0
else
echo "ERROR: failed to stop $pid"
exit 1
fi
else
echo "$pidfile does not exist"
echo "ERROR: $pidfile does not exist"
exit 1
fi

View File

@ -16,33 +16,70 @@
# specific language governing permissions and limitations
# under the License.
curdir=`dirname "$0"`
curdir=`cd "$curdir"; pwd`
curdir=$(dirname "$0")
curdir=$(
cd "$curdir"
pwd
)
export DORIS_HOME=`cd "$curdir/.."; pwd`
export PID_DIR=`cd "$curdir"; pwd`
export DORIS_HOME=$(
cd "$curdir/.."
pwd
)
export PID_DIR=$(
cd "$curdir"
pwd
)
while read line; do
envline=`echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*="`
envline=`eval "echo $envline"`
envline=$(echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*=")
envline=$(eval "echo $envline")
if [[ $envline == *"="* ]]; then
eval 'export "$envline"'
fi
done < $DORIS_HOME/conf/fe.conf
done <$DORIS_HOME/conf/fe.conf
pidfile=$PID_DIR/fe.pid
if [ -f $pidfile ]; then
pid=`cat $pidfile`
pidcomm=`ps -p $pid -o comm=`
if [ "java" != "$pidcomm" ]; then
echo "ERROR: pid process may not be fe. "
fi
pid=$(cat $pidfile)
if kill -9 $pid > /dev/null 2>&1; then
echo "stop $pidcomm, and remove pid file. "
rm $pidfile
fi
#check if pid valid
if test -z "$pid"; then
echo "ERROR: invalid pid."
exit 1
fi
#check if pid process exist
if ! kill -0 $pid; then
echo "ERROR: fe process $pid does not exist."
exit 1
fi
pidcomm=$(ps -p $pid -o comm=)
#check if pid process is frontend process
if [ "java"x != "$pidcomm"x ]; then
echo "ERROR: pid process may not be fe. "
exit 1
fi
#kill pid process and check it
if kill $pid >/dev/null 2>&1; then
while true; do
if ps -p $pid >/dev/null; then
echo "waiting fe to stop, pid: $pid"
sleep 2
else
echo "stop $pidcomm, and remove pid file. "
if [ -f $pidfile ]; then rm $pidfile; fi
exit 0
fi
done
else
echo "ERROR: failed to stop $pid"
exit 1
fi
else
echo "ERROR: $pidfile does not exist"
exit 1
fi