DotNET: Difference between revisions

Lostmsu (talk | contribs)
create systemd service from an ASP.NET-based package
Lostmsu (talk | contribs)
fixed formatting of ASP.NET 8 block
Line 54: Line 54:
== Packaging ASP.NET projects ==
== Packaging ASP.NET projects ==


Currently building ASP.NET project as Nix package produces a website that does not work correctly out of the box because the executable can not find `wwwroot`, so all the static assets won't load with 404.
Currently building ASP.NET project as Nix package produces a website that does not work correctly out of the box because the executable can not find <code>wwwroot</code>, so all the static assets won't load with 404.


> Request finished HTTP/2 GET https://my.app/css/site.css - 404 0
<blockquote>
Request finished HTTP/2 GET https://my.app/css/site.css - 404 0
</blockquote>


The situation can be fixed by setting `WEBROOT` environment variable to the package path.
The situation can be fixed by setting <code>WEBROOT</code> environment variable to the package path.


An example of systemd + ASP.NET 8 service:
An example of systemd + ASP.NET 8 service:


```nix
<syntaxhighlight lang="nix">
# myapp package needs to be imported; and added to `environment.systemPackages`
# myapp package needs to be imported; and added to `environment.systemPackages`
# it is used below
# the variable myapp is used below


systemd.services.my-app = {
systemd.services.my-app = {
Line 73: Line 75:
   wants = [ "network-online.target" ];
   wants = [ "network-online.target" ];
   serviceConfig = {
   serviceConfig = {
     AmbientCapabilities = "CAP_NET_BIND_SERVICE"; # allow binding to privileged ports - when you want to expose Kestrel directly without reverse proxy
     # allow binding to privileged ports - when you want to expose Kestrel directly without reverse proxy
    AmbientCapabilities = "CAP_NET_BIND_SERVICE";
     User = "myapp"; # must be created using users.users.myapp = { isSystemUser = true; group = "myapp"; };
     User = "myapp"; # must be created using users.users.myapp = { isSystemUser = true; group = "myapp"; };
     Group = "myapp"; # must be created using users.groups.myapp = {};
     Group = "myapp"; # must be created using users.groups.myapp = {};
Line 110: Line 113:
};
};


```
</syntaxhighlight>
[ACME](https://wiki.nixos.org/wiki/ACME)
 
See also: setting up SSL certificates using [[ACME]]


== .NET location: Not found ==
== .NET location: Not found ==