loic-sharma / BaGet

A lightweight NuGet and symbol server
https://loic-sharma.github.io/BaGet/
MIT License
2.62k stars 674 forks source link

run baget as windows service #510

Open PurTahan opened 4 years ago

PurTahan commented 4 years ago

Hi

how can i run baget as windows service?

when i create service using sc.exe it can't run!

jeroenlandheer commented 4 years ago

BaGet is built as a ASP.Net Core Web host, if you want to run this as a Windows Service, you can, but you'll need to do some additional work to make that happen.

You can take a look here to see how that works.

(If this is a highly requested feature I might be able to contribute, @loic-sharma ?)

PurTahan commented 4 years ago

thank but many web based project can run as a windows service like gitea. i think it is a great option for end users

PurTahan commented 4 years ago

BaGet is built as a ASP.Net Core Web host, if you want to run this as a Windows Service, you can, but you'll need to do some additional work to make that happen.

You can take a look here to see how that works.

(If this is a highly requested feature I might be able to contribute, @loic-sharma ?)

if it's not in this project's road map, please help me to make it possible for myself.

WernerMairl commented 4 years ago

You can use a tool like the Windows Service Wrapper

SeppPenner commented 4 years ago

@PurTahan You should probably take a look at this article: https://devblogs.microsoft.com/aspnet/net-core-workers-as-windows-services/ and at my project under https://github.com/SeppPenner/NetCoreMQTTExampleCluster/blob/master/src/NetCoreMQTTExampleCluster.Cluster/Program.cs where you can see this at work. I have also the option to run my service in Linux (SystemD). As far as I know, this is the recommended way from Microsoft to run services in NetCore3.1+ right now.

I can add this to the project if it's desired. However, I don't know how or if this will affect the Docker build here. This is something @loic-sharma needs to answer. That said, just hit me up if you need help here :)

loic-sharma commented 4 years ago

I can add this to the project if it's desired. This is something @loic-sharma needs to answer. That said, just hit me up if you need help here :)

I'm not very familiar with Microsoft.Extensions.Hosting.WindowsServices as I've never used it myself. Does it work if you run on mac or linux?

SeppPenner commented 4 years ago

@loic-sharma Of course, Microsoft.Extensions.Hosting.WindowsServices will not run under Linux ;D It will work on Linux with the Microsoft.Extensions.Hosting.Systemd package or CreateDefaultBuilder().UseSystemd().Build(); (and the correct systemd service configuration file). I have no idea if / how this works on Mac to be honest.

SeppPenner commented 4 years ago

Another link (for using this under Linux): https://devblogs.microsoft.com/dotnet/net-core-and-systemd/. I will search for MacOSX, but haven't found anything yet. Maybe we need to ask someone on Stackoverflow for this^^ Same for Open / FreeBSD (If anyone should ever need this).

jeroenlandheer commented 4 years ago

I was thinking, since this is basically building a host around ASP.Net Core's web server Kestrel, I wonder if there's nothing similar already done out there (which is platform agnostic)...

SeppPenner commented 4 years ago

@jeroenlandheer I don't think so. Maybe an extension of the Microsoft.Extensions.Hosting for those platforms, yes. As far as I know, these worker services are the way to at the moment...

loic-sharma commented 4 years ago

I don't think it makes sense for BaGet to directly integrate with either systemd or Windows services given that BaGet aims to be cross-platform. I think using a wrapper like @WernerMairl suggested is the best option right now. The nuget.org team does something very similar - we use nssm to run our job executables as Windows services. Maybe we should add documentation that details how to do this for BaGet?

I would like to make it easy to embed BaGet into your .NET application. Ideally, this embeddedable version of BaGet should play support systemd or Window services integration. What are your thoughts?

SeppPenner commented 4 years ago

I don't think it makes sense for BaGet to directly integrate with either systemd or Windows services given that BaGet aims to be cross-platform.

That's true. I don't know how this would affect Docker builds and that kind of stuff^^ However, we might provide a extra project that runs BaGet as service in the future?

I would like to make it easy to embed BaGet into your .NET application. Ideally, this embeddedable version of BaGet should play support systemd or Window services integration. What are your thoughts?

Ok, I didn't read that :D Exactly the idea I had as well 👍