How to create service application in Linux using C#.Net Core 3.1?

Prabs 1 Reputation point
2021-07-28T10:53:57.37+00:00

Hi Team,

I have a C# .NET Core 3.1 console application which is running on terminal window in RedHat Linux.
It is a long running application. it runs 24/7.
I need to change from console to service application (like windows service in windows OS) which should running on background in Linux.

Could you please help me on this?

Regards,
Prabhakaran

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,180 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 4,662 Reputation points Microsoft Employee
    2021-07-28T14:49:37.087+00:00

    You need to utilize systemd and Microsoft has a very detailed sample to guide you,

    https://devblogs.microsoft.com/dotnet/net-core-and-systemd/

    0 comments No comments

  2. Bruce (SqlWork.com) 54,626 Reputation points
    2021-07-28T14:49:50.713+00:00

    You can any console app with cron, or create a daemon process.

    In Unix/Linux you create a daemon process, by disconnecting from the console. You do this by forking and redirecting stdout to a log file.

    Fortunately ms has wrapped this up for with their service worker project type and UseSystemd(). See

    https://devblogs.microsoft.com/dotnet/net-core-and-systemd/

    0 comments No comments

  3. Prabs 1 Reputation point
    2021-07-30T11:47:55.137+00:00

    Thanks team. I will test it out and come back if I face any issues.

    0 comments No comments

  4. Prabs 1 Reputation point
    2021-08-02T06:48:32.17+00:00

    Hello Team,

    I have one new requirement.
    When i run the sudo systemctl start testapp.service command, application has to wait for config file path provided by user.

    I tried the following code but it is not showing in Linux terminal window

    Console.WriteLine("Enter config file path :");
    string configFilepath = Console.ReadLine();

    Could you please help me on this?

    Regards,
    Prabs

    0 comments No comments