Ubuntu20.04 安装、配置supervisor

2021-03-23  乐帮网

ubuntu supervisor

在Ubuntu上安装 supervisor只需要一行命令就可以了,在联网的状态下,命令行如下(注意本篇所有命令默认都是在root账号下运行):
 

apt install supervisor

等待安装完成后需要进行一些配置,首先你需要知道它默认的配置文件路径,默认如下,可使用cat进行查看

root # cat /etc/supervisor/supervisord.conf 发现内容如下:

; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

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

最后一行是配置的加载路径。我们只需要把要守护的进程配置信息放到这个目录就可以了/etc/supervisor/conf.d/ 后缀是.conf

下面加一下.Net Core的配置信息文件名称 netcoredemo.conf内容如下:

[program:netcore.demo.mvcweb] 
command=/bin/bash -c "dotnet netcore.demo.mvcweb.dll"
directory=/www/demoweb/
stderr_logfile=/tmp/netcore.demo.mvcweb.error.log
stdout_logfile=/tmp/netcore.demo.mvcweb.stdout.log
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3

此时我们重新加载 supervisor 配置

systemctl reload supervisor

发现网站就能正常访问了。

以下是总结的小技巧
我是通过查看服务service  --status-all 来找到这个服务名称:supervisor 的。
如何你找不到supervisor服务可以使用如下命令注册服务 systemctl enable supervisor
同理卸载服务就是 systemctl disable supervisor

开启服务: systemctl start supervisor 
停止服务:systemctl stop supervisor
查看状态:systemctl status supervisor
重新加载:systemctl reload supervisor
重启服务:systemctl restart supervisor

相信你能用得着。以下启用进程的配置说明

[program:netcore.demo.mvcweb] #自己随便起名 但进程名称需要唯一
command=/bin/bash -c "dotnet netcore.demo.mvcweb.dll"  #程序的入口  .Net Core站点就是一条启动命令
directory=/www/demoweb/ #上述命令的运行目录 
stderr_logfile=/tmp/netcore.demo.mvcweb.error.log  #进程错误日志目录
stdout_logfile=/tmp/netcore.demo.mvcweb.stdout.log  #进程输出日志目录
environment=ASPNETCORE_ENVIRONMENT=Production  #进程环境变量
user=root #启动进程的用户
stopsignal=INT #收到此信号后会杀死该进程 可省略
autostart=true  #是否自动启动
autorestart=true #是否自动重启
startsecs=5 #启动 5 秒后没有异常退出,就当作已经正常启动了
priority=999 #优先级

lebang2020.cn :https://lebang2020.cn/details/210323w1i4tstv.html

公众号二维码

关注我的微信公众号
在公众号里留言交流
投稿邮箱:1052839972@qq.com

庭院深深深几许?杨柳堆烟,帘幕无重数。
玉勒雕鞍游冶处,楼高不见章台路。
雨横风狂三月暮。门掩黄昏,无计留春住。
泪眼问花花不语,乱红飞过秋千去。

欧阳修

付款二维码

如果感觉对您有帮助
欢迎向作者提供捐赠
这将是创作的最大动力