惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
F
Full Disclosure
博客园 - 【当耐特】
博客园 - 司徒正美
V
Visual Studio Blog
F
Fortinet All Blogs
T
Tor Project blog
T
Threatpost
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
C
Cyber Attacks, Cyber Crime and Cyber Security
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
M
MIT News - Artificial intelligence
L
Lohrmann on Cybersecurity
P
Palo Alto Networks Blog
I
Intezer
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
The Last Watchdog
The Last Watchdog
S
Securelist
T
Tailwind CSS Blog
V
Vulnerabilities – Threatpost
U
Unit 42
博客园 - 叶小钗
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
SecWiki News
SecWiki News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Project Zero
Project Zero
T
The Exploit Database - CXSecurity.com
TaoSecurity Blog
TaoSecurity Blog
A
Arctic Wolf
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
N
News | PayPal Newsroom

博客园 - 码 头

实测有效:Win11右键默认显示更多设置教程 netcore 并发锁 多线程中使用SemaphoreSlim HTML转义字符大全 .Net Core后台任务启停(BackgroundService) 常见的JavaScript的循环处理数据方法 记录 IIS 部署vue 项目步骤 AspNetCoreApi 跨域处理(CORS ) .NET CORE 使用Session报错:Session has not been configured for this application or request 小豆苗疫苗辅助搜索 日期函数(sql) 图片javascript缩小 c# DESEncrypt 加密、解密算法 汉字编码问题转换 二分法算法 MVC拦截器记录操作用户日志 最全的Resharper快捷键汇总 如何将数据库中的表导入到PowerDesigner中 修复IE9.0下PlaceHolder 属性问题js脚本 sql脚本查询日期时间段日期
Linux下.NET Core进程守护设置,解决SSH关闭后.NET Core服务无法访问的问题
码 头 · 2022-09-22 · via 博客园 - 码 头

通过dotnet命令启动的程序,会在控制台关闭时结束进程,因此需要设置守护进程。这样可以让应用程序一直运行,并且在服务器重启后自动启动。

把以下内容保存为appname.service文件放在/etc/systemd/system目录下

[Unit]
Description=appname守护进程

[Service]
WorkingDirectory=/home/www/appname/bin
ExecStart=/usr/bin/dotnet /home/www/appname/bin/appname.dll

# 程序崩溃后自动启动
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=appname.service
# 用户角色
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
# The default value is 90 seconds for most distributions.
TimeoutStopSec=90

[Install]
WantedBy=multi-user.target
如何管理进程,通过systemctl命令管理

启用服务进程
systemctl enable appname.service

启动服务进程
systemctl start appname.service

查看进程状态
systemctl status appname.service

重启进程
systemctl restart appname.service

停止进程
systemctl stop appname.service

查看日志,实时显示程序console信息
journalctl -fu appname.service

关于.netcore应用程序更新

可以直接覆盖旧的应用程序文件,然后使用systemctl restart 命令重启进程,不需要先关闭进程后覆盖文件再启动。