Supervisor守护进程虚拟环境部署Django

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Supervisor守护进程虚拟环境部署Django相关的知识,希望对你有一定的参考价值。

参考技术A 解决unix:///tmp/supervisor.sock no such file的问题1
解决unix:///tmp/supervisor.sock no such file的问题2
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting

Ubuntu中通过SuperVisor添加守护进程

1. 用途

守护进程用于保持一个指定程序(dll)时刻保持运行。在命令行终端中通过dotnet run命令执行的程序,在退出命令行终端后,程序自动终止。添加守护进程后,即使终端退出,程序仍可后台执行。可用于执行定时任务。

2. 安装(环境:ubuntu 16.04 dotnet 2.1.104)

sudo apt-get install supervisor  (必须在root下执行)

3. 修改配置文件

配置文件路径:/ect/supervisor/conf.d/supervisord.conf

直接修改该文件

gedit supervisord.conf

增加:

1)开启查看进程的界面

[inet_http_server]
port=127.0.0.1:7002

2)添加被守护的程序

[program:TimeTest]
command=dotnet TimeTest.dll   ;要执行的指令
directory=/mnt/hgfs/Projects/Linux/SurfaceRunoff/TimeTest/TimeTest/bin/Debug/netcoreapp2.0/publish        ;dll的路径
autostart=true
autorestart=true
numprocs=1
process_name=TimeTests        ;名称

3)重启

supervisord reload

4)访问localhost:7002(与配置文件中的端口相同)即可查看当前正在运行的所有程序

 

配置文件完整示例:

; supervisor config file

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

[inet_http_server]
port=127.0.0.1:7002

[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.

[program:TimeTest]
command=dotnet TimeTest.dll
directory=/mnt/hgfs/Projects/Linux/SurfaceRunoff/TimeTest/TimeTest/bin/Debug/netcoreapp2.0/publish
autostart=true
autorestart=true
numprocs=1
process_name=TimeTests

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

 

4. 参考:

https://www.cnblogs.com/savorboard/p/dotnetcore-supervisor.html(给出的配置文件设置方法似乎有问题,添加后无法通过浏览器进行查看,也可能是版本问题,未再深究)

https://www.cnblogs.com/dingsblog/p/7040680.html(后来按这篇帖子完成配置文件修改)

 

以上是关于Supervisor守护进程虚拟环境部署Django的主要内容,如果未能解决你的问题,请参考以下文章

CentOS/Linux 部署.NET5.0 Blazor到ngnix并用supervisor守护进程

Supervisor 为服务创建守护进程

nginx通过Supervisor实现守护进程

进程守护Supervisor系列一:安装与配置

Ubuntu中通过SuperVisor添加守护进程

ansible+Jenkins+supervisor(Jenkins守护进程)