场景:当部署完.netcore程序后 使用dotnet xx.dll 后可以运行,但关闭shell或隔断时间会自动断开,此时部署的.netcore程序就不能访问了,此时需要用到Supervisor了

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

1、安装Python

yum install python-setuptools
easy_install supervisor

2、新建supervisor文件夹

mkdir /etc/supervisor

3、在该目录下,生成supervisord.conf文件

echo_supervisord_conf > /etc/supervisor/supervisord.conf

4、新建conf.d文件夹

mkdir /etc/supervisor/conf.d

此时的目录结构:

5、编辑supervisord.conf文件,在文件中末尾添加

[include]
files=conf.d/*.conf

6、在conf.d中添加文件test.conf

文件内容:

[program:testservice] ;程序名称,终端控制时需要的标识
command=dotnet test2.dll ; 运行程序的命令
directory=/home/website/test/ ; 命令执行的目录
autorestart=true ; 程序意外退出是否自动重启
stderr_logfile=/var/log/testservice.err.log ; 错误日志文件
stdout_logfile=/var/log/testservice.out.log ; 输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量
user=root ; 进程执行的用户身份
stopsignal=INT
startsecs=1 ; 自动重启间隔

7、指定supervisor配置文件

supervisord -c /etc/supervisor/supervisord.conf

8、Supervisor开机自启动

在目录/usr/lib/systemd/system 中新建文件supervisord.service

文件内容:

#supervisord.service

[Unit]
Description=Supervisor daemon [Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s [Install]
WantedBy=multi-user.target

9、使配置生效

systemctl daemon-reload

重启supervisor服务
   $ supervisorctl reread
   如果重启的时候报错: 
   error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.6/socket.py line: 567
   则说明服务尚未启动,先启动即可:
   sudo supervisord -c /etc/supervisor/supervisord.conf
   sudo supervisorctl -c /etc/supervisor/supervisord.conf
   如果修改了 /etc/supervisord.conf ,需要执行 supervisorctl reload 来重新加载配置文件,否则不会生效。

10、设置服务开机启动

systemctl enable supervisor.service

11、验证一下是否为开机启动

systemctl is-enabled supervisord

12、启动服务

systemctl start supervisor.service

至此完成

参考文章:

https://www.cnblogs.com/hobinly/p/7382038.html

https://my.oschina.net/lichaoqiang/blog/1861791

https://www.cnblogs.com/sundahua/p/9149692.html

https://blog.csdn.net/chivalrousli/article/details/60324140

linux centos Supervisor守护.netcore进程安装配置的更多相关文章

  1. .Net Core 项目发布到Linux - CentOS 7(二)用Supervisor守护netcore进程

    简介 supervisor可以保证程序崩溃后,可以重新把程序启动起来等相关功能. 安装 yum install -y supervisor 安装好后在/etc/会生成一个supervisord.con ...

  2. 在Linux(CentOS 6.6)服务器上安装并配置基于Apache的SVN服务器

    #!/bin/bash # # 在Linux(CentOS 6.6)服务器上安装并配置基于Apache的SVN服务器: # # .安装服务 # .创建svn版本库 # .创建svn用户 # .配置sv ...

  3. Linux(CentOS 7)命令行模式安装VMware Tools 详解

    本篇文章主要介绍了如何在Linux(CentOS 7)命令行模式安装VMware Tools,具有一定的参考价值,感兴趣的小伙伴们可以参考一下. 本例中为在Linux(以CentOS 7为例)安装VM ...

  4. CentOS 6.3下NFS安装配置

    CentOS 6.3下NFS安装配置 一.环境介绍   NFS服务器:CentOS6.3 192.168.8.20 NFS客户端:CentOS6.5 192.168.8.39 二.服务器端安装配置   ...

  5. CentOS 6.8 ftp服务安装配置 基于本地用户和虚拟用户

    CentOS 6.8 ftp服务安装配置 基于本地用户和虚拟用户 一.安装ftp服务 1.检查是否已经安装 # rpm -qa | grep ftp ftp-0.17-54.el6.x86_64 vs ...

  6. 【转载】基于Linux命令行KVM虚拟机的安装配置与基本使用

    基于Linux命令行KVM虚拟机的安装配置与基本使用 https://alex0227.github.io/2018/06/06/%E5%9F%BA%E4%BA%8ELinux%E5%91%BD%E4 ...

  7. Linux CentOS 7 & JDK 1.7 安装与配置

    前言 简单记录一下在CentOS 7中安装配置JDK 1.7的全过程~ 下载 首先是jdk 1.7 64bit & 32bit的下载地址: jdk-7u79-linux-x64.tar.gz ...

  8. CentOS 6.3 NFS的安装配置、启动及mount挂载方法

    一.环境介绍: 服务器:centos 192.168.1.225 客户端:centos 192.168.1.226 二.安装: NFS的安装配置: centos 5 : yum -y install ...

  9. 阿里云服务器CentOS 5.7(64位)安装配置LAMP服务器(Apache+PHP5+MySQL)

    一.快速安装Apache+PHP5+MySql ----------------------------------------------------- 补充:由于163的yum源上只有php5.1 ...

随机推荐

  1. 三个线程abc顺序执行

    1.使用synchronized悲观锁(秋招阿里的一个笔试题,应该写的比较复杂,然后就没有然后了o(╥﹏╥)o) public class ThreadThreadp { private int fl ...

  2. 【Leetcode_easy】748. Shortest Completing Word

    problem 748. Shortest Completing Word 题意: solution1: class Solution { public: string shortestComplet ...

  3. 比较SSO协议: WS-Fed, SAML, and OAuth

    真实比喻 在我们获得技术之前,让我们用完全非技术性的东西来解决这个问题.作为工程师,我们非常注重将事情分解为组件和流程.这有助于我们了解事情,以便我们可以排除故障或构建复杂的系统.当你去机场登机时,你 ...

  4. Python3之类和实例访问限制

    在Class内部,可以有属性和方法,而外部代码可以通过直接调用实例变量的方法来操作数据,这样,就隐藏了内部的复杂逻辑. 但是,从前面的Student类定义来看,外部代码还是可以自由地修改一个实例的na ...

  5. java基本思想

    面向对象 众所周知,面向对象编程思想是java的基本思想.java的整个体系和技术实现都是以这个思想为基础.(这个通过类和接口能看出来,后面提到) 对这个事情的认知度甚至变成了很多公司的面试标准.比如 ...

  6. 解决电脑开机连不上网问题(Windows检测:远程计算机或设备将不接受连接)

    打开Google Chrome浏览器  -----> 设置 ------> 高级设置 -----> 打开代理设置 -----> 连接 -----> 局域网设置 ----& ...

  7. mysql 按照配置文件启动

      有时,我们的机器上面装了很多个mysql,但只有一个3306端口,其余的mysql服务器需要重新指定端口.我们需要多个配置文件来启动它们.那么我们怎么通过指定配置文件的方式来启动呢?   例如,按 ...

  8. Servlet技术之——概述、实现、细节、获取资源、ServletConfig、ServletContext

    Servlet概述.实现.细节.获取资源.ServletConfig.ServletContext (一) Setvlet基本概述 (1) 什么是Servlet ? Servlet(Server Ap ...

  9. Openssl 加解密文件

    使用openssl 的命令行进行文件的加密与解密过程,主要有两种方式: openssl 指定加密/解密算法加密 openssl 指定公钥/私钥文件加密 openssl 指定加密/解密算法加密 To E ...

  10. 【ZOJ】4012 Your Bridge is under Attack

    [ZOJ]4012 Your Bridge is under Attack 平面上随机n个点,然后给出m条直线,问直线上有几个点 \(n,m \leq 10^{5}\) 由于共线的点不会太多,于是我们 ...