.netcore程序发布到linux然后执行dotnet xxx.dll,如果退出shell终端,程序也会跟着退出,则需要使用supervisor来守护
环境centos7,.netcore3.1
1,安装supervisor
yum install supervisor
2,设置开启启动
systemctl enable supervisord.service
3,生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
打开配置文件找到最后两行改为如下:
[include]
files = /etc/supervisord.d/*.ini
ps:supervisor会对/etc/supervisord.d/目录下的所有.ini文件起作用
4,在/etc/supervisord.d/目录添加api.ini文件如下:
[program:api] command=dotnet xxx.dll directory=/root/web/api environment=ASPNETCORE__ENVIRONMENT=Production user=root stopsignal=INT autostart=true autorestart=true startsecs=3 stderr_logfile=/root/web/api/err.log stdout_logfile=/root/web/api/out.log
5,启动
supervisord -c /etc/supervisord.conf
6,查看运行状态
supervisorctl -c /etc/supervisord.conf
ps:supervisor可以用来守护redis和nginx
nginx.ini仅供参考:
[program:nginx] command= /root/nginx/sbin/nginx -g 'daemon off;' environment=ASPNETCORE__ENVIRONMENT=Production user=root stopsignal=INT autostart=true autorestart=true startsecs=3 stderr_logfile=/root/nginx/sbin/err.log stdout_logfile=/root/nginx/sbin/out.log
redis.ini仅供参考:
[program:redis] command=/root/redis/src/redis-server /root/redis/redis.conf environment=ASPNETCORE__ENVIRONMENT=Production user=root stopsignal=INT autostart=true autorestart=true startsecs=3 stderr_logfile=/root/redis/src/err.log stdout_logfile=/root/redis/src/out.log