update
parent
18d2a58725
commit
83bf9ef8b2
|
@ -0,0 +1,162 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
# 应用终止脚本
|
||||||
|
# @author Zhang Peng
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ libs
|
||||||
|
|
||||||
|
SCRIPTS_DIR=$(cd `dirname $0`; pwd)
|
||||||
|
|
||||||
|
if [[ ! -x ${SCRIPTS_DIR}/utils.sh ]]; then
|
||||||
|
logError "${SCRIPTS_DIR}/utils.sh not exists!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
source ${SCRIPTS_DIR}/utils.sh
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ functions
|
||||||
|
|
||||||
|
stopServer() {
|
||||||
|
if [[ ! $1 ]]; then
|
||||||
|
logError "please input java app name"
|
||||||
|
return ${ENV_FAILED}
|
||||||
|
fi
|
||||||
|
|
||||||
|
local appName=$1
|
||||||
|
local pid=`jps | grep ${appName} | awk '{print $1}'`
|
||||||
|
if [[ -n "${pid}" ]]; then
|
||||||
|
kill -9 ${pid}
|
||||||
|
if [[ $? -eq ${ENV_SUCCEED} ]]; then
|
||||||
|
printInfo "stop ${appName} succeed"
|
||||||
|
return ${ENV_SUCCEED}
|
||||||
|
else
|
||||||
|
logError "stop ${appName} failed"
|
||||||
|
return ${ENV_FAILED}
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printWarn "${appName} is not running"
|
||||||
|
return ${ENV_SUCCEED}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
startServer() {
|
||||||
|
|
||||||
|
# >>>> validate params
|
||||||
|
if [[ ! $1 ]] || [[ ! $2 ]] || [[ ! $3 ]] || [[ ! $4 ]]; then
|
||||||
|
logError "you must input following params in order:"
|
||||||
|
echo -e "${ENV_COLOR_B_RED}"
|
||||||
|
echo " (1)jarPath"
|
||||||
|
echo " (2)libPath"
|
||||||
|
echo " (3)confPath"
|
||||||
|
echo " (4)logPath"
|
||||||
|
echo " (5)appName [optional]"
|
||||||
|
echo " (6)port [optional]"
|
||||||
|
echo " (7)profile [optional]"
|
||||||
|
echo " (8)debug [optional]"
|
||||||
|
echo -e "\nEg. startServer /usr/lib/dunwu/app.jar /usr/lib/dunwu/lib /usr/lib/dunwu/conf /var/log/dunwu dunwu 8888 prod off"
|
||||||
|
echo -e "${ENV_COLOR_RESET}"
|
||||||
|
return ${ENV_FAILED}
|
||||||
|
fi
|
||||||
|
|
||||||
|
local jarPath=$1
|
||||||
|
local libPath=$2
|
||||||
|
local confPath=$3
|
||||||
|
local logPath=$4
|
||||||
|
local appName=${5:-myapp}
|
||||||
|
local port=${6:-8888}
|
||||||
|
local profile=${7:-prod}
|
||||||
|
local debug=${8:-off}
|
||||||
|
|
||||||
|
# >>>> 1. check java app is started or not
|
||||||
|
# >>>> 1.1. exit script if the app is started
|
||||||
|
local pid=`jps | grep ${appName} | awk '{print $1}'`
|
||||||
|
if [[ -n "${pid}" ]]; then
|
||||||
|
printInfo "${appName} is started, PID: ${pid}"
|
||||||
|
return ${ENV_SUCCEED}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# >>>> 2. package options
|
||||||
|
# GC OPTS
|
||||||
|
local javaOptions="-server -Xms1g -Xmx2g -Xss256k"
|
||||||
|
javaOptions="${javaOptions} -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:NewRatio=4"
|
||||||
|
|
||||||
|
# GC LOG OPTS
|
||||||
|
javaOptions="${javaOptions} -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps"
|
||||||
|
javaOptions="${javaOptions} -verbose:gc -Xloggc:${logPath}/${appName}.gc.log"
|
||||||
|
javaOptions="${javaOptions} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
|
||||||
|
|
||||||
|
# Heap Dump OPTS
|
||||||
|
javaOptions="${javaOptions} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError"
|
||||||
|
javaOptions="${javaOptions} -XX:HeapDumpPath=${logPath}/${appName}.heapdump.hprof"
|
||||||
|
|
||||||
|
# APP OPTS
|
||||||
|
javaOptions="${javaOptions} -Dsun.net.inetaddr.ttl=60 -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
|
||||||
|
if [[ ${profile} ]]; then
|
||||||
|
javaOptions="${javaOptions} -Dspring.profiles.active=${profile}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# DEBUG OPTS
|
||||||
|
if [[ "${debug}" == "on" ]]; then
|
||||||
|
# JMX OPTS
|
||||||
|
local ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/')
|
||||||
|
local jmxPort=$(expr 10000 + ${port})
|
||||||
|
javaOptions="${javaOptions} -Dcom.sun.management.jmxremote=true"
|
||||||
|
javaOptions="${javaOptions} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
|
||||||
|
javaOptions="${javaOptions} -Djava.rmi.server.hostname=${ip} -Dcom.sun.management.jmxremote.port=${jmxPort}"
|
||||||
|
|
||||||
|
# Remote Debug
|
||||||
|
local debugPort=$(expr 20000 + ${port})
|
||||||
|
javaOptions="${javaOptions} -Xdebug -Xnoagent -Djava.compiler=NONE"
|
||||||
|
javaOptions="${javaOptions} -Xrunjdwp:transport=dt_socket,address=${debugPort},server=y,suspend=n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# CLASSPATH
|
||||||
|
local appOptions="-classpath ${libPath}/* -Dlogging.config=file:${confPath}/logback.${profile}.xml"
|
||||||
|
local springConfigFiles="classpath:/,classpath:/config/"
|
||||||
|
local springConfigFiles="${springConfigFiles},file:${confPath}/,file:${confPath}/application.properties"
|
||||||
|
appOptions="${appOptions} --spring.config.location=${springConfigFiles}"
|
||||||
|
appOptions="${appOptions} --spring.cache.ehcache.config=file:${confPath}/config/ehcache.xml"
|
||||||
|
if [[ ${port} ]]; then
|
||||||
|
appOptions="${appOptions} --server.port=${port}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# >>>> 3. create log dir and console log file
|
||||||
|
local consoleLogPath=${logPath}/${appName}.console.log
|
||||||
|
mkdir -p ${logPath}
|
||||||
|
if [[ ! -x ${consoleLogPath} ]]; then
|
||||||
|
touch ${consoleLogPath}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# >>>> 4. start java app
|
||||||
|
# print bootstrap info
|
||||||
|
printInfo "starting ${appName}"
|
||||||
|
echo -e "${ENV_COLOR_B_GREEN}"
|
||||||
|
echo -e "${ENV_COLOR_B_CYAN}\nBOOT PARAMS:${ENV_COLOR_B_GREEN}\n\n"
|
||||||
|
echo "appName=${appName}"
|
||||||
|
echo "jarPath=${jarPath}"
|
||||||
|
echo "libPath=${libPath}"
|
||||||
|
echo "confPath=${confPath}"
|
||||||
|
echo "logPath=${logPath}"
|
||||||
|
echo "port=${port}"
|
||||||
|
echo "profile=${profile}"
|
||||||
|
echo "debug=${debug}"
|
||||||
|
echo -e "${ENV_COLOR_B_CYAN}\nEXEC CLI:${ENV_COLOR_B_GREEN}\n\n"
|
||||||
|
echo "nohup java ${javaOptions} -jar ${jarPath} ${appOptions} >> ${consoleLogPath} 2>&1 &"
|
||||||
|
echo -e "${ENV_COLOR_RESET}"
|
||||||
|
|
||||||
|
# exec boot cli
|
||||||
|
nohup java ${javaOptions} -jar ${jarPath} ${appOptions} >> ${consoleLogPath} 2>&1 &
|
||||||
|
|
||||||
|
# >>>> 5. check java app is started or not
|
||||||
|
local pid=`jps | grep ${appName} | awk '{print $1}'`
|
||||||
|
if [[ -n "${pid}" ]]; then
|
||||||
|
printInfo "start ${appName} succeed, PID: ${pid}"
|
||||||
|
return ${ENV_SUCCEED}
|
||||||
|
else
|
||||||
|
logError "start ${appName} failed"
|
||||||
|
return ${ENV_FAILED}
|
||||||
|
fi
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
# myapp 启动脚本,用于【虚拟机环境】
|
||||||
|
# @author Zhang Peng
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ libs
|
||||||
|
|
||||||
|
SCRIPTS_DIR=$(dirname ${BASH_SOURCE[0]})
|
||||||
|
if [[ ! -x ${SCRIPTS_DIR}/lifecycle.sh ]]; then
|
||||||
|
logError "${SCRIPTS_DIR}/lifecycle.sh not exists!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
source ${SCRIPTS_DIR}/lifecycle.sh
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ main
|
||||||
|
|
||||||
|
APP_DIR=$(cd `dirname $0`/..; pwd)
|
||||||
|
|
||||||
|
export LANG="zh_CN.UTF-8"
|
||||||
|
APP=myapp
|
||||||
|
JAR_PATH=${APP_DIR}/myapp.jar
|
||||||
|
LIB_PATH=${APP_DIR}/lib
|
||||||
|
CONF_PATH=${APP_DIR}/config
|
||||||
|
LOG_DIR=/var/log/dunwu
|
||||||
|
PORT=8888
|
||||||
|
PROFILE=prod
|
||||||
|
DEBUG=off
|
||||||
|
|
||||||
|
declare -a serial
|
||||||
|
serial=(on off)
|
||||||
|
echo -n "是否启动 debug 模式(可选值:on|off):"
|
||||||
|
read DEBUG
|
||||||
|
if ! echo ${serial[@]} | grep -q ${DEBUG}; then
|
||||||
|
echo "是否启动 debug 模式(可选值:on|off)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
startServer ${JAR_PATH} ${LIB_PATH} ${CONF_PATH} ${LOG_DIR} ${APP} ${PORT} ${PROFILE} ${DEBUG}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
# 应用启动脚本
|
||||||
|
# @author Zhang Peng
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ libs
|
||||||
|
|
||||||
|
SCRIPTS_DIR=$(dirname ${BASH_SOURCE[0]})
|
||||||
|
if [[ ! -x ${SCRIPTS_DIR}/lifecycle.sh ]]; then
|
||||||
|
logError "${SCRIPTS_DIR}/lifecycle.sh not exists!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
source ${SCRIPTS_DIR}/lifecycle.sh
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ main
|
||||||
|
|
||||||
|
export LANG="zh_CN.UTF-8"
|
||||||
|
stopServer myapp
|
|
@ -0,0 +1,115 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
# Shell Utils
|
||||||
|
# 使用此脚本,应该先 export ENV_LOG_PATH,指定日志路径;否则将使用默认日志路径 /var/log/shell.log
|
||||||
|
# @author Zhang Peng
|
||||||
|
# -----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ env params
|
||||||
|
|
||||||
|
# 颜色状态
|
||||||
|
# Regular Color
|
||||||
|
export ENV_COLOR_BLACK="\033[0;30m"
|
||||||
|
export ENV_COLOR_RED="\033[0;31m"
|
||||||
|
export ENV_COLOR_GREEN="\033[0;32m"
|
||||||
|
export ENV_COLOR_YELLOW="\033[0;33m"
|
||||||
|
export ENV_COLOR_BLUE="\033[0;34m"
|
||||||
|
export ENV_COLOR_MAGENTA="\033[0;35m"
|
||||||
|
export ENV_COLOR_CYAN="\033[0;36m"
|
||||||
|
export ENV_COLOR_WHITE="\033[0;37m"
|
||||||
|
# Bold Color
|
||||||
|
export ENV_COLOR_B_BLACK="\033[1;30m"
|
||||||
|
export ENV_COLOR_B_RED="\033[1;31m"
|
||||||
|
export ENV_COLOR_B_GREEN="\033[1;32m"
|
||||||
|
export ENV_COLOR_B_YELLOW="\033[1;33m"
|
||||||
|
export ENV_COLOR_B_BLUE="\033[1;34m"
|
||||||
|
export ENV_COLOR_B_MAGENTA="\033[1;35m"
|
||||||
|
export ENV_COLOR_B_CYAN="\033[1;36m"
|
||||||
|
export ENV_COLOR_B_WHITE="\033[1;37m"
|
||||||
|
# Underline Color
|
||||||
|
export ENV_COLOR_U_BLACK="\033[4;30m"
|
||||||
|
export ENV_COLOR_U_RED="\033[4;31m"
|
||||||
|
export ENV_COLOR_U_GREEN="\033[4;32m"
|
||||||
|
export ENV_COLOR_U_YELLOW="\033[4;33m"
|
||||||
|
export ENV_COLOR_U_BLUE="\033[4;34m"
|
||||||
|
export ENV_COLOR_U_MAGENTA="\033[4;35m"
|
||||||
|
export ENV_COLOR_U_CYAN="\033[4;36m"
|
||||||
|
export ENV_COLOR_U_WHITE="\033[4;37m"
|
||||||
|
# Background Color
|
||||||
|
export ENV_COLOR_BG_BLACK="\033[40m"
|
||||||
|
export ENV_COLOR_BG_RED="\033[41m"
|
||||||
|
export ENV_COLOR_BG_GREEN="\033[42m"
|
||||||
|
export ENV_COLOR_BG_YELLOW="\033[43m"
|
||||||
|
export ENV_COLOR_BG_BLUE="\033[44m"
|
||||||
|
export ENV_COLOR_BG_MAGENTA="\033[45m"
|
||||||
|
export ENV_COLOR_BG_CYAN="\033[46m"
|
||||||
|
export ENV_COLOR_BG_WHITE="\033[47m"
|
||||||
|
# Reset Color
|
||||||
|
export ENV_COLOR_RESET="$(tput sgr0)"
|
||||||
|
|
||||||
|
# 常用状态值
|
||||||
|
export ENV_YES=0
|
||||||
|
export ENV_NO=1
|
||||||
|
export ENV_SUCCEED=0
|
||||||
|
export ENV_FAILED=1
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------ functions
|
||||||
|
|
||||||
|
# 显示打印日志的时间
|
||||||
|
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
|
||||||
|
# 那个用户在操作
|
||||||
|
USER=$(whoami)
|
||||||
|
# 日志路径
|
||||||
|
LOG_PATH=${ENV_LOG_PATH:-/var/log/shell.log}
|
||||||
|
# 日志目录
|
||||||
|
LOG_DIR=${LOG_PATH%/*}
|
||||||
|
|
||||||
|
createLogFileIfNotExists() {
|
||||||
|
if [[ ! -x "${LOG_PATH}" ]]; then
|
||||||
|
mkdir -p "${LOG_DIR}"
|
||||||
|
touch "${LOG_PATH}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
logInfo() {
|
||||||
|
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
|
||||||
|
createLogFileIfNotExists
|
||||||
|
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [INFO] [$0] $@" >> "${LOG_PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
logWarn() {
|
||||||
|
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
|
||||||
|
createLogFileIfNotExists
|
||||||
|
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [WARN] [$0] $@" >> "${LOG_PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
logError() {
|
||||||
|
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
|
||||||
|
createLogFileIfNotExists
|
||||||
|
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [ERROR] [$0] $@" >> "${LOG_PATH}"
|
||||||
|
}
|
||||||
|
|
||||||
|
printInfo() {
|
||||||
|
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
|
||||||
|
}
|
||||||
|
|
||||||
|
printWarn() {
|
||||||
|
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
|
||||||
|
}
|
||||||
|
|
||||||
|
printError() {
|
||||||
|
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
|
||||||
|
}
|
||||||
|
|
||||||
|
callAndLog () {
|
||||||
|
$*
|
||||||
|
if [[ $? -eq ${ENV_SUCCEED} ]]; then
|
||||||
|
logInfo "$@"
|
||||||
|
return ${ENV_SUCCEED}
|
||||||
|
else
|
||||||
|
logError "$@ EXECUTE ENV_FAILED"
|
||||||
|
return ${ENV_FAILED}
|
||||||
|
fi
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
# 安装 Ruby
|
||||||
|
|
||||||
|
## 安装 rvm
|
||||||
|
|
||||||
|
### 下载安装 rvm
|
||||||
|
|
||||||
|
- 先安装好 RVM
|
||||||
|
- RVM 是一个便捷的多版本 Ruby 环境的管理和切换工具
|
||||||
|
官网:[https://rvm.io/](https://links.jianshu.com/go?to=https%3A%2F%2Frvm.io%2F)
|
||||||
|
- 在终端控制台命令:
|
||||||
|
$ curl -sSL [https://get.rvm.io](https://links.jianshu.com/go?to=https%3A%2F%2Fget.rvm.io) | bash -s stable 之后按回车键
|
||||||
|
- 截止到目前 最新的版本是 1.29.9
|
||||||
|
- 如下所示:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
:~ admin$ curl -sSL https://get.rvm.io | bash -s stable
|
||||||
|
Downloading https://github.com/rvm/rvm/archive/1.29.1.tar.gz
|
||||||
|
Downloading https://github.com/rvm/rvm/releases/download/1.29.1/1.29.1.tar.gz.asc
|
||||||
|
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.1/1.29.1.tar.gz.asc',
|
||||||
|
but no GPG software exists to validate it, skipping.
|
||||||
|
|
||||||
|
Installing RVM to /Users/admin/.rvm/
|
||||||
|
Adding rvm PATH line to /Users/admin/.profile /Users/admin/.mkshrc /Users/admin/.bashrc /Users/admin/.zshrc.
|
||||||
|
Adding rvm loading line to /Users/admin/.profile /Users/admin/.bash_profile /Users/admin/.zlogin.
|
||||||
|
Installation of RVM in /Users/admin/.rvm/ is almost complete:
|
||||||
|
|
||||||
|
* To start using RVM you need to run `source /Users/admin/.rvm/scripts/rvm`
|
||||||
|
in all your open shell windows, in rare cases you need to reopen all shell windows.
|
||||||
|
|
||||||
|
# admin,
|
||||||
|
#
|
||||||
|
# Thank you for using RVM!
|
||||||
|
# We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
|
||||||
|
#
|
||||||
|
# ~Wayne, Michal & team.
|
||||||
|
|
||||||
|
In case of problems: https://rvm.io/help and https://twitter.com/rvm_io
|
||||||
|
```
|
||||||
|
|
||||||
|
等待一两分钟,成功安装好 RVM。
|
||||||
|
|
||||||
|
### 设置环境变量
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# 1.2 然后,载入 RVM 环境:
|
||||||
|
$ source /etc/profile.d/rvm.sh
|
||||||
|
$ sudo chmod -R 777 /usr/local/rvm/archives
|
||||||
|
|
||||||
|
# 1.3 修改 RVM 下载 Ruby 的源,到 Ruby China 的镜像
|
||||||
|
$ echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > /usr/local/rvm/user/db
|
||||||
|
$ rvm install 2.7.0 --disable-binary
|
||||||
|
|
||||||
|
// 如下所示:
|
||||||
|
AdmindeiMac-4:~ admin$ source ~/.rvm/scripts/rvm
|
||||||
|
AdmindeiMac-4:~ admin$ echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db
|
||||||
|
AdmindeiMac-4:~ admin$ rvm -v
|
||||||
|
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]
|
||||||
|
如果能显示版本号,则安装成功。
|
||||||
|
```
|
||||||
|
|
||||||
|
## 参考资料
|
||||||
|
|
||||||
|
- [MAC_Ruby 安装](https://www.jianshu.com/p/c073e6fc01f5)
|
Loading…
Reference in New Issue