1.在etc/crontab写定时执行的脚本
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
0 0 * * * root /usr/local/service/nft-content-service/nohup.sh
0 0 * * * root /usr/local/service/nft-cos-service/nohup.sh
0 0 * * * root /usr/local/service/nft-gateway/nohup.sh
0 0 * * * root /usr/local/service/nft-order-service/nohup.sh
0 0 * * * root /usr/local/service/nft-pay-service/nohup.sh
0 0 * * * root /usr/local/service/nft-user-service/nohup.sh

 

2.创建 nohup.sh
date=`date -d "yesterday" +%Y_%m_%d`
cp -r /usr/local/service/nft-user-service/nft-user-service.log  /usr/local/service/nft-user-service/${date}.log
cat /dev/null > /usr/local/service/nft-user-service/nft-user-service.log

 

 

启动jar的脚本
run-nft-user-service.sh

APP_NAME=nft-user-service.jar usage() { echo "执行操作命令 [start|stop|restart|status]" exit 1 } if_exist() { pid=`ps -ef|grep $APP_NAME|grep -v grep|awk "{print $2}"` if [ -z "${pid}" ]; then return 1 else return 0 fi } start() { if_exist if [ $? -eq 0 ]; then echo "${APP_NAME} already running . pid=${pid}" else nohup java -jar -Dspring.profiles.active=prod ${APP_NAME} >> nft-user-service.log 2>&1 & npid=`ps -ef|grep $APP_NAME|grep -v grep|awk "{print $2}"` echo "start ${APP_NAME} success, pid=${npid}" fi } stop() { if_exist if [ $? -eq 0 ]; then kill -9 $pid echo "stop $pid success". else echo "${APP_NAME} is not running" fi } status() { if_exist if [ $? -eq 0 ]; then echo "${APP_NAME} is running. pid is ${pid}" else echo "${APP_NAME} is not running " fi } restart() { stop sleep 5 start } case "$1" in "start") start ;; "stop") stop ;; "status") status ;; "restart") restart ;; *) usage ;; esac

  

posted on 2023-02-28 11:45  我是坏男孩  阅读(36)  评论(0编辑  收藏  举报