Generally, we can execute dotnet < app on Linux server_ assembly.dll >Command to run our. Net core webapi application. However, the application running in this way is very unstable. After closing the terminal window, the application will also stop running. In order to make it run stably, we need to make it become the system’s daemons, a service that runs in the system all the time, and can restart when there is an exception.
Linux system has its own daemons management tool SYSTEMd. SYSTEMd is the first user process after the kernel starts, with PID of 1 and is the parent process of all other user processes. It interacts directly with the kernel and has excellent performance. It can provide many powerful functions for starting, stopping and managing processes. We can give the program to SYSTEMd and make the system unified management and become the real system service.
Systemctl is used to manage the behavior of SYSTEMd, replacing the previous systemvinit and upstart.
Create service file
To create a service definition file:
Here is a sample service file for the application:
[Unit] Description = run Qf.InteCabinet service [Service] Workingdirectory = / opt / intecabinet ා depends on the environment and can specify multiple ExecStart=/usr/bin/dotnet /opt/InteCabinet/Qf.InteCabinet.WebApi.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=qf-intecabinet User = root # the user who manages the service. The user must exist and have the ownership of the correct application file Environment=ASPNETCORE_ Environment = production ා environment variable Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi- user.target #The target where the service is located
Save the file and enable the service
systemctl enable qf-intecabinet.service
Start the service
systemctl start qf-intecabinet.service
View service status
systemctl status qf-intecabinet.service
journalctl -fu qf-intecabinet.service
You can reduce the number of entries returned by using time options such as — since today, — until 1 hour ago) or a combination of these options
journalctl -fu qf-intecabinet.service --since "2020-01-01" --until "2020-03-01 12:00"
Shut down the service
systemctl stop qf-intecabinet.service
Microsoft official documents
This article on the. Net core 3.0 webapi to create Linux daemons on this, more related. Net core webapi create daemons content, please search the previous articles or continue to browse the related articles below, I hope you can support developeppaer more in the future!