Dotnet Service on Linux

the folder structures

the actual project

the actual projects are in the users repos folder, where JetBrains Rider, or dotnet itself creates the folder structure appropriately for each project

~/repos/`organisation`/`projectname`

the deployed service

/usr/local/sbin/`organisation`/`projectname`

the service configuration file

/etc/systemd/system/`servicename`.service

the configuration

create the deployment

cd /usr/local/sbin
mkdir `organisation`
chown $USER `organisation`

configure the service

sudo gnome-text-editor /etc/systemd/system/`servicename`.service

then edit the file as follows

[Unit]
Description=`your service description`

[Service]
WorkingDirectory=/usr/local/sbin/`organisation`/`projectname`
ExecStart=/usr/bin/dotnet /usr/local/sbin/`organisation`/`projectname`/`servicename`.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=`servicename`
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

start the service

sudo systemctl daemon-reload
sudo systemctl enable `servicename`.service
sudo systemctl start `servicename`.service

based on information from tecadmin.net: create systemd service for dotnet application on linux