WorkerService使用文档

1. 创建项目(中文版选用辅助角色服务,英文版直接选用worker Service即可)

2. 添加依赖包

Microsoft.Extensions.Hosting    //worker service 必要包
Microsoft.Extensions.Hosting.Systemd    //部署到Linux系统并使用systemctl管理时使用
Microsoft.Extensions.Hosting.WindowsServices    //部署到Windows,使用sc管理时使用
​

3. 修改Program.cs文件

#添加
.UseSystemd()
.UseWindowsService()

4. Windows启动说明

  1. 发布(使用命名和vs都可以实现)
  2. 使用sc.exe管理
#创建服务名
sc.exe create ServiceName binPath=C:\ServiceName.exe
#启动服务
sc.exe start ServiceName
#查看服务状态
sc.exe query ServiceName
#停止服务
sc.exe stop ServiceName
#删除服务
sc.exe delete ServiceName

5. Linux启动说明

  1. 发布(同windows)
  2. 上传至Linux
  3. 编写systemctl管理文件
vim /etc/systemd/system/ServiceName.service
#配置内容
**********************************************
[Unit]
Description=Servie Information
[Service]
Type=notify
WorkingDirectory=/fileAddrss
ExecStart=/fileAddress/ServiceName
SyslogIdentifier=Servicelog
User=system user name
Environment=.dotnet环境变量
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
  1. systemctl管理
#开启服务
systemctl start ServiceName
#查看服务状态
systemctl status ServiceName
#停止服务
systemctl stop ServiceName
#服务重启
systemctl restart ServiceName
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值