-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] The FE&BE&CN startup script automatically detects that the startup is successful #48793
base: main
Are you sure you want to change the base?
[Enhancement] The FE&BE&CN startup script automatically detects that the startup is successful #48793
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,9 +171,18 @@ fi | |
|
||
if [ ${RUN_BE} -eq 1 ]; then | ||
pidfile=$PID_DIR/be.pid | ||
process_name="backend" | ||
conf_file="$STARROCKS_HOME/conf/be.conf" | ||
fi | ||
if [ ${RUN_CN} -eq 1 ]; then | ||
pidfile=$PID_DIR/cn.pid | ||
process_name="compute node" | ||
conf_file="STARROCKS_HOME/conf/cn.conf" | ||
fi | ||
|
||
http_port=$(grep -v ^# $conf_file |grep be_http_port| sed 's/.*= *//') | ||
if [ -z "$http_port" ]; then | ||
http_port="8040" | ||
fi | ||
|
||
if [ -f $pidfile ]; then | ||
|
@@ -206,14 +215,47 @@ fi | |
if [ ${RUN_LOG_CONSOLE} -eq 1 ] ; then | ||
# force glog output to console (stderr) | ||
export GLOG_logtostderr=1 | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't remove this, it'll break the assumption that crash core will be redirected to be.out/cn.out |
||
# redirect stdout/stderr to ${LOG_FILE} | ||
exec &>> ${LOG_FILE} | ||
fi | ||
|
||
echo "start time: $(date), server uptime: $(uptime)" | ||
check_health() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really tricky. I am inclined not to do so in start script. the |
||
response=$(curl -s -w "\n%{http_code}" http://127.0.0.1:${http_port}/api/health) | ||
body=$(echo "$response" | sed -e '$d') | ||
status_code=$(echo "$response" | tail -n1) | ||
|
||
# check http status code | ||
if [ "$status_code" -eq 200 ] | ||
then | ||
# Parse the JSON response and check the status field | ||
status=$(echo "$body" | sed -n 's/.*"status"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') | ||
if [ "$status" = "OK" ] | ||
then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
echo "start time: $(date), server uptime: $(uptime)" >> ${LOG_FILE} | ||
if [ ${RUN_DAEMON} -eq 1 ]; then | ||
nohup ${START_BE_CMD} "$@" </dev/null & | ||
echo "The $process_name process is starting!" | ||
nohup ${START_BE_CMD} "$@" &>/dev/null & | ||
if command -v curl &>/dev/null; then | ||
timeout=30 | ||
end_time=$((SECONDS + timeout)) | ||
while [ $SECONDS -lt $end_time ]; do | ||
if check_health; then | ||
echo "The $process_name process has started successfully!" | ||
exit 0 | ||
fi | ||
sleep 1 | ||
done | ||
echo "The startup time is more than $timeout seconds, the $process_name process may not start successfully!" | ||
else | ||
echo "This node does not have the curl command, please manually check whether the $process_name process is successfully started" | ||
fi | ||
else | ||
exec ${START_BE_CMD} "$@" </dev/null | ||
fi | ||
zhuxt2015 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,18 +217,58 @@ if [ ${RUN_LOG_CONSOLE} -eq 1 ] ; then | |
fi | ||
# force sys_log_to_console = true | ||
echo -e "\nsys_log_to_console = true" >> $STARROCKS_HOME/conf/fe.conf | ||
else | ||
# redirect all subsequent commands' stdout/stderr into $LOG_FILE | ||
exec &>> $LOG_FILE | ||
fi | ||
|
||
echo "using java version $JAVA_VERSION" | ||
echo $final_java_opt | ||
echo "start time: $(date), server uptime: $(uptime)" | ||
echo "using java version $JAVA_VERSION" >> $LOG_FILE | ||
echo $final_java_opt >> $LOG_FILE | ||
echo "start time: $(date), server uptime: $(uptime)" >> $LOG_FILE | ||
|
||
process_name="frontend" | ||
conf_file="$STARROCKS_HOME/conf/fe.conf" | ||
http_port=$(grep -v ^# $conf_file | grep http_port | sed 's/.*= *//') | ||
if [ -z "$http_port" ]; then | ||
http_port="8030" | ||
fi | ||
|
||
check_health() { | ||
response=$(curl -s -w "\n%{http_code}" http://127.0.0.1:${http_port}/api/health) | ||
body=$(echo "$response" | sed -e '$d') | ||
status_code=$(echo "$response" | tail -n1) | ||
|
||
# check http status code | ||
if [ "$status_code" -eq 200 ] | ||
then | ||
# Parse the JSON response and check the status field | ||
status=$(echo "$body" | sed -n 's/.*"status"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') | ||
if [ "$status" = "OK" ] | ||
then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# StarRocksFE java process will write its process id into $pidfile | ||
if [ ${RUN_DAEMON} -eq 1 ]; then | ||
nohup $LIMIT $JAVA $final_java_opt com.starrocks.StarRocksFE ${HELPER} ${HOST_TYPE} "$@" </dev/null & | ||
echo "The $process_name process is starting!" | ||
nohup $LIMIT $JAVA $final_java_opt com.starrocks.StarRocksFE ${HELPER} ${HOST_TYPE} "$@" &> /dev/null & | ||
if command -v curl &>/dev/null; then | ||
timeout=30 | ||
end_time=$((SECONDS + timeout)) | ||
while [ $SECONDS -lt $end_time ]; do | ||
if check_health; then | ||
echo "The $process_name process has started successfully!" | ||
exit 0 | ||
fi | ||
sleep 1 | ||
done | ||
echo "The startup time is more than $timeout seconds, the $process_name process may not start successfully!" | ||
else | ||
echo "This node does not have the curl command, please manually check whether the $process_name process is successfully started" | ||
fi | ||
else | ||
exec $LIMIT $JAVA $final_java_opt com.starrocks.StarRocksFE ${HELPER} ${HOST_TYPE} "$@" </dev/null | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The most risky bug in this code is: You can modify the code like this: # StarRocksFE java process will write its process id into $pidfile
if [ ${RUN_DAEMON} -eq 1 ]; then
echo "The $process_name process is starting!"
nohup $LIMIT $JAVA $final_java_opt com.starrocks.StarRocksFE ${HELPER} ${HOST_TYPE} "$@" &> /dev/null &
pid=$!
if command -v curl &>/dev/null; then
timeout=30
end_time=$((SECONDS + timeout))
while [ $SECONDS -lt $end_time ]; do
if check_health; then
echo "The $process_name process has started successfully!"
exit 0
fi
sleep 1
done
echo "The startup time is more than $timeout seconds, the $process_name process may not start successfully!"
kill $pid # Ensure the process does not linger if startup fails
else
echo "This node does not have the curl command, please manually check whether the $process_name process is successfully started"
fi
else
exec $LIMIT $JAVA $final_java_opt com.starrocks.StarRocksFE ${HELPER} ${HOST_TYPE} "$@" </dev/null
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this already loaded by
export_env_from_conf $STARROCKS_HOME/conf/cn.conf
in line 72