使用 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 启动某个程序

最新文章

  1. python-phpbb3 (可以用python3 操作 phpbb3 论坛的模块)
  2. 每次点击按钮后,判断页面是否已经有该行,没有弹出repeater的一行,并给他赋一个这行附值,没有则跳出
  3. C语言程序代写
  4. Maven 如何为不同的环境打包 —— 开发、测试和生产环境
  5. 利用SecondaryNameNode文件恢复Namenode-实践可行
  6. 【递推】BZOJ 1088: [SCOI2005]扫雷Mine
  7. IPTV小窗口播放视频 页面焦点无法移动的解决方法
  8. Android文本Flood it游戏源代码
  9. AntData.ORM框架 之DBModel CodeGen如何使用
  10. bzoj 5212: [Zjoi2018]历史
  11. mybatis自动生成
  12. 文件比较与同步工具——FreeFileSync
  13. bat(批处理)命令(tomcat 7.0.75 startup.bat 命令集)
  14. 前端学习之CSS
  15. Python语言说明
  16. bzoj1565: [NOI2009]植物大战僵尸 最大权闭合子图,tarjan
  17. AngularJS路由系列(3)-- UI-Router初体验
  18. Thymeleaf模板引擎的初步使用
  19. collections之deque【双向队列】与Queue【单向队列】
  20. 動態修改 XML 欄位

热门文章

  1. 【C#第一天】数据相关
  2. Tomcat关闭失败,SEVERE: Could not contact localhost:8005. Tomcat may not be running.
  3. Linux中普通用户配置sudo权限(带密或免密)
  4. sqlserver 获取汉字拼音的首字母(大写)函数
  5. Spring中@Component注解,@Controller注解详解
  6. idea的一些设置
  7. 使用gethostname()函数和gethostbyname()函数获取主机相关信息
  8. P4391 [BOI2009]Radio Transmission 无线传输(KMP)
  9. 四丶前端基础之jquery
  10. OPPO A3在哪里打开usb调试模式的详细教程