Run your app as a Linux service with systemd
To configure your ASP.NET Core application to run as a Linux service (or daemon in Linux parlance), install the Microsoft.Extensions.Hosting.Systemd
package from NuGet. Then add a call to UseSystemd
to the CreateHostBuilder
method in Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSystemd() // Enable running as a Systemd service .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
dotnet publish -c Release -r linux-x64 -o ./publish
/etc/systemd/system/myapp.service
[Unit] Description=My gRPC Application [Service] Type=notify ExecStart=/usr/sbin/myapp [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl status myapp
sudo systemctl start myapp.service sudo systemctl enable myapp
References
https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/self-hosted