Skip to content
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

feat(deployment): add datetime output for ob-odc-web.std.log #1420

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions script/start-odc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,25 @@ function usage() {
echo "- SERVER_PORT: deprecated environment variable, same as ODC_SERVER_PORT, for compatibility"
}

function log_info() {
echo 1>&2 "$(date +"%Y-%m-%dT%H:%M:%S.%Z") [INFO]" "$*"
yizhouxw marked this conversation as resolved.
Show resolved Hide resolved
}

function log_error() {
echo 1>&2 "$(date +"%Y-%m-%dT%H:%M:%S.%Z") [ERROR]" "$*"
}

function check_env_value_set() {
local name=$1
local value=$2
if [ -z "$value" ]; then
echo "FATAL ERROR!, environment variable <${name}> not set, cannot start odc-server"
log_error "FATAL ERROR!, environment variable <${name}> not set, cannot start odc-server"
exit 1
fi
}

function init_parameters() {
echo "init parameters start"
log_info "init parameters start"

# init parameters require environment variable
check_env_value_set DATABASE_HOST "${DATABASE_HOST}"
Expand All @@ -82,31 +90,31 @@ function init_parameters() {
starter_directory="${ODC_STARTER_DIR:-${install_directory}/starters}"
obclient_file_path="${OBCLIENT_FILE_PATH:-${install_directory}/obclient/bin/obclient}"
if [ ! -z "${ODC_HOST}" ]; then
echo "ODC_HOST given, will set LOCAL_IP by ODC_HOST, ODC_HOST=${ODC_HOST}"
log_info "ODC_HOST given, will set LOCAL_IP by ODC_HOST, ODC_HOST=${ODC_HOST}"
export LOCAL_IP="${ODC_HOST}"
else
echo "ODC_HOST not given, will set ODC_HOST by ip addr"
export LOCAL_IP=`ip addr | grep "eth0" | grep "inet" | awk '{print $2}' | awk -F '/' '{print $1}'`
log_info "ODC_HOST not given, will set ODC_HOST by ip addr"
export LOCAL_IP=$(ip addr | grep "eth0" | grep "inet" | awk '{print $2}' | awk -F '/' '{print $1}')
fi
export LOCAL_HOSTNAME=`hostname -I | awk -F ' ' '{print $1}'`
export LOCAL_HOSTNAME=$(hostname -I | awk -F ' ' '{print $1}')
export ODC_PROFILE_MODE="${profile}"
echo "init parameters done"
log_info "init parameters done"
}

# init jvm args
function init_jvm_options() {
echo "init jvm options start"
log_info "init jvm options start"
heap_options=${ODC_JVM_HEAP_OPTIONS:-${default_heap_options}}
gc_options=${ODC_JVM_GC_OPTIONS:-${default_gc_options}}
init_remote_debug_options
oom_options=${ODC_JVM_OOM_OPTIONS:-${default_oom_options}}
extra_options="${ODC_JVM_EXTRA_OPTIONS}"
if [ -z "${SPACEV_JAVA_AGENT}" ]; then
spacev_java_agent_options=""
echo "SPACEV_JAVA_AGENT is not set"
log_info "SPACEV_JAVA_AGENT is not set"
else
spacev_java_agent_options="${SPACEV_JAVA_AGENT}"
echo "SPACEV_JAVA_AGENT is set"
log_info "SPACEV_JAVA_AGENT is set"
fi
local log_options="-Dlog4j.configurationFile=${app_log_config_file} -Dodc.log.directory=${app_log_directory}"
local work_dir_options="-Duser.dir=${ODC_WORK_DIR:-${current_work_directory}}"
Expand All @@ -121,41 +129,41 @@ function init_jvm_options() {
local extra_args="${ODC_APP_EXTRA_ARGS}"
app_args="${listen_port_args} ${obclient_args} ${file_args} ${extra_args}"

echo "init jvm options done"
log_info "init jvm options done"
}

function init_remote_debug_options() {
if [ -z "${ODC_REMOTE_DEBUG_PORT}" ]; then
echo "ODC_REMOTE_DEBUG_PORT not set, will disable remote debug."
log_info "ODC_REMOTE_DEBUG_PORT not set, will disable remote debug."
else
echo "ODC_REMOTE_DEBUG_PORT is set to ${ODC_REMOTE_DEBUG_PORT}, will enable remote debug."
log_info "ODC_REMOTE_DEBUG_PORT is set to ${ODC_REMOTE_DEBUG_PORT}, will enable remote debug."
remote_debug_options="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${ODC_REMOTE_DEBUG_PORT}"
fi
}

function init_java_exec() {
echo "init java exec start"
log_info "init java exec start"
try_use_jdk=${ODC_JVM_TRY_USE_JDK:-0}
java_exec=java
if [ ! -z "${JAVA_HOME}" ]; then
echo "JAVA_HOME detected, will use ${JAVA_HOME}/bin/java instead"
log_info "JAVA_HOME detected, will use ${JAVA_HOME}/bin/java instead"
java_exec="${JAVA_HOME}/bin/java"
elif [ "1" = "${try_use_jdk}" ]; then
echo "ODC_JVM_TRY_USE_JDK detected, try detect jdk home directory..."
log_info "ODC_JVM_TRY_USE_JDK detected, try detect jdk home directory..."
local jdk_home=$(dirname $(dirname $(dirname $(readlink -f $(which java)))))
local has_jdk=$(if [ -f "${jdk_home}/bin/java" ]; then echo 1; else echo 0; fi)
if [ "1" = "${has_jdk}" ]; then
export JAVA_HOME=${jdk_home}
echo "jdk_home detected, set as JAVA_HOME, JAVA_HOME=${JAVA_HOME}"
log_info "jdk_home detected, set as JAVA_HOME, JAVA_HOME=${JAVA_HOME}"
java_exec="${JAVA_HOME}/bin/java"
fi
fi
${java_exec} -version
if [ $? != 0 ]; then
echo "FATAL ERROR! java program <${java_exec}> not found, cannot start odc-server"
log_error "FATAL ERROR! java program <${java_exec}> not found, cannot start odc-server"
exit 1
fi
echo "init java exec done, java_exec=${java_exec}"
log_info "init java exec done, java_exec=${java_exec}"
}

main() {
Expand All @@ -169,11 +177,11 @@ main() {
init_jvm_options

if [ ! -e ${jar_file} ]; then
echo "FATAL ERROR!, jar file <${jar_file}> not found, cannot start odc-server"
log_error "FATAL ERROR!, jar file <${jar_file}> not found, cannot start odc-server"
exit 1
fi

echo "Starting odc-server..."
log_info "Starting odc-server..."

export ODC_DATABASE_HOST=${DATABASE_HOST}
export ODC_DATABASE_PORT=${DATABASE_PORT}
Expand All @@ -184,7 +192,7 @@ main() {
local cmd="${java_exec} ${remote_debug_options} ${spacev_java_agent_options} ${gc_options} ${heap_options} ${oom_options}
${extra_options} ${app_options} -jar
${jar_file} ${app_args}"
echo "cmd=${cmd}"
log_info "cmd=${cmd}"
eval ${cmd}
return $?
}
Expand Down