supervisor 配置程序挂起自启动
2024-08-21 03:43:25
使用 supervisor 服务,将程序监控起来,如果程序挂掉了,可以实现自启动
编写 c++ 程序 test.c
#include <stdio.h>
#include <string.h> int main(){
FILE *fp = fopen("./1.txt","a+");
if(fp==){
printf("can't open file\n");
return ;
} int ix = ;
for(;;ix++){
fseek(fp,,SEEK_END);
char s_add_arr[];
memset(s_add_arr,'\0',);
sprintf(s_add_arr,"%i\n",ix);
fwrite(s_add_arr,strlen(s_add_arr),,fp); sleep();
}
fclose(fp);
return ;
}
启动服务
supervisord -c /etc/supervisord.conf
# 使用了默认的配置文件 在 /etc/ 下
要给需要自拉起的程序添加配置文件 默认放在 /etc/supervisor.d/ 目录下,以 .conf 文件结尾
测试程序为 test.conf
[program:test]
command=/home/jingchanglin/code/test/test
autostart=true
autorestart=true
startsecs=
priority=
redirect_stderr=true
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=
stdout_logfile=/home/jingchanglin/code/test/app.log
服务启动后,可以使用 supervisorctl 命令来进入控制台
[root@localhost]# supervisorctl
sshd RUNNING pid , uptime ::
test RUNNING pid , uptime ::
supervisor> help default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version supervisor>
进入之后,看到的是在监控的程序的名称
使用 help 可以看服务支持哪些自命令
一般常用的包括
reload
重新加载,这样某个新添/删除的服务就可以看到了
shutdown 关闭某个程序
start 启动某个程序
最新文章
- python-phpbb3 (可以用python3 操作 phpbb3 论坛的模块)
- 每次点击按钮后,判断页面是否已经有该行,没有弹出repeater的一行,并给他赋一个这行附值,没有则跳出
- C语言程序代写
- Maven 如何为不同的环境打包 —— 开发、测试和生产环境
- 利用SecondaryNameNode文件恢复Namenode-实践可行
- 【递推】BZOJ 1088: [SCOI2005]扫雷Mine
- IPTV小窗口播放视频 页面焦点无法移动的解决方法
- Android文本Flood it游戏源代码
- AntData.ORM框架 之DBModel CodeGen如何使用
- bzoj 5212: [Zjoi2018]历史
- mybatis自动生成
- 文件比较与同步工具——FreeFileSync
- bat(批处理)命令(tomcat 7.0.75 startup.bat 命令集)
- 前端学习之CSS
- Python语言说明
- bzoj1565: [NOI2009]植物大战僵尸 最大权闭合子图,tarjan
- AngularJS路由系列(3)-- UI-Router初体验
- Thymeleaf模板引擎的初步使用
- collections之deque【双向队列】与Queue【单向队列】
- 動態修改 XML 欄位
热门文章
- 【C#第一天】数据相关
- Tomcat关闭失败,SEVERE: Could not contact localhost:8005. Tomcat may not be running.
- Linux中普通用户配置sudo权限(带密或免密)
- sqlserver 获取汉字拼音的首字母(大写)函数
- Spring中@Component注解,@Controller注解详解
- idea的一些设置
- 使用gethostname()函数和gethostbyname()函数获取主机相关信息
- P4391 [BOI2009]Radio Transmission 无线传输(KMP)
- 四丶前端基础之jquery
- OPPO A3在哪里打开usb调试模式的详细教程