To run an ASP. NET Core site on a Linux server in a build environment, the first problem is to run the ASP. NET core site as a service, so that the site can run automatically even if the server restarts.
There are powerful PM2 in node. js, and. NET core has nothing to do with its own hands-on implementation. Groping for a night, and finally using the INITCTL command based on the Linux upstart implementation, in this blog post to share (the experiment with the Linux server is Ubuntu).
First create a service configuration file in the/etc/init/directory, such as this is/etc/init/dotnet-app.conf, and add the following to the file:
Description "Set System Dotnet-app" Start on RunLevel [2345]taskscriptcd/data/aboutus && sudo dotnet run End Script
The bold part is the command that runs the ASP. NET Core site.
Then start the service with the following command:
Initctl Start Dotnet-app
Note: If the "Initctl:job failed to start" error occurs, you can view the corresponding error log in the "/var/log/upstart/" directory, for example, this is/var/log/upstart/dotnet-app.log.
Then use the following command to see the service running:
# initctl Status Dotnet-appdotnet-app start/running, Process 862
"Start/running" indicates that the service started successfully, and then the ASP. NET core site is normally accessible.
Finally reboot the Linux server verify that the reboot command restarts the server, after the server is started, the ASP. NET Core site is also accessible, done.
Running an ASP. NET core site on Linux as a service