.netcore web应用在linux上如何自动重启
首先创建一个启动脚本命名为netcore.servic,放到/etc/systemd/system目录下,修改对应的app目录和 启动命令即可
Type=simple # app的目录 WorkingDirectory=/www/publish # 启动命令 ExecStart=/usr/bin/dotnet Web.App.dll Restart=always StandardOutput=journal StandardError=journal # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dotnet-example User=root Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
这个脚本只具有启动应用的能力,没有停止和重启的功能,所以要再写一个脚本停止并启动应用
#!/bin/sh app_dir="/www/publish" pid=`ps -ef | grep ‘Web.App.dll‘ | grep -v grep |awk ‘{print $2}‘` echo $pid #kill process while [ "#$pid" != "#" ];do echo "kill $pid" kill -9 $pid sleep 1s pid=`ps -ef | grep ‘Web.App.dll‘ | grep -v grep |awk ‘{print $2}‘` done #start process sleep 5s systemctl start netcore.service
最后创建任务计划即可(每天零点重启)
crontab -e * 0 * * * /opt/script/app_restart.sh
重启crond服务
systemctl restart crond
相关推荐
playlinuxxx 2020-11-11
farwang 2020-11-25
星愿心愿 2020-11-24
tianhuak 2020-11-24
zhjn0 2020-11-24
昭君出塞 2020-11-23
bluecarrot 2020-11-23
linuxwcj 2020-10-21
以梦为马不负韶华 2020-10-20
彼岸随笔 2020-10-20
yutou0 2020-10-17
applecarelte 2020-10-16
ourtimes 2020-10-16
waterhorse 2020-09-19
MRFENGG 2020-11-11
rainandtear 2020-10-30
kyssfanhui 2020-10-20