脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| #!/bin/bash #本脚本基本无需改动,注意要点均已用中文说明 # 1. 请将本脚本放到Linux系统的path路径下,最好是/bin目录下 # 2. 请给本脚本设备可执行权限 # 3. 启动示例 sh ./script.sh start # 4. 重启示例 sh ./script.sh restart # 5. 停止示例 sh ./script.sh stop # 6. 查看状态示例 sh ./script.sh status
# JAVA_CMD=`which java`
# APP_NAME="trans-admin.jar";
if [ -z "${JAVA_CMD}" ];then echo "Please install the Java environment"; exit 1; fi
# usage() { echo "Usage: sh ./script.sh [start|stop|restart|status]" exit 1 }
# if [ $# -lt 1 ]; then usage fi
# OPERATION=$1;
# is_running(){ # PID=`ps -ef|grep ${APP_NAME}|grep -v grep|awk '{print $2}'` if [ -z "${PID}" ]; then return 0 else return 1 fi }
# start(){ is_running if [ $? -eq "1" ]; then echo "${APP_NAME} is already running. pid is ${PID} ." else ## 启动 jar 包 echo "${APP_NAME} starting ...... " JVM_PARAMS="-Xms1280m -Xmx2560m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCCause -XX:+PrintHeapAtGC -Xloggc:/home/trans/logs/gc.log" APP_PARAMS="--spring.profiles.active=dev" nohup ${JAVA_CMD} ${JVM_PARAMS} -jar ${APP_NAME} ${APP_PARAMS} > /dev/null 2>&1 & echo "启动${APP_NAME}" sleep 1 echo "${APP_NAME} started completed " echo "" fi }
# stop(){ is_running if [ $? -eq "1" ]; then echo "execute kill ${PID}" kill ${PID} sleep 1 echo "${APP_NAME} stopped completed " else echo "${APP_NAME} is not running" fi }
# status(){ is_running if [ $? -eq "1" ]; then echo "${APP_NAME} is running. pid is ${PID}" else echo "${APP_NAME} is NOT running." fi }
# restart(){ stop sleep 15 start }
case "$OPERATION" in "start") start ;; "stop") stop ;; "status") status ;; "restart") restart ;; *) usage ;; esac exit 0
|
windows创建文件传到Linux需要把回车符转换:
用notepad++中“编辑”菜单中“文档格式转换”中“转换为UNIX”。
java -jar
直接进入服务器或者在本地执行 java -jar显示:
1 2 3 4
| java [-options] class [args...] (执行类) 或 java [-options] -jar jarfile [args...] (执行 jar 文件)
|
java -jar , -jar前是jvm的参数, args是应用的参数。