ConSol-Monitoring / snclient

SNClient+ - Cross platform monitoring agent
MIT License
48 stars 8 forks source link

Keep logon account for snclient Windows service #23

Closed h4ppywastaken closed 10 months ago

h4ppywastaken commented 1 year ago

On version 0.03 I configured the snclient Windows service to run with a different user. (Services > snclient Properties > Log On) After upgrading to version 0.04 this configuration was lost and reverted back to default "Local system account". Is it possible to keep this setting on version upgrades?

lausser commented 1 year ago

How did you upgrade? Installing via MSI?

h4ppywastaken commented 1 year ago

First I installed version 0.03 from msi package. Then configured the LogOn Account. Restarted the snClient service. Then installed version 0.04 from msi package. The LogOn account was then reset to default System account.

sni commented 1 year ago

the service is tied to the msi installer, if you install the msi, the default service will be installed. Always. I didn't find a workaround. The service definition is here: https://github.com/ConSol-Monitoring/snclient/blob/main/packaging/windows/snclient.wxs#L35-L53 For now i give up, but i am open to suggestions and pull requests which improves the service installation.

h4ppywastaken commented 1 year ago

You could have public properties for the service account that can be set on calling the .msi file like here: https://stackoverflow.com/questions/51787967/wix-serviceinstall-specify-account

I am not really familiar with wix - but maybe this works.

ArisNeander commented 10 months ago

I found two more StackOverflow links regarding this: https://stackoverflow.com/a/57517308/1595345 https://stackoverflow.com/q/2228855/1595345

I can verify that adding the 'DeleteServices' tag works to prevent overwriting the service definition on upgrade. I just don't know enough about wix to tell if everything from the first link is needed.

sni commented 10 months ago

Thanks for that one, i gonna have a look. Sounds promising.

sni commented 10 months ago

the problem with that approach is, that the installer does not handle the service anymore but needs to stop the service in order to replace the snclient.exe This leads to this ugly dialog during the update:

2023-11-06_23-17

Then i tried to move the creation and removal of the service completely from the msi into pre/post hooks. But i wasn't able to start any hook before the dialog above pops up.

The order of steps is listed here: https://learn.microsoft.com/en-us/windows/win32/msi/suggested-installexecutesequence Hooks can be run between InstallInitialize and InstallFinalize.

But it seems like this dialog can be suppressed by setting MSIRESTARTMANAGERCONTROL=Disable.

sni commented 10 months ago

implemented in cc5501ff9f0f7e1f6796077e9be8cb9ac172c8d4