mirror of
https://github.com/alibaba/arthas.git
synced 2026-11-30 15:33:59 +00:00
fix as.sh test string contains space problem. #180
This commit is contained in:
1 parent
16224993a9
commit
f76e9e33af
1 file changed
+23
-23
@@ -75,7 +75,7 @@ default()
|
||||
# check arthas permission
|
||||
check_permission()
|
||||
{
|
||||
[ ! -w ${HOME} ] \
|
||||
[ ! -w "${HOME}" ] \
|
||||
&& exit_on_err 1 "permission denied, ${HOME} is not writable."
|
||||
}
|
||||
|
||||
@@ -86,18 +86,18 @@ reset_for_env()
|
||||
{
|
||||
|
||||
# init ARTHAS' lib
|
||||
mkdir -p ${ARTHAS_LIB_DIR} \
|
||||
mkdir -p "${ARTHAS_LIB_DIR}" \
|
||||
|| exit_on_err 1 "create ${ARTHAS_LIB_DIR} fail."
|
||||
|
||||
# if env define the JAVA_HOME, use it first
|
||||
# if is alibaba opts, use alibaba ops's default JAVA_HOME
|
||||
[ -z ${JAVA_HOME} ] && JAVA_HOME=/opt/taobao/java
|
||||
[ -z "${JAVA_HOME}" ] && JAVA_HOME=/opt/taobao/java
|
||||
|
||||
# iterater throught candidates to find a proper JAVA_HOME at least contains tools.jar which is required by arthas.
|
||||
if [ ! -d ${JAVA_HOME} ]; then
|
||||
if [ ! -d "${JAVA_HOME}" ]; then
|
||||
JAVA_HOME_CANDIDATES=($(ps aux | grep java | grep -v 'grep java' | awk '{print $11}' | sed -n 's/\/bin\/java$//p'))
|
||||
for JAVA_HOME_TEMP in ${JAVA_HOME_CANDIDATES[@]}; do
|
||||
if [ -f ${JAVA_HOME_TEMP}/lib/tools.jar ]; then
|
||||
if [ -f "${JAVA_HOME_TEMP}/lib/tools.jar" ]; then
|
||||
JAVA_HOME=${JAVA_HOME_TEMP}
|
||||
break
|
||||
fi
|
||||
@@ -107,7 +107,7 @@ reset_for_env()
|
||||
# maybe 1.8.0_162 , 11-ea
|
||||
local JAVA_VERSION_STR=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '$2>"1.5"{print $2}')
|
||||
# check the jvm version, we need 1.6+
|
||||
[[ ! -x ${JAVA_HOME} || -z ${JAVA_VERSION_STR} ]] && exit_on_err 1 "illegal ENV, please set \$JAVA_HOME to JDK6+"
|
||||
[[ ! -x "${JAVA_HOME}" || -z "${JAVA_VERSION_STR}" ]] && exit_on_err 1 "illegal ENV, please set \$JAVA_HOME to JDK6+"
|
||||
|
||||
local JAVA_VERSION
|
||||
if [[ $JAVA_VERSION_STR = "1."* ]]; then
|
||||
@@ -119,7 +119,7 @@ reset_for_env()
|
||||
# when java version greater than 9, there is no tools.jar
|
||||
if [[ "$JAVA_VERSION" -lt 9 ]];then
|
||||
# check tools.jar exists
|
||||
if [ ! -f ${JAVA_HOME}/lib/tools.jar ]; then
|
||||
if [ ! -f "${JAVA_HOME}/lib/tools.jar" ]; then
|
||||
exit_on_err 1 "${JAVA_HOME}/lib/tools.jar does not exist, arthas could not be launched!"
|
||||
else
|
||||
BOOT_CLASSPATH=-Xbootclasspath/a:${JAVA_HOME}/lib/tools.jar
|
||||
@@ -134,7 +134,7 @@ reset_for_env()
|
||||
# get latest version from local
|
||||
get_local_version()
|
||||
{
|
||||
ls ${ARTHAS_LIB_DIR} | sort | tail -1
|
||||
ls "${ARTHAS_LIB_DIR}" | sort | tail -1
|
||||
}
|
||||
|
||||
# get latest version from remote
|
||||
@@ -148,17 +148,17 @@ update_if_necessary()
|
||||
{
|
||||
local update_version=$1
|
||||
|
||||
if [ ! -d ${ARTHAS_LIB_DIR}/${update_version} ]; then
|
||||
if [ ! -d "${ARTHAS_LIB_DIR}/${update_version}" ]; then
|
||||
echo "updating version ${update_version} ..."
|
||||
|
||||
local temp_target_lib_dir="$TMP_DIR/temp_${update_version}_$$"
|
||||
local temp_target_lib_zip="${temp_target_lib_dir}/arthas-${update_version}-bin.zip"
|
||||
local target_lib_dir="${ARTHAS_LIB_DIR}/${update_version}/arthas"
|
||||
mkdir -p ${target_lib_dir}
|
||||
mkdir -p "${target_lib_dir}"
|
||||
|
||||
# clean
|
||||
rm -rf ${temp_target_lib_dir}
|
||||
rm -rf ${target_lib_dir}
|
||||
rm -rf "${temp_target_lib_dir}"
|
||||
rm -rf "${target_lib_dir}"
|
||||
|
||||
mkdir -p "${temp_target_lib_dir}" \
|
||||
|| exit_on_err 1 "create ${temp_target_lib_dir} fail."
|
||||
@@ -167,16 +167,16 @@ update_if_necessary()
|
||||
curl \
|
||||
-#Lk \
|
||||
--connect-timeout ${SO_TIMEOUT} \
|
||||
-o ${temp_target_lib_zip} \
|
||||
-o "${temp_target_lib_zip}" \
|
||||
"${ARTHAS_REMOTE_DOWNLOAD_URL}/${update_version}/arthas-packaging-${update_version}-bin.zip" \
|
||||
|| return 1
|
||||
|
||||
# unzip arthas lib
|
||||
unzip ${temp_target_lib_zip} -d ${temp_target_lib_dir} || (rm -rf ${temp_target_lib_dir} \
|
||||
${ARTHAS_LIB_DIR}/${update_version} && return 1)
|
||||
unzip "${temp_target_lib_zip}" -d "${temp_target_lib_dir}" || (rm -rf "${temp_target_lib_dir}" \
|
||||
"${ARTHAS_LIB_DIR}/${update_version}" && return 1)
|
||||
|
||||
# rename
|
||||
mv ${temp_target_lib_dir} ${target_lib_dir} || return 1
|
||||
mv "${temp_target_lib_dir}" "${target_lib_dir}" || return 1
|
||||
|
||||
# print success
|
||||
echo "update completed."
|
||||
@@ -221,7 +221,7 @@ $(${JAVA_HOME}/bin/jps -l | grep -v sun.tools.jps.Jps)
|
||||
list_versions()
|
||||
{
|
||||
echo "Arthas versions under ${ARTHAS_LIB_DIR}:"
|
||||
ls -1 ${ARTHAS_LIB_DIR}
|
||||
ls -1 "${ARTHAS_LIB_DIR}"
|
||||
}
|
||||
|
||||
# parse the argument
|
||||
@@ -432,26 +432,26 @@ main()
|
||||
|
||||
local remote_version=$(get_remote_version)
|
||||
|
||||
if [ -z ${ARTHAS_VERSION} ]; then
|
||||
update_if_necessary ${remote_version} || echo "update fail, ignore this update." 1>&2
|
||||
if [ -z "${ARTHAS_VERSION}" ]; then
|
||||
update_if_necessary "${remote_version}" || echo "update fail, ignore this update." 1>&2
|
||||
else
|
||||
update_if_necessary ${ARTHAS_VERSION} || echo "update fail, ignore this update." 1>&2
|
||||
update_if_necessary "${ARTHAS_VERSION}" || echo "update fail, ignore this update." 1>&2
|
||||
fi
|
||||
|
||||
local arthas_local_version=$(get_local_version)
|
||||
|
||||
if [ ! -z ${ARTHAS_VERSION} ]; then
|
||||
if [ ! -z "${ARTHAS_VERSION}" ]; then
|
||||
arthas_local_version=${ARTHAS_VERSION}
|
||||
fi
|
||||
|
||||
if [ ! -d ${ARTHAS_LIB_DIR}/${arthas_local_version} ]; then
|
||||
if [ ! -d "${ARTHAS_LIB_DIR}/${arthas_local_version}" ]; then
|
||||
exit_on_err 1 "arthas not found, please check your network."
|
||||
fi
|
||||
|
||||
sanity_check
|
||||
|
||||
echo "Calculating attach execution time..."
|
||||
time (attach_jvm ${arthas_local_version} || exit 1)
|
||||
time (attach_jvm "${arthas_local_version}" || exit 1)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit_on_err 1 "attach to target jvm (${TARGET_PID}) failed, check ${HOME}/logs/arthas/arthas.log or stderr of target jvm for any exceptions."
|
||||
|
||||
Reference in new issue
Block a user