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

supervisor 配置程序挂起自启动的更多相关文章

  1. 【netcore基础】ubuntu 16.04 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动

    今天来整理下 netcore 在 linux(ubuntu) 上的运行环境搭建 对应版本 ubuntu 16.04 .net core 2.1 nginx version: nginx/1.10.3 ...

  2. 【netcore基础】CentOS 7.6.1810 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动

    之前写过一篇Ubuntu的环境搭建博客,感觉一些配置大同小异,这里重点记录下 nginx 作为静态 angular 项目文件服务器的配置 参考链接 [netcore基础]ubuntu 16.04 搭建 ...

  3. Robotium调用getActivity()导致程序挂起的方法

    1. 问题背景的叙述性说明 需要直接用在工作中没有项目的源代码robotium测试目标android平台launcher,该平台的基础上,当前日期的版本号android 4.4.2.之前我用来验证的可 ...

  4. 配置程序成为Linux服务

    最近写了个程序需要随Linux启动时自动运行起来, 查了一些方法后, 通过配置程序成为系统的服务实现了这个需求, 在此记录一下. 测试程序 #! /bin/sh while [ true ] do e ...

  5. Supervisor 配置过程

    Supervisor 配置过程 (转自https://www.izixia.cn/2016/01/03/supervisor-pei-zhi-guo-cheng/) 1.安装 pip install ...

  6. centos系统supervisor配置

    supervisor用来管理非daemon程序!将自动转换为daemon程序 安装: yum install supervisor 配置: 默认配置文件路径: /etc/supervisord.con ...

  7. .Net Core实战教程(三):使用Supervisor配置守护进程

    安装Supervisor yum install python-setuptools easy_install supervisor 配置Supervisor mkdir /etc/superviso ...

  8. 正尝试在 OS 载入程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内执行托管代码,这样做会导致应用程序挂起。

    出错提示: 正尝试在 OS 载入程序锁内执行托管代码. 不要尝试在 DllMain 或映像初始化函数内执行托管代码,这样做会导致应用程序挂起. 原因分析: .NET2.0中添加了42种非常强大的调试助 ...

  9. AppDelegate关于应用程序挂起、复原与终止的代理方法

    AppDelegate关于应用程序挂起.复原与终止的代理方法: 首次运行: - (BOOL)application:(UIApplication *)application didFinishLaun ...

随机推荐

  1. HBase基本概念与基本使用

    1. HBase简介 1.1 什么是HBase HBASE是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBASE技术可在廉价PC Server上搭建起大规模结构化存储集群. HBASE ...

  2. 轻量Pythonweb - flask+jinja2

    后台代码 MVC from flask import Flask,request,render_template app = Flask(__name__) @app.route('/',method ...

  3. 轻型Database- sqlite入门

    SQLite 是一个软件库,实现了自给自足的.无服务器的.零配置的.事务性的 SQL 数据库引擎.SQLite 是在世界上最广泛部署的 SQL 数据库引擎.SQLite 源代码不受版权限制. 下面跟着 ...

  4. (Python3) 求中位数 代码

    def zhongweishu(a): new=sorted(a) if len(a)%2==0: s=(new[int(len(a)/2-1)]+new[int(len(a)/2)])/2 else ...

  5. mysql,mycat的demo

    一直都是使用公司架构师提供的mycat,今天得空自己尝试了以下: 1.首先安装jdk(官网建议1.7及以上版本),mysql(我安装的是5.7.19-0ubuntu0.16.04.1,设置账号密码为r ...

  6. C++编译/运行过程中产生的各种文件

    参考:https://blog.csdn.net/weixin_39609623/article/details/82348576 Windows中的obj,lib,dll,exe文件 lib是和dl ...

  7. JavaWeb处理GET、POST时的编码乱码问题

    对于GET方法,只要设置了res.setContentType("text/html;charset=UTF-8"), req.getParameter()就不会产生乱码. 对于P ...

  8. Kafka安装配置

    Kafka是由Apache软件基金会开发的一个高吞吐量的分布式发布订阅消息系统,由Scala和Java编写.官网地址:http://kafka.apache.org 0.基本概念 Broker:Kaf ...

  9. 417 事件、监听、jQuery、轮播手动

    am:通用事件 a链接事件阻止默认行为 return false HTML元素大都包含了自己的默认行为,例如:超链接.提交按钮等.我们可以通过在绑定事件中加上return false来阻止它的默认行为 ...

  10. [经验交流] 试用 grafana 报警功能

    1. grafana 概述 grafana 是一款优秀的数据展示工具,几乎是各类时序数据库的前端标配系统.grafana 在V4版本中已经加入了报警功能. 2. influxdb 概述 influxd ...