@echo off
chcp 65001
rem 启动扩展本地环境变量延迟
setlocal enabledelayedexpansion
rem 通过文件名截取出服务名称
set filename=%~n0
set service_name=%filename:server-=%
rem 默认参数
set jvm_options_file=%~dp0jvm-%service_name%.options
set spring_profiles_active=prod
rem 读取参数
:readParams
set p=%*
:loop
for /f "tokens=1*" %%a in ("%p%") do (
set p=%%b
for /f "tokens=1* delims==" %%i in ("%%a") do (
if "%%i"=="jvm" (
if not "%%j"=="" set jvm_options_file=%cd%\%%j
) else if "%%i"=="active" (
if not "%%j"=="" set spring_profiles_active=%%j
) else (
echo unknown parameter name: %%i
goto usage
)
)
)
if defined p goto loop
goto start
:usage
echo Usage: %0 [jvm=^] [active=^]
echo jvm: 可选。jvm配置文件,默认值 %~dp0jvm-%service_name%.options
echo active: 可选。jar包启动的配置,默认值prod,即配置文件为application-prod.yml
echo Example: '%0' or '%0 active=prod'
goto :eof
:start
echo service name is %service_name%
title %service_name%
if not exist %jvm_options_file% (
echo Error: Unable to access jvm options file %jvm_options_file%
goto :eof
)
rem 输出配置文件目录
echo jvm-options-file:%jvm_options_file%
rem 读取文件第一列,type是显示文件内容的命令
set jvm_options=-Dfile.encoding=utf-8
for /f %%a in ('type %jvm_options_file%') do (
rem 必须用!!而不能用%%
set jvm_options=!jvm_options! %%a
)
rem 输出jvm配置
echo jvm-options:%jvm_options%
rem 输出启动环境
echo spring.profiles.active=%spring_profiles_active%
rem jar包路径
set jar_path=%~dp0..\%service_name%.jar
if not exist %jar_path% (
echo Error: Unable to access jarfile %jar_path%
goto :eof
)
rem 启动
java %jvm_options% -jar %jar_path% --spring.profiles.active=%spring_profiles_active%
endlocal
5、添加server.sh文件,编写打包的启动停止脚本
#!/usr/bin/env bash
BIN="${BASH_SOURCE-$0}"
DIR_NAME="$(dirname ${BIN})"
# 脚本所在路径
DIR="$(cd ${DIR_NAME}; pwd)"
# 程序根目录
PROGRAM_ROOT=${DIR%/*}
# 通过文件名截取出服务名称
filename=${0##*/server-}
service_name=${filename%.sh}
# 默认参数
jvm_options_file=${DIR_NAME}/jvm-${service_name}.options
spring_profiles_active=prod
# 其它参数
other_params=
# 运行名称,用来记录pid的唯一标识
pid_name=
# 打印错误信息
error(){
echo -e "\033[31m$1\033[0m"
}
info(){
echo -e "\033[34m$1\033[0m"
}
showUsage(){
echo "Usage: $0 {start|stop|restart|status} [jvm=] [active=]"
echo " start|stop|restart|status: 必选。启动|停止|重启|状态"
echo " jvm: 可选。jvm配置文件,默认值 ${DIR_NAME}/jvm-${service_name}.options"
echo " active: 可选。jar包启动的配置,默认值prod,即配置文件为application-prod.yml"
echo " name: 可选。启动后用来存储pid的唯一标识符,pid存储文件为[jar包所在目录]/pid/server-${service_name}-[name].pid"
echo "Example: '$0 start' or '$0 start active=prod'"
}
# 读取参数
for i in "${@:2}"
do
param=(${i//=/ })
case ${param[0]} in
jvm)
if [[ -n ${param[1]} ]]
then
jvm_options_file=${param[1]}
fi
;;
active)
if [[ -n ${param[1]} ]]
then
spring_profiles_active=${param[1]}
fi
;;
name)
if [[ -n ${param[1]} ]]
then
pid_name=${param[1]}
fi
;;
*)
other_params="${other_params} ${i}"
;;
esac
done
if [[ -z ${pid_name} ]]
then
pid_name=${spring_profiles_active}
fi
# ivm参数配置文件
if [[ ! -f ${jvm_options_file} ]]
then
error "Error: Unable to access jvm options file ${jvm_options_file}"
exit 1
fi
echo spring.profiles.active=${spring_profiles_active}
# pid存储文件
PID_DIR=${PROGRAM_ROOT}/pid
if [[ ! -e ${PID_DIR} ]]
then
mkdir -p ${PID_DIR}
fi
PID_FILE=${PID_DIR}/server-${service_name}-${pid_name}.pid
# 读取命令参数
case $1 in
start)
echo Starting...
# 输出jvm配置目录
echo jvm-options-file:${jvm_options_file}
# 输出jvm配置
for line in $(cat ${jvm_options_file})
do
if [[ -z ${jvm_options} ]]
then
jvm_options="${line}"
else
jvm_options="${jvm_options} ${line}"
fi
done
echo jvm-options:${jvm_options}
# jar包路径
jarPath=${PROGRAM_ROOT}/${service_name}.jar
if [[ ! -f ${jarPath} ]]
then
error "Error: Unable to access jarfile ${jarPath}"
error "Failed"
exit 1
fi
# 检测如果同样的环境已经启动一次则退出并打印提示信息
if [[ -f ${PID_FILE} ]]
then
if kill -0 `cat ${PID_FILE}` > /dev/null 2>&1
then
error "already running [${spring_profiles_active}] as process `cat ${PID_FILE}`."
exit 0
fi
fi
# 后台启动
# echo "nohup java ${jvm_options} -jar ${jarPath} --spring.profiles.active=${spring_profiles_active} ${other_params} > /dev/null 2>&1 &"
nohup java ${jvm_options} -jar ${jarPath} --spring.profiles.active=${spring_profiles_active} ${other_params} > /dev/null 2>&1 &
if [[ $? -eq 0 ]]
then
echo -n $! > ${PID_FILE}
if [[ $? -eq 0 ]]
then
sleep 1
echo STARTED. $!
else
echo FAILED TO WRITE PID
exit 1
fi
else
echo SERVER DID NOT START
exit 1
fi
;;
stop)
echo Stopping...
# 停止服务
if [[ ! -f ${PID_FILE} ]]
then
echo "no server to stop (could not find file $PID_FILE)"
else
kill $(cat ${PID_FILE})
rm ${PID_FILE}
echo STOPPED
fi
exit 0
;;
restart)
shift
"$0" stop ${@}
sleep 3
"$0" start ${@}
;;
status)
if [[ -f ${PID_FILE} ]]
then
if kill -0 `cat ${PID_FILE}` > /dev/null 2>&1
then
info "running [${spring_profiles_active}] as process `cat ${PID_FILE}`."
exit 0
fi
else
echo "It is probably not running."
exit 0
fi
;;
*)
showUsage
exit 1
esac
CMS概述
并发标记清理垃圾回收(Concurrent Mark and Sweep GC)算法的主要目标是在GC过程中,减少暂停用户线程的次数以及在不得不暂停用户线程的请夸功能,尽可能短的暂停用户线程的时间。这对于交互式应用,比如web应用来说,是非常重要的。
CMS垃圾回收针对新生代和老年代采用不同的策略。相比同吞吐量垃圾回收,它要复杂的多。吞吐量垃圾回收在执
1,找到配置文件
vi /etc/sysconfig/iptables
2,添加端口开放,增加一行,开放18081端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 18081 -j ACCEPT
3,保存
ESC
:wq!
4,重启服务
service iptables
使用Android SDK Manager 更新了Anadroid SDK Tooks 之后,
打开eclipse提示 This Android SDK requires Android Developer Toolkit version 23.0.0 or above, 点击Check for Updates
检测一会后提示 No update were found