1

I'm trying to develop a C# Worker Service with .NET Core 3.1 and run it as a service on an Ubuntu machine.

I found this guide to set up Worker Services on Linux, but I'm getting errors (see screenshot) when trying to start the service.

The guide does not specify how to compile the solution for Linux, so I found this post and compiled a package using dotnet build --runtime ubuntu.18.04-x64. The result is a folder with my Application and no file extension, as well as a long list of .dll files.

Is this the correct way of publishing Worker Services, or generally .NET Core Applications targeting Linux, on a Windows machine? I wasn't able to find any official documentation or other resources on how to properly do this.

I unfortunately can't directly develop on the Ubuntu machine, as it only has a command-line interface.

enter image description here

Johannes Mols
  • 890
  • 1
  • 12
  • 35
  • Publish as self contained, https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained Then you won't need anything else on the target Ubuntu machine. Also never post something like "I'm getting errors" here in the future. We expect you describe the actual errors in details. – Lex Li Feb 21 '20 at 21:16
  • @LexLi Is -runtime and -r the same parameter? If so, I already did that. Sorry for not specifying the error, I added a screenshot of the error message I am getting. – Johannes Mols Feb 21 '20 at 21:39
  • Learn the Linux command `chmod` please. – Lex Li Feb 21 '20 at 23:11
  • @LexLi I used it to set the files to 777, but it didn't change anything. – Johannes Mols Feb 21 '20 at 23:28
  • Then your debugging on .NET Core side is finished. Try more general Linux side debugging https://unix.stackexchange.com/questions/472950/systemd-status-203-exec-error-when-creating-new-service – Lex Li Feb 22 '20 at 01:21
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Mar 06 '20 at 00:38
  • @JohannesMols did you find a working solution ? – Vinod Jun 23 '20 at 14:36
  • @Vinod no, unfortunately not – Johannes Mols Jun 23 '20 at 15:39
  • 1
    @JohannesMols , it worked for me after giving the 777 permission for published files which your going to host. (.dll,config & json) – Vinod Jun 25 '20 at 09:32
  • Following [this](https://medium.com/bluekiri/packaging-a-net-core-service-for-ubuntu-4f8e9202d1e5) article did it for me. – Veverke Nov 09 '20 at 21:26

2 Answers2

2

Looking at the documentation for dotnet run ubuntu.18.04-x64 looks like an incorrect runtime: https://learn.microsoft.com/en-us/dotnet/core/rid-catalog

Only common values are listed. For the latest and complete version, see the runtime.json file on the dotnet/runtime repository. Devices running a distribution not listed below may work with one of the Portable RIDs. For example, Raspberry Pi devices running a Linux distribution not listed can be targeted with linux-arm.

  • Portable (.NET Core 2.0 or later versions)

    • linux-x64 (Most desktop distributions like CentOS, Debian, Fedora, Ubuntu, and derivatives)

    • linux-musl-x64 (Lightweight distributions using musl like Alpine Linux)

    • linux-arm (Linux distributions running on ARM like Raspberry Pi)
  • Red Hat Enterprise Linux
    • rhel-x64 (Superseded by linux-x64 for RHEL above version 6)
    • rhel.6-x64 (.NET Core 2.0 or later versions)
  • Tizen (.NET Core 2.0 or later versions)
    • tizen
    • tizen.4.0.0
    • tizen.5.0.0

so instead of dotnet build --runtime ubuntu.18.04-x64 try dotnet build --runtime linux-x64

Mark Davies
  • 1,447
  • 1
  • 15
  • 30
  • Thank you for your answer. That unfortunately doesn't change anything, I'm still getting the same errors. I will update my question with the error message in a second. – Johannes Mols Feb 21 '20 at 21:33
  • Might be a good idea to post some of your code as the error message seems related to what your doing code wise – Mark Davies Feb 21 '20 at 21:39
  • I updated the screenshot as I tried a fix to my actual error messages and forgot to change it back. It's saying Permission Denied, even though I am running the command with sudo and I set file without a file extension to be executable. The code itself is extremely basic and basically only prints out a test message. – Johannes Mols Feb 21 '20 at 21:44
  • Hey sorry about the late reply but it looks like this is a file/folder persmision thing, have you tried running this under the super user? i.e. `sudo dotnet build --runtime linux-x64`, you may wan to check your users persmissions to those files and folders – Mark Davies Aug 27 '20 at 12:18
1

Following this article did it for me.

The article's example uses "linux-x64" as the dotnet publish runtime identifier, that's what I used (my machine also runs Ubuntu). Until proved the contrary, seems like "linux-x64" may run properly in different distributions.

Am leaving here one question I posted on a related issue I faced during the process of deploying my .net core worker service as a systemd daemon/service unit in linux.

Veverke
  • 9,208
  • 4
  • 51
  • 95