惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
D
DataBreaches.Net
腾讯CDC
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
罗磊的独立博客
月光博客
月光博客
MyScale Blog
MyScale Blog
U
Unit 42
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园 - 【当耐特】
D
Docker
I
InfoQ
雷峰网
雷峰网

博客园 - 程序员老刘

SaaS多租户改造Spring项目核心代码 windows11的vmware启动报错 MySQL8的root帐号授权 centrifugal 的IM消息服务历史消息报错 golang strings.Split的疑问 golang的极简流式编程实现 golang 常用的日期方法和时区的坑 golang SQLite3性能测试 golang的多协程实践 golang redis的模式订阅 golang 实现并发计算文件数量 java开发的zimg客户端 CAS单点登录实践(spring cas client配置) 81进制,用多进制方式把一个长长的整数变短 chrome浏览器自动填充失效问题 spring 登录提示 Bad credentials spring 项目tomcat 8.0.2 发布报错:Could not initialize class org.hibernate.validator.engine.ConfigurationImpl spring tiles界面为空白 activiti部署到linux后流程图不显示汉字的问题
支持restart的启动脚本
程序员老刘 · 2023-04-04 · via 博客园 - 程序员老刘

在实际部署中经常会重启某个进程,有个支持restart的脚本会很方便。

下面的代码是启动数字人制作进程的例子,需要根据自己的需要修改第3行和第26行;

第3行是进程的关键字,第26行是启动进程的命令。

 1 #!/bin/bash
 2   #这里可替换为你自己的执行程序,其他代码无需更改
 3   APP_NAME="droid_make"
 4   #使用说明,用来提示输入参数
 5   usage() {
 6       echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
 7       exit 1
 8   }
 9   #检查程序是否在运行
10   is_exist(){
11     pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
12     #如果不存在返回1,存在返回0
13     if [ -z "${pid}" ]; then
14      return 1
15     else
16       return 0
17     fi
18   }
19   
20   #启动方法
21   start(){
22     is_exist
23     if [ $? -eq "0" ]; then
24       echo "${APP_NAME} is already running. pid=${pid} ."
25     else
26       nohup python3 droid_make.py 2>&1 &
27     fi
28   }
29   
30   #停止方法
31   stop(){
32     is_exist
33     if [ $? -eq "0" ]; then
34       kill -9 $pid
35     else
36       echo "${APP_NAME} is not running"
37     fi
38   }
39   
40   #输出运行状态
41   status(){
42     is_exist
43     if [ $? -eq "0" ]; then
44       echo "${APP_NAME} is running. Pid is ${pid}"
45     else
46       echo "${APP_NAME} is NOT running."
47     fi
48   }
49   
50   #重启
51   restart(){
52     stop
53     start
54   }
55   
56   #根据输入参数,选择执行对应方法,不输入则执行使用说明
57   case "$1" in
58     "start")
59       start
60       ;;
61     "stop")
62       stop
63       ;;
64     "status")
65       status
66       ;;
67     "restart")
68       restart
69       ;;
70     *)
71       usage
72       ;;
73   esac