zoukankan      html  css  js  c++  java
  • supervisor 配置程序挂起自启动

    使用 supervisor 服务,将程序监控起来,如果程序挂掉了,可以实现自启动

    编写 c++ 程序 test.c

    #include <stdio.h>
    #include <string.h>
    
    int main(){
            FILE *fp = fopen("./1.txt","a+");
            if(fp==0){
                    printf("can't open file
    ");
                    return 0;
            }
    
            int ix = 0;
            for(;;ix++){
                    fseek(fp,0,SEEK_END);
                    char s_add_arr[10];
                    memset(s_add_arr,'',10);
                    sprintf(s_add_arr,"%i
    ",ix);
                    fwrite(s_add_arr,strlen(s_add_arr),1,fp);
    
                    sleep(1);
            }
            fclose(fp);
            return 0;
    }

    启动服务

    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=10
    priority=1
    redirect_stderr=true
    stdout_logfile_maxbytes=50MB
    stdout_logfile_backups=10
    stdout_logfile=/home/jingchanglin/code/test/app.log

    服务启动后,可以使用 supervisorctl 命令来进入控制台

    [root@localhost]# supervisorctl
    sshd                             RUNNING   pid 28606, uptime 0:02:42
    test                             RUNNING   pid 28605, uptime 0:02:42
    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 启动某个程序

  • 相关阅读:
    git 回滚到某个历史版本
    java值传递与引用传递
    Spring的事务管理
    MySql安装详细图解 以及卸载不干净解决方法
    如果你决定要出发,那么旅行中最困难的部分已经结束,出发吧!
    微信小程序总是提醒安装X5内核
    使用vuerouter实现返回
    手机上测试
    H5移动端知识点总结
    微信小程序授权问题
  • 原文地址:https://www.cnblogs.com/oftenlin/p/9479553.html
Copyright © 2011-2022 走看看