The .net6 core Worker Service project is released and deployed to Linux, and it is deployed and started as a daemon service

1. Publish the project

1. In the form of a folder
2. Select the corresponding platform (Linux-x64) when the target is running
3. Folder option: delete all existing files before publishing
insert image description here
insert image description here

2. Deployment project (install .net6 environment: refer to Linux installation dotnet sdk 6.0 )

(1) Use Xftp to upload the project release file to a specified directory on the Linux server, such as: /var/www
insert image description here
(2) Assign executable permissions to the application

# chmod +x /var/www/chinahorn.mail.send.workerservice/Chinahorn.Mail.Send.WorkerService

insert image description here
(3) Create a new chinahorn.mail.send.service daemon file and move it to /etc/systemd/system/

1. ExecStart: Set the project path
2. Use the systemctl command to reload the new configuration file # systemctl daemon-reload

[Unit]
Description=Running ASP.NET Core on Ubuntu 20.04 Webserver APACHE

[Service]
WorkingDirectory=/var/www/chinahorn.mail.send.workerservice/
ExecStart=/var/www/chinahorn.mail.send.workerservice/Chinahorn.Mail.Send.WorkerService
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=chinahornmailsend
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

insert image description here
(4) Reload the configuration file, start the service, set the service to start automatically

1、使用systemctl命令重新加载新的配置文件
# systemctl daemon-reload
42、启动服务
# systemctl start chinahorn.mail.send
3、停止服务
# systemctl stop chinahorn.mail.send
4、重新查看服务状态
# systemctl status chinahorn.mail.send
5、重启服务
# systemctl restart chinahorn.mail.send
6、设置服务开机自启
# systemctl enable chinahorn.mail.send
7、禁用开机自启
# systemctl disable chinahorn.mail.send
3. View service status

insert image description here

Guess you like

Origin blog.csdn.net/vaecnfeilong/article/details/130326033