zoukankan      html  css  js  c++  java
  • .Net core 守护进程配置(supervisor)

    1、介绍supervisor

    Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。

    2、安装环境

    # 安装 python环境
    yum install python-setuptools
    # 安装 Supervisor
    easy_install supervisor
    

    3、配置Supervisor

    # 新建配置目录命令:
    mkdir /etc/supervisor
    #生成supervisor的初始化配置文件 :
    echo_supervisord_conf > /etc/supervisor/supervisord.conf
    

    编辑配置supervisord.conf

    vim supervisord.conf 
    

    主要是打开网络访问、默认启动配置目录

    # 创建配置目录
    mkdir /etc/supervisor/conf.d
    # 进入目录
    cd conf.d
    
    #创建一个WebApplication1.conf配置
    vi WebApplication1.conf
    # 创建程序启动配置
    # 进程名称
    [program:WebApplication1] 
    # 执行命令
    command=dotnet WebApplication1.dll
    # 执行目录
    directory=/root/aspnetcoreapi
    # 掉线是否自动重启
    autorestart=true
    # 日志信息
    stderr_logfile=/var/log/WebApplication1.err.log
    stdout_logfile=/var/log/WebApplication1.out.log
    # 环境.Net core
    environment=ASPNETCORE_ENVIRONMENT=Production
    # 执行用户
    user=root
    stopsignal=INT
    

    4、启动Supervisor

    # 启动Supervisor
    supervisord -c /etc/supervisor/supervisord.conf
    #查看状态
    supervisorctl status
    

    5、bash终端控制

    #启动Supervisor
    supervisord -c /etc/supervisor/supervisord.conf
    # 查看状态
    supervisorctl status
    # 停止某个服务
    supervisorctl stop WebApplication1
    # 开始某个服务
    supervisorctl start WebApplication1
    # 重启某个服务
    supervisorctl restart WebApplication1
    # 重启Supervisor
    supervisorctl reload
    # 修改Supervisor
    supervisorctl update
    

    6、将supervisor配置为开机自启动服务

    # 编辑服务文件
    vim /usr/lib/systemd/system/supervisord.service
    # 内容
    [Unit]
    Description=Supervisor
    [Service]
    Type=forking
    PIDFile=/var/run/supervisord.pid
    ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
    ExecStop=/usr/bin/supervisorctl shutdown
    ExecReload=/usr/bin/supervisorctl reload
    KillMode=process
    Restart=on-failure
    RestartSec=42s
    [Install]
    WantedBy=multi-user.target
    # 保存退出 启动服务
    systemctl enable supervisord
    # 查看启动状态  返回enabled成功
    systemctl is-enabled supervisord
    
    #成功之后,就可以使用如下命令管理supervisor服务了
    # 停止
    systemctl stop supervisord
    # 启动
    systemctl start supervisord
    # 状态
    systemctl status supervisord
    # 重载
    systemctl reload supervisord
    # 重启
    systemctl restart supervisord
    

    我们最后也可以看到我们将进程杀死之后马上会启动一个新的进程启动程序

    最后我们可以通过我们配置的网络地址访问了,可以看到所有的程序方便管理

  • 相关阅读:
    POJ 1611
    [Erlang24]使用zotonic搭建网站记录
    [Erlang23]怎么有效的遍历ETS表?
    [Erlang22]如何按规则位数输出数字
    [Git00] Pro Git 一二章读书笔记
    十分钟用HTML&CSS让博客园变得高大上
    [Erlang21]Erlang性能分析工具eprof fporf的应用
    [Erlang20]一起攻克Binary
    [Erlang19]Erlang的config文件读取效率问题
    [Erlang18]教练!又发现Erlang Shell里面的神奇函数一只
  • 原文地址:https://www.cnblogs.com/chenxi001/p/13614831.html
Copyright © 2011-2022 走看看