<h2></h2>
<h2></h2>
<h2>1.安装supervisor</h2>
<span class="hljs-meta">#</span><span class="bash">pip </span>
pip install supervisor
<span class="hljs-meta">
#</span><span class="bash">ubuntu </span>
sudo apt-get install supervisor
<span class="hljs-meta">
#</span><span class="bash">centos (可能需要先安装epel源) </span>
yum install epel-release
yum -y install supervisor
<div data-unique="2.启动"></div>
<h2>2.启动</h2>
安装完后如supervisor没启动,可以使用如下,手动启动
<span class="hljs-meta">#</span><span class="bash">启动supervisor </span>
/usr/bin/supervisord -c /etc/supervisord.conf
或者
supervisord -c /etc/supervisord.conf
进入 cd /etc 目录 找到supervisord.conf 配置文件和supervisord.d 文件夹,编辑supervisord.conf文件,拉到最底部我们可以看到
files = supervisord.d/*.ini 这句代码说明它会加载supervisord.d文件夹中的所有.ini配置文件
<h2>3.添加开机自启动</h2>
<span class="hljs-comment">#创建supervisord.service </span>
<span class="hljs-attribute">vi</span> /usr/lib/systemd/system/supervisord.service
<span class="hljs-comment">#supervisord.service文件内容 </span>
[Unit]
Description=Supervisor
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl <span class="hljs-variable">$OPTIONS</span> shutdown
ExecReload=/usr/bin/supervisorctl <span class="hljs-variable">$OPTIONS</span> reload
KillMode=process
Restart=<span class="hljs-literal">on</span>-failure
RestartSec=<span class="hljs-number">42s</span>
[Install]
WantedBy=multi-user.target
激活开机启动
<span class="hljs-meta">#</span><span class="bash">激活开机启动 </span>
systemctl enable supervisord.service
<span class="hljs-meta">
#</span><span class="bash">如修改了supervisord.service配置文件需重新加载 </span>
systemctl daemon-reload
各种开机自启动脚本:https://github.com/Supervisor/initscripts
<div data-unique="4.创建一个配置文件"></div>
<h2>4.创建一个配置文件</h2>
[<span class="hljs-meta">program:DeployLinux</span>] <span class="hljs-meta">#DeployLinux 为程序的名称</span>
command=dotnet DeployLinux.dll <span class="hljs-meta">#需要执行的命令</span>
directory=/home/publish <span class="hljs-meta">#命令执行的目录</span>
environment=ASPNETCORE__ENVIRONMENT=Production <span class="hljs-meta">#环境变量</span>
user=root <span class="hljs-meta">#用户</span>
stopsignal=INT
autostart=<span class="hljs-literal">true</span> <span class="hljs-meta">#是否自启动</span>
autorestart=<span class="hljs-literal">true</span> <span class="hljs-meta">#是否自动重启</span>
startsecs=<span class="hljs-number">3</span> <span class="hljs-meta">#自动重启时间间隔(s)</span>
stderr_logfile=/<span class="hljs-keyword">var</span>/log/ossoffical.err.log <span class="hljs-meta">#错误日志文件</span>
stdout_logfile=/<span class="hljs-keyword">var</span>/log/ossoffical.<span class="hljs-keyword">out</span>.log <span class="hljs-meta">#输出日志文件</span>
<span class="hljs-meta">#</span><span class="bash">加载配置文件 </span>
supervisorctl reread
<span class="hljs-meta">
</span><span class="bash">启动spring-app </span>
supervisorctl start spring-app
<span class="hljs-meta">
</span><span class="bash">查看进程状态 </span>
supervisorctl status
<h3>遇到的问题</h3>
添加要启动的程序配置文件后supervisor无法再启动,用systemctl status supervisor 命令查看状态发现有错误。
把添加的程序配置文件删除后再启动 supervisor可以正常启动,这样问题就是出现在了所添加的程序配置文件上。
比较奇怪的的是配置文件和另一台一样也会报错,需要把配置文件里面的一行命令删除后才正常。好奇怪,也不知道为什么。