forked from oldmanpushcart/greys-anatomy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request oldmanpushcart#118 from oldmanpushcart/develop-for…
…-1.7.4.0 Develop for 1.7.4.0
- Loading branch information
Showing
25 changed files
with
993 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# program : greys-attach | ||
# author : [email protected] | ||
# date : 2016-02-05 | ||
# desc : write for july | ||
# version : 1.7.4.0 | ||
|
||
|
||
# the usage | ||
usage() | ||
{ | ||
echo " | ||
greys attach usage: | ||
the format was [-s] <PID> | ||
<PID> : the target Java Process ID | ||
-s : attach jvm with silent | ||
example: | ||
./ga.sh <PID> | ||
./ga.sh -s <PID> | ||
" | ||
} | ||
|
||
# exit shell with err_code | ||
# $1 : err_code | ||
# $2 : err_msg | ||
exit_on_err() | ||
{ | ||
[[ ! -z "${2}" ]] && echo "${2}" 1>&2 | ||
exit ${1} | ||
} | ||
|
||
|
||
# the option to control ga.sh attach jvm with silent | ||
OPTION_SILENT=0 | ||
|
||
while getopts "sh" ARG | ||
do | ||
case ${ARG} in | ||
s) OPTION_SILENT=1;; | ||
h) usage;exit 0;; | ||
*) usage;exit 1;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)); | ||
|
||
if [[ $# -lt 1 ]]; then | ||
exit_on_err 1 "illegal arguments, the <PID> is required." | ||
fi | ||
|
||
if [[ ${OPTION_SILENT} -eq 1 ]]; then | ||
./greys.sh -C "${@}" || exit 1 | ||
else | ||
./greys.sh -C "${@}" \ | ||
&& echo "greys attach to target(${@}) success" \ | ||
|| exit_on_err 1 "greys attach to target(${@}) failed." | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# author : [email protected] | ||
# date : 2015-05-04 | ||
# desc : write for july | ||
# version : 1.7.0.1 | ||
# version : 1.7.4.0 | ||
|
||
# define greys's home | ||
GREYS_HOME=${HOME}/.greys | ||
|
@@ -31,6 +31,17 @@ DEFAULT_TARGET_PORT="3658" | |
JVM_OPS=""; | ||
|
||
|
||
# the option to control greys.sh check the permission | ||
OPTION_CHECK_PERMISSION=1 | ||
|
||
# the option to control greys.sh update version if necessary | ||
OPTION_UPDATE_IF_NECESSARY=1 | ||
|
||
# the option to control greys.sh attach target jvm | ||
OPTION_ATTACH_JVM=1 | ||
|
||
# the option to control greys.sh active greys-console | ||
OPTION_ACTIVE_CONSOLE=1 | ||
|
||
# exit shell with err_code | ||
# $1 : err_code | ||
|
@@ -75,7 +86,7 @@ reset_for_env() | |
[ -z ${JAVA_HOME} ] && JAVA_HOME=/opt/taobao/java | ||
|
||
# check the jvm version, we need 1.6+ | ||
local JAVA_VERSION=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '/java version/&&$2>"1.5"{print $2}') | ||
local JAVA_VERSION=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '/version/&&$2>"1.5"{print $2}') | ||
[[ ! -x ${JAVA_HOME} || -z ${JAVA_VERSION} ]] && exit_on_err 1 "illegal ENV, please set \$JAVA_HOME to JDK6+" | ||
|
||
# reset BOOT_CLASSPATH | ||
|
@@ -254,34 +265,54 @@ active_console() | |
fi | ||
} | ||
|
||
|
||
|
||
|
||
# the main | ||
main() | ||
{ | ||
|
||
check_permission | ||
while getopts "PUJC" ARG | ||
do | ||
case ${ARG} in | ||
P) OPTION_CHECK_PERMISSION=0;; | ||
U) OPTION_UPDATE_IF_NECESSARY=0;; | ||
J) OPTION_ATTACH_JVM=0;; | ||
C) OPTION_ACTIVE_CONSOLE=0;; | ||
?) usage;exit 1;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)); | ||
|
||
if [[ ${OPTION_CHECK_PERMISSION} -eq 1 ]]; then | ||
check_permission | ||
fi | ||
|
||
reset_for_env | ||
|
||
parse_arguments "${@}" \ | ||
|| exit_on_err 1 "$(usage)" | ||
|
||
update_if_necessary \ | ||
|| echo "update fail, ignore this update." 1>&2 | ||
if [[ ${OPTION_UPDATE_IF_NECESSARY} -eq 1 ]]; then | ||
update_if_necessary \ | ||
|| echo "update fail, ignore this update." 1>&2 | ||
fi | ||
|
||
local greys_local_version=$(default $(get_local_version) ${DEFAULT_VERSION}) | ||
|
||
if [[ ${greys_local_version} = ${DEFAULT_VERSION} ]]; then | ||
exit_on_err 1 "greys not found, please check your network." | ||
fi | ||
|
||
attach_jvm ${greys_local_version}\ | ||
|| exit_on_err 1 "attach to target jvm(${TARGET_PID}) failed." | ||
if [[ ${OPTION_ATTACH_JVM} -eq 1 ]]; then | ||
attach_jvm ${greys_local_version}\ | ||
|| exit_on_err 1 "attach to target jvm(${TARGET_PID}) failed." | ||
fi | ||
|
||
if [[ ${OPTION_ACTIVE_CONSOLE} -eq 1 ]]; then | ||
active_console ${greys_local_version}\ | ||
|| exit_on_err 1 "active console failed." | ||
fi | ||
|
||
active_console ${greys_local_version} | ||
} | ||
|
||
|
||
|
||
main "${@}" | ||
main "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/bin/bash | ||
|
||
# program : greys-shell | ||
# author : [email protected] | ||
# date : 2016-02-05 | ||
# desc : write for july | ||
# version : 1.7.4.0 | ||
|
||
# define greys's home | ||
GREYS_HOME=${HOME}/.greys | ||
|
||
# define greys's lib | ||
GREYS_LIB_DIR=${GREYS_HOME}/lib | ||
|
||
# last update greys version | ||
DEFAULT_VERSION="0.0.0.0" | ||
|
||
DEFAULT_TARGET_IP=127.0.0.1 | ||
DEFAULT_TARGET_PORT=3658 | ||
|
||
TARGET_IP=${DEFAULT_TARGET_IP} | ||
TARGET_PORT=${DEFAULT_TARGET_PORT} | ||
|
||
# reset greys work environment | ||
# reset some options for env | ||
reset_for_env() | ||
{ | ||
|
||
# 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 | ||
|
||
# check the jvm version, we need 1.6+ | ||
local JAVA_VERSION=$(${JAVA_HOME}/bin/java -version 2>&1|awk -F '"' '/version/&&$2>"1.5"{print $2}') | ||
[[ ! -x ${JAVA_HOME} || -z ${JAVA_VERSION} ]] && exit_on_err 1 "illegal ENV, please set \$JAVA_HOME to JDK6+" | ||
|
||
} | ||
|
||
# parse the argument | ||
parse_arguments() | ||
{ | ||
|
||
TARGET_IP=$(echo ${1}|awk -F ":" '{print $1}'); | ||
TARGET_PORT=$(echo ${1}|awk -F ":" '{print $2}'); | ||
|
||
# reset ${ip} to default if empty | ||
[ -z ${TARGET_IP} ] && TARGET_IP=${DEFAULT_TARGET_IP} | ||
|
||
# reset ${port} to default if empty | ||
[ -z ${TARGET_PORT} ] && TARGET_PORT=${DEFAULT_TARGET_PORT} | ||
|
||
return 0 | ||
|
||
} | ||
|
||
|
||
# get latest version from local | ||
get_local_version() | ||
{ | ||
ls ${GREYS_LIB_DIR}\ | ||
|awk -F "." '{printf("%03d.%03d.%03d.%03d\n",$1,$2,$3,$4)}'\ | ||
|sort\ | ||
|awk '/^[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9]$/'\ | ||
|tail -1\ | ||
|awk -F "." '{printf("%d.%d.%d.%d\n",$1,$2,$3,$4)}' | ||
} | ||
|
||
# get with default value | ||
# $1 : target value | ||
# $2 : default value | ||
default() | ||
{ | ||
[[ ! -z "${1}" ]] \ | ||
&& echo "${1}" \ | ||
|| echo "${2}" | ||
} | ||
|
||
# exit shell with err_code | ||
# $1 : err_code | ||
# $2 : err_msg | ||
exit_on_err() | ||
{ | ||
[[ ! -z "${2}" ]] && echo "${2}" 1>&2 | ||
exit ${1} | ||
} | ||
|
||
|
||
# greys netcat | ||
greys_nc() | ||
{ | ||
local greys_lib_dir=${GREYS_LIB_DIR}/${1}/greys | ||
while read line; | ||
do | ||
echo ${line} \ | ||
| ${JAVA_HOME}/bin/java \ | ||
-cp ${greys_lib_dir}/greys-core.jar \ | ||
com.github.ompc.greys.core.util.GaNetCat \ | ||
${TARGET_IP} \ | ||
${TARGET_PORT} | ||
done | ||
} | ||
|
||
# the usage | ||
usage() | ||
{ | ||
echo " | ||
greys shell usage: | ||
the format was [@IP:PORT] | ||
[IP] : the target's IP, default ${DEFAULT_TARGET_IP} | ||
[PORT] : the target's PORT, default ${DEFAULT_TARGET_PORT} | ||
example: | ||
echo help|./gs.sh [IP] | ||
echo help|./gs.sh [IP:PORT] | ||
" | ||
} | ||
|
||
main() | ||
{ | ||
|
||
while getopts "h" ARG | ||
do | ||
case ${ARG} in | ||
h) usage;exit 0;; | ||
*) usage;exit 1;; | ||
esac | ||
done | ||
|
||
reset_for_env | ||
|
||
parse_arguments "${@}" \ | ||
|| exit_on_err 1 "$(usage)" | ||
|
||
local greys_local_version=$(default $(get_local_version) ${DEFAULT_VERSION}) | ||
greys_nc ${greys_local_version} | ||
|
||
} | ||
|
||
main "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.