智慧屏 安装 app如何提升家庭娱乐与教育体验的关键工具
706
2022-09-01
用脚本启动和关闭jar包或者war包
启动Spring Boot
启动
后台启动,启动日志输出到out
nohup java -jar weibo-interface-1.0.jar >/dev/null 2>&1 &if [ $? -eq 0 ]then echo "start `hostname`else echo "start `hostname`Failed!"fi
关闭
pidfile=`jps -l | grep 'weibo-interface-1.0.jar' | awk '{print $1}'`kill -9 $pidfileif [ $? -eq 0 ]then echo "stop `hostname`else echo "stop `hostname`fi
自用
启动
重新引入配置文件 引入外部jar包 打印pid到WeiboSerachServer.pid
#!/bin/sh# WeiboSerachServerexport JAVA_HOME=/data/lib/jdk8export APP_HOME=.export CLSPATH=$APP_HOME/cis-ws-1.0.jarexport APP_LIB=$APP_HOME/lib#------------------------------------------------echo UserAnalysisServerV2 created by zhaidwecho -------------------------------------echo using JAVA_HOME: $JAVA_HOMEfor i in $APP_LIB/*.jar; do export CLSPATH=$CLSPATH:$idoneexport CLASSPATH=$APP_HOME/config:$CLSPATHecho using classpath: $CLASSPATHecho -------------------------------------nohup $JAVA_HOME/bin/java -server -Xmx6g com.st.cis.main.WeiboSerachServer cis-ws >/dev/null 2>&1 $JAVA_HOME/bin/java -server -Xmx2g com.st.cis.main.WeiboSerachServerif [ $? -eq 0 ]then echo "WeiboSerachServer start Success!"else echo "WeiboSerachServer start Faild!" exit;fiecho $! >
关闭
#!/bin/bashpidfile=`ps -ef | grep 'WeiboSerachServer' | grep -v "grep" | grep cis-ws$ | awk '{print $2}'`kill -9 $pidfileif [ $? -eq 0 ]then echo "stop `hostname`else echo "stop `hostname`fi
启动和关闭
#!/bin/sh#BIN_NAME="simple-sb-service-0.0.1.jar"BIN_NAME="fuyoukache-knowledgebase-service-0.0.1.jar"SERVICE_PORT=38889BASE_DIR=$(pwd)COMMAND_STR=""# local function defin ##function helper() { echo "-h help" echo "-b basedir" echo "-c command(start | stop | restart)" exit 1}## end of function defin ###while getopts "hb:c:" argdo case $arg in h) helper ;; b) BASE_DIR=$OPTARG ;; c) COMMAND_STR=$OPTARG ;; ?) helper exit 1 esacdoneLOG_DIR="${BASE_DIR}/log"CONF_DIR="${BASE_DIR}/conf"DATA_DIR="${BASE_DIR}/data"LIB_DIR="${BASE_DIR}/lib"BIN_PATH="${LIB_DIR}/${BIN_NAME}"echo "=======>load config<====="echo "BASE_DIR : ${BASE_DIR}"echo "CONF_DIR : ${CONF_DIR}"echo "DATA_DIR : ${DATA_DIR}"echo "LIB_DIR : ${LIB_DIR}"echo "BIN_PATH : ${BIN_PATH}"echo "COMMAND_STR: ${COMMAND_STR}"echo "=======>end config<====="app_conf_file="${CONF_DIR}/application.properties"log_conf_file="${CONF_DIR}/logback.xml"if [ ! -e ${app_conf_file} ];then echo "${app_conf_file} helper exit 1fiif [ ! -e ${log_conf_file} ]; then echo "${log_conf_file} helper exit 1fiSYSTEM_OPT="-Xms256M -Xmx512M -Xss1024k"APP_OPT=" --spring.config.location=${app_conf_file} --logging.config=${log_conf_file} \ --server.port=$SERVICE_PORT -b ${BASE_DIR}function getpid() { pid=$(ps -elf | grep ${BIN_PATH} | grep -v 'grep' | awk -F ' ' '{print $4}') echo $pid}function start() { pid=$(getpid) if [ ! -z $pid ];then echo "service already run as pid:$pid" exit 1 fi COMMAND="nohup java -jar ${SYSTEM_OPT} ${BIN_PATH} ${APP_OPT} $@ > /dev/null 2>> ${LOG_DIR}/${BIN_NAME}.err &" echo $COMMAND eval $COMMAND}function stop() { pid=$(getpid) echo $pid if [ -z $pid ];then echo "service not running." exit 1 fi echo "stoping...$pid" kill $pid while [ -e /proc/$pid ]; do echo -n '=' sleep 1 done echo "$pid}if [ "start" == "$COMMAND_STR" ];then startelif [ "stop" == "$COMMAND_STR" ];then stopelif [ "restart" == "$COMMAND_STR" ];then stop && startelse helperfi
/dev/null :代表空设备文件 > :代表重定向到哪里,例如:echo “123” > /home/123.txt 1 :表示stdout标准输出,系统默认值是1,所以">/dev/null"等同于"1>/dev/null" 2 :表示stderr标准错误 & :表示等同于的意思,2>&1,表示2的输出重定向等同于1
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~