Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make ASP.NET application always running on linux? #2367

Open
nabeelriazhi opened this issue Feb 15, 2024 · 1 comment
Open

How to make ASP.NET application always running on linux? #2367

nabeelriazhi opened this issue Feb 15, 2024 · 1 comment

Comments

@nabeelriazhi
Copy link

We have a background job that is long running and cannot be idempotent. When redhat restarts our hangfire .net core app, we lose hours of progress.

We are using following configuration.

`
[Unit]
Description=ABC

[Service]
WorkingDirectory=/var/www/html/ABC
ExecStart=/usr/bin/dotnet /var/www/html/ABC/XYZ.DLL
Restart=always

Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target
`

@pieceofsummer
Copy link
Contributor

pieceofsummer commented Feb 15, 2024

The very concept of "always running" or not is only applicable when your application is hosted by IIS. It has the ability to stop/unload applications after a period of inactivity, and load/start it again when request comes.

When hosting it as a systemd service on Linux, there's no such thing. All services (unless they're socket-activated templates on per-connection basis, which it is not your case) are always running. Systemd starts the service process and monitors its status, but otherwise doesn't affect it in any way (unless it is explicitly told to with systemctl command or similar).

So, with your app stopping and restarting, I can imagine a few possible scenarios:

  • Something (e.g. cron schedule, or host events if your machine is running in a cloud) or someone (admin) is restarting your server/service periodically. This is unlikely, but still a possibility.
  • Your application crashes hard (memory corruption in native modules or runtime itself, stack overflow, or some other thing that can't be handled by .net managed exception handlers), and is restarted by systemd because of restart policy.
  • Your application hits some limit (virtual memory size, number of open file handles, amount of data written etc.) set on your system, and is killed by the kernel. Then it is restarted by systemd.

In any case, there should be traces in the service log. If the reason is system limits, those can be altered globally or set in service config for a specific service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants