dasMulli / dotnet-win32-service

Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
MIT License
451 stars 57 forks source link

Stop service before deleting it to avoid "disabled" state and being able to recreate it without having to manually stop it. #75

Closed gbrousseau-genetec closed 2 months ago

gbrousseau-genetec commented 6 years ago

Call the StopService() method prior to unistalling the service in Win32ServiceManager to prevent it staying in "disabled" state until someone stops the service (which might never happen). If not doing that, we cannot then install the service. Add a Stop() method to ServiceHandle class. Add a StopService() method to INativeInterop (implemented in Win32Interop). Add ControlService() function to Win32Interop file.

dasMulli commented 6 years ago

Thanks for looking into this.

Do you think this warrants a breaking change in behavior? I'm not against it but trying to decide if an additional StopAndDelete() method makes sense.

ServiceController makes a more sophisticated dance of stopping all dependent services recursively - https://github.com/dotnet/corefx/blob/63cfd9ebb28533078b69daf16287dee1e1daef22/src/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs#L870-L901, so I'm wondering if we should do that as well or just use ServiceController to do that.

gbrousseau-genetec commented 6 years ago

Hi Martin!

I don’t mind having a separate call. I simply thought that there was no point to delete the service without first stopping it. You could just add a default parameter to DeleteService(strtring serviceName, bool stopImmediately = false) similar to the CreateService. As for how to implement it, I don’t mind. My specific needs are only with a small service and no dependencies. If you think a more complete solution can be implemented, go for it ! 😊

-Guy

De : Martin Andreas Ullrich notifications@github.com Envoyé : 13 juin 2018 15:21 À : dasMulli/dotnet-win32-service dotnet-win32-service@noreply.github.com Cc : Guy Brousseau gbrousseau@GENETEC.COM; Author author@noreply.github.com Objet : Re: [dasMulli/dotnet-win32-service] Stop service before deleting it to avoid "disabled" state and being able to recreate it without having to manually stop it. (#75)

Thanks for looking into this.

Do you think this warrants a breaking change in behavior? I'm not against it but trying to decide if an additional StopAndDelete() method makes sense.

ServiceController makes a more sophisticated dance of stopping all dependent services recursively - https://github.com/dotnet/corefx/blob/63cfd9ebb28533078b69daf16287dee1e1daef22/src/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs#L870-L901https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fcorefx%2Fblob%2F63cfd9ebb28533078b69daf16287dee1e1daef22%2Fsrc%2FSystem.ServiceProcess.ServiceController%2Fsrc%2FSystem%2FServiceProcess%2FServiceController.cs%23L870-L901&data=02%7C01%7Cgbrousseau%40genetec.com%7C122d3c88bb4643bf2dfc08d5d162bc9c%7C7ba8d2fb46604a19802e4d015a17e167%7C0%7C0%7C636645144364043944&sdata=RpyoNFLIxm3%2FQgaWLFPRLhHv6RYOI5pqbViB%2FiRRMuw%3D&reserved=0, so I'm wondering if we should do that as well or just use ServiceController to do that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FdasMulli%2Fdotnet-win32-service%2Fpull%2F75%23issuecomment-397054885&data=02%7C01%7Cgbrousseau%40genetec.com%7C122d3c88bb4643bf2dfc08d5d162bc9c%7C7ba8d2fb46604a19802e4d015a17e167%7C0%7C0%7C636645144364043944&sdata=PSRC3N2wKB9ORWwSVhsU2NjcvnwXuSTC7LaQtvhojRA%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAmNs0hANMh9LPSf38VoaU0KpeegCdalSks5t8WYBgaJpZM4UmrKl&data=02%7C01%7Cgbrousseau%40genetec.com%7C122d3c88bb4643bf2dfc08d5d162bc9c%7C7ba8d2fb46604a19802e4d015a17e167%7C0%7C0%7C636645144364053952&sdata=PB2ZHr7XdVfXNGUaxzl30QR005oLLH61Dz02AHKeWwg%3D&reserved=0.