Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Irina Scurtu
Irina Scurtu

Posted on • Originally published atirina.codes on

     

.NET API as a Linux Service

.net api as linux service

.NET API as a Linux Service is just one of the many options when it comes to hosting.

One thing I love about .NET Core is that it runs everywhere. Running .NET APIs as Linux services, allows different organizations to reduce some costs by maybe reusing infrastructure. Before .NET Core, .NET was almost synonymous with Windows. The only server for .NET was IIS.

Now you have a ton of options when it comes to hosting your .NET applications.

You want to keep running it on Windows? You can host and install it as a Windows Service withNSSM. Do you want Kestrel instead of IIS Express? No worries, you can do that. Nowadays, sky is the limit when it comes to hosting a .NET API.

One thing you will need to do is to install .NET on the server. You can readherehow to install .NET on different Linux distributions. (If you never did this or you are not an experienced Linux user).

What you need

– Putty or a way to connect to your Linux server

– sudo rights or execution rights on the server

Running an API as a Linux Service

If you have your API in good standing,versioned,and with the right status codes and you chose Kestrel, the only thing you need to do is to create a .service file and to put it on your Linux server. In my case, the API was hosted on a RedHat distribution.

The service content will be a file with the .service extension (let’s call the file myapi.service), placed under/etc/systemd/system path.

The .service file will contain info related to what it will need to run and from where, and a few flags.

[Unit]Description=Awesome API[Service]WorkingDirectory=/var/opt/myapps/myapiExecStart=/usr/bin/dotnet /var/opt/myapps/myapi/MyApi.dllRestart=alwaysRestartSec=10SyslogIdentifier=myapiUser=rootEnvironment=ASPNETCORE_ENVIRONMENT=DevelopmentEnvironment=DOTNET_PRINT_TELEMETRY_MESSAGE=false[Install]WantedBy=multi-user.target
Enter fullscreen modeExit fullscreen mode

Assuming you have sudo rights, you will need to start the service by runningsystemctl start myapi.service

Useful linux commands

systemctl stop myapi.service stops your service

systemctl start myapi.service starts your service

systemctl status myapi.service returns the status of your service. Is useful when you want to make sure the service is running or for debugging purposes. The response will contain some aditional info, depending on what you have configure, but it will look pretty much like this:status response

Once you have your NET API as a Linux Service up and running, you might need to make it run on HTTPS.

You’ll see in another article how you can configure NGINX Reverse proxy to have Https.

The post.NET API as a Linux Service appeared first onIrina Scurtu.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
insight_it_891bf8cd689700 profile image
Insight IT
Insight IT Training Institute, located in the heart of Hyderabad, is a premier destination for IT education and skill development. we will provide Quality Training with 100% Placement Assitance.
  • Location
    Kphb, Hyderabad
  • Joined

Nice blog and informative content,
We are providing Best Dot NET Training in Hyderabad,
Thanks for sharing with us,
DOT NET Training in Hyderabad
DOT NET Online Training in Hyderabad

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Microsoft MVP, .NET Dev, community builder, conference speaker & organizerhttps://irina.codes, https://dotnetdays.ro)@irina_scurtu
  • Location
    Romania
  • Work
    Software Architect
  • Joined

More fromIrina Scurtu

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp