Windows configuration uses supervisor

Tip: After the article is written, the table of contents can be automatically generated. For how to generate it, please refer to the help document on the right.


Preface

Using supervisor in Windows is slightly different from that in Linux. Strictly speaking, it is slightly more difficult than Linux, and not all features are supported.


1. Usage steps

1.Install supervisor-win

In fact, there is a pure exe version of supervisor, but it is less functional than the python version in actual use. Therefore, after comparison, supervisor-win is more cost-effective.

It is recommended to use anaconda3, because this article is based on anaconda3, please find the native python directory by yourself, and I will not go into details here.

pip install supervisor-win -i https://mirrors.aliyun.com/pypi/simple

After the installation is complete, there is an exe file under Scripts in anaconda. What is used is a few exes enclosed in red boxes.
Insert image description here

2. Configure supervisord

Anyone who has used Linux knows that /etc/supervisor.conf is a configuration file, and the configuration file on Windows needs to be generated with commands.

echo_supervisord_conf.exe > D:\supervisord.conf

You can specify a directory, not necessarily the D drive.

3.Configure program

Just fill it out directly in supervisord.conf. Here is an example conf:

[program:theprogramname]
command=cmd.exe               ; the program (relative uses PATH, can take args)
directory=%(ENV_TMP)s         ; directory to cwd to before exec (def no cwd)
autostart=true                ; start at supervisord start (default: true)
startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
startretries=3                ; max # of serial start failures when starting (default 3)
autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=a\\path        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)

在supervisord.conf里面 ; 符号是行注释的意思,去掉行注释,这一行就会被supervidord.exe解析。

Field explanation:
[program:theprogramname]: Fixed writing method, theprogramname is the program name, in English.
command: the command that needs to be executed, it is recommended to use 绝对路径, and it must be the Linux type 正斜杠 / 分割目录
directory: working directory stdout_logfile_backups: The maximum number of log files to keep stdout_logfile_maxbytes: The maximum space of a single file exceeds the size of another file stdout_logfile: standard output directory, can be a backslash. redirect_stderr: Redirect the standard error log output to the standard output, or output it separately , according to preference. autorestart: Automatically restart, effective if the program exits unexpectedly (keep-alive function) startretries: Number of failed startup attempts startsecs: The program needs to last for at least 1 second before it is considered successful.
autostart: Automatically start, enabled by default




目录一定要存在,否则报错。

4. Start supervisord.exe

After configuration, you can control the program. All tested exe programs can be controlled,有些bat报错,还在研究原因.

Before that, you need to change two places in supervisord.conf so that supervisorctl.exe can work normally. Yes, supervisorctl.exe and supervisord.exe are connected through the network.

#默认的配置
;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

#改为
[inet_http_server]         ; inet (TCP) server disabled by default
port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

If a username and password are required, uncomment the username and password.

#默认配置
[supervisorctl]
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

#改为
[supervisorctl]
serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

If a username and password are required, uncomment the username and password.

In this way, the basic configuration is basically completed, and other functions need to be configured by yourself.

Start supervisord.exe to control the program

‪D:\conda\envs\supervisord\Scripts\supervisorctl.exe -c D:\conda\envs\supervisord\Scripts\supervisord.conf

这种启动方式是前台启动,cmd关掉就没了。

5.supervisorctl.exe control

#重新加载,修改了supervisord.conf必须reload
D:\conda\envs\supervisord\Scripts\supervisorctl.exe reload

#查看状态
D:\conda\envs\supervisord\Scripts\supervisorctl.exe status

#启动程序
D:\conda\envs\supervisord\Scripts\supervisorctl.exe start <program name>

#停止程序
D:\conda\envs\supervisord\Scripts\supervisorctl.exe stop <program name>

I won’t introduce much here, it’s basically the same as Linux.

2. Background startup

There are several methods, here is a vbs method

supervisord.vbs

Set ws = CreateObject("Wscript.Shell")
ws.run "D:\Work\Anaconda\envs\supervisord\Scripts\supervisord.exe -c D:\conda\envs\supervisord\Scripts\supervisord.conf",vbhide

Double-click supervisord.vbs, supervisord.exe will be started in the background, and you can use supervisorctl.exe to control it after analysis.


Summarize

1. It is slightly worse than the one on Linux, but it has the basic functions and can meet the needs of use.

Guess you like

Origin blog.csdn.net/jiexijihe945/article/details/134716094