首页 > 系统相关 >写一个linux 定时器与jar的启动脚本

写一个linux 定时器与jar的启动脚本

时间:2023-02-28 11:58:20浏览次数:34  
标签:定时器 NAME service jar nft usr linux local user

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

  

标签:定时器,NAME,service,jar,nft,usr,linux,local,user
From: https://www.cnblogs.com/imfjj/p/17149254.html

相关文章

  • Linux 经典脚本
    编写helloworld脚本#!/bin/bash#编写helloworld脚本echo"HelloWorld!"通过位置变量创建Linux系统账户及密码#!/bin/bash#通过位置变量创建Linux系......
  • linux 定时任务 crontab
    linux定时任务crontabcrontab-l列出所有任务crontab-e编辑任务servicecrondreload刷新任务......
  • linux命令的使用
    文章目录​​查看文件的实际路径​​​​mkdir已存在目录会覆盖么​​​​linux常用的颜色​​​​文件名有特殊符号的时候​​记录一些不好分类的命令查看文件的实际路......
  • linux定时任务crontab的使用
    文章目录​​linux​​​​crontab参数列表​​​​crontab-e和vim/etc/crontab的区别​​​​编辑完定时任务重启什么吗​​​​定时任务是否生效,查看日志​​​​定时......
  • 高并发linux内核参数调优
    高并发linux内核参数调优内核参数说明#【net】########################cat/proc/sys/net/ipv4/tcp_syncookies#默认值:1#作用:是否打开SYNCookie功能,该功能可以防......
  • linux重置密码和单用户模式
    CentOS7.9CentOS7系统root密码丢失找回方法(史上最好)1.重新启动或开启CentOS7系统,在选择进入系统Grub菜单界面如下图1-1,根据提示按“e”小写字母进入编辑界面,如下图1-2......
  • linux驱动移植-GPIO子系统
    ----------------------------------------------------------------------------------------------------------------------------内核版本:linux5.2.8根文件系统:busybo......
  • Linux基本命令--ping的语法
    1、命令介绍ping命令用来测试主机之间网络的连通性,通过发送Internet控制消息协议(ICMP)回响请求消息来验证与另一台TCP/IP计算机的IP级连接.用途:发送一个回送信号请求给网络......
  • Linux - firewalld 使用方法
    firewalld防火墙是Centos7系统默认的防火墙管理工具,取代了之前的iptables防火墙,也是工作在网络层,属于包过滤防火墙。1、安装firewallyuminstallfirewalld......
  • 从Linux Bridge引发的网桥、交换机与路由器区别探究
    背景最近接触docker的网络配置方式,发现其默认会创建一个docker0的LinuxBridge,宿主机上运行的容器可以通过连接该birdge实现与外网的通信,根据bridge这个命名很自然的认为......