Reputation: 111
I'm trying to run my dotnet
application as a daemon service, the first steps that I did are:
NetCore 2.0
dotnet publish bot
inside Ubuntu
terminal I created an user for run the daemon:
sudo useradd -s /sbin/nologin dotnetuser
sudo mkdir /var/bot
sudo cp -R /home/publish/* /var/bot
sudo chown -R dotnetuser:dotnetuser /var/bot
so I created a custom systemd
unit file under: /etc/systemd/system/netcore-console-bot.service
directory:
[Unit]
Description= Bot console application
DefaultDependencies = no
[Service]
Type = oneshot
RemainAfterExit = no
ExecStart= /var/bot/ bot.dll
WorkingDirectory = /var/bot
User = dotnetuser
Group = dotnetuser
[install]
I tried to execute the daemon
using the systemctl status
command: start netcore-console-bot.service
but I got:
netcoreconsole-bot.service: Main process exited, code=exit
What I did wrong?
Upvotes: 1
Views: 634
Reputation: 3357
I am pretty sure that the only change that you need to make from my testing is making sure to tell dotnet to run the dll. My paths should be pretty close to what you need to do. Alternatively you could use a self-contained deployment when you publish and package the runtime with the app.
[Unit]
Description= Bot console application
DefaultDependencies = no
[Service]
Type = oneshot
RemainAfterExit = no
ExecStart= /usr/bin/dotnet /var/bot/bot.dll
WorkingDirectory = /var/bot
User = dotnetuser
Group = dotnetuser
[install]
Upvotes: 1