'Linux Systemd Service does not want to start .net core HelloWorld aplication (code=exited, status=203/EXEC)
Im trying to run my Hello World application using a service in the systend file. the steps i followed
mkdir ~/HelloWorld
cd ~/HelloWorld
dotnet new console
sudo mkdir /srv/HelloWorld # Create directory /srv/HelloWorld
sudo chown yourusername /srv/HelloWorld # Assign ownership to yourself of the directory
dotnet publish -c Release -o /srv/HelloWorld
/srv/HelloWorld/HelloWorld # it outputs'Hello World!'
I then create the HelloWorld.service file:
[Unit]
Description=Hello World console application
[Service]
ExecStart=/srv/HelloWorld/HelloWorld
SyslogIdentifier=HelloWorld
User=admin
[Install]
WantedBy=multi-user.target
I then copy the file to systemd
sudo cp HelloWorld.service /etc/systemd/system/HelloWorld.service
sudo systemctl daemon-reload
sudo systemctl start HelloWorld
sudo systemctl status HelloWorld
##When runing status it gives me Acrive failed (Result:exit-code) Process ExecStart=/srv/HelloWorld/HelloWorld (code=exited, status=203/EXEC)
(When i run my Heloworld using "/srv/HelloWorld/HelloWorld " in the console it does log Hello WOrld )
Solution 1:[1]
I'm assuming you were following my blog post on running console apps on Linux (RHEL), based on the commands and comments that are matching. Thank you for reading and sorry you ran into issues. I happen to be refreshing this blog post and ran into the same issue as you, which is why I started Googling and found your question.
Unfortunately, RHEL and dotnet made some changes and the original instructions don't work anymore. Luckily, I was able to resolve it by making some modifications to the service file:
[Unit]
Description=Hello World console application
[Service]
# systemd will run this executable to start the service
ExecStart=/usr/bin/dotnet /srv/HelloWorld/HelloWorld.dll
# to query logs using journalctl, set a logical name here
SyslogIdentifier=HelloWorld
# Use your username to keep things simple.
# If you pick a different user, make sure dotnet and all permissions are set correctly to run the app
# To update permissions, use 'chown yourusername -R /srv/HelloWorld' to take ownership of the folder and files,
# Use 'chmod +x /srv/HelloWorld/HelloWorld' to allow execution of the executable file
User=admin
# This environment variable is necessary when dotnet isn't loaded for the specified user.
# To figure out this value, run 'env | grep DOTNET_ROOT' when dotnet has been loaded into your shell.
Environment=DOTNET_ROOT=/usr/lib64/dotnet
[Install]
WantedBy=multi-user.target
Specifically, pay attention to how I'm invoking the dotnet
executable and passing the path to the HelloWorld.dll as an argument. This is also what the HelloWorld executable file is supposed to do, but for some reason, no longer works.
I'm not sure if you're using RHEL or how you installed .NET, so you may want to replace the path to the dotnet executable (/usr/bin/dotnet), to the path where your dotnet executable is loaded.
The easiest way to find this path is by running which dotnet
.
Alternatively, you can find the path by running dotnet --info
to figure out where the SDK is installed, and start digging for the dotnet executable.
Also, the DOTNET_ROOT
env variable had to be set in the service for me. I used the env | grep DOTNET_ROOT
command to find the correct value for the env variable.
Next time, feel free to message me, so I can be notified and update my content more quickly. Let me know if this works!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |