views:

75

answers:

3

Say, you have a custom Windows service installed on a server. The service is written using .NET, and it is installed using either InstallUtil, an MSI package or the ManagedInstallerClass (if it makes a difference, pick the one that solves the problem). Regularly, you will need to deploy changes to the service, and of course you want to make this as easy as possible.

Is it "safe" to just stop the service, replace the .exe file and restart the service? Or would you have to uninstall and reinstall with the new .exe file? Would it be easier if the "evolving" part of the service was split into a separate assembly? Are there any tools or APIs that might be of help in either development or deployment of the service?

+4  A: 

I just stop the service and replace the exe; it's safe to do that.

You can have it so that your service begins to load modules, and you develop your system that way; it would work, but it may be overly complicated, or not, depending on what exactly you're wanting to do.

Noon Silk
This is easiest, after installUtil registration theres no need to do anything but re-copy the files.
Pat
This works fine unless some relevant settings in the service installer are changed, e.g. user account etc. Of course the service might still run but with different settings than the expected ones.
0xA3
divo: You're correct, I neglected to mention that. It's worth noting, but in practice those types of things rarely change between versions of apps.
Noon Silk
+2  A: 

Just stop the service, replace the EXE and restart it. This should probably be part of your installer. Separating it into separate assemblies just for the sake of reinstall is a rabbit hole.

David Lively
+1  A: 

For updating services we either use MSI packages (in case we provide an installer to our customers anyway) or a short script that handles stopping and uninstalling the old version of service, and then copies, installs and starts the new version.

For scripting the deployment of local services you can use standard Windows commands such as net start and net stop in combination with installutil, for remote deployment you could e.g. use psexecute and psservice from SysInternals.

0xA3
Any particular reason you choose to uninstall and reinstall? Is it just to guard against possible changes to "settings in the service installer"? (cf. your comment on silky's answer)
Jørn Schou-Rode
Yes, it is just a cleaner way e.g. in case the service name has been changed. Without uninstall/reinstall you might get stale entries in the Registry.
0xA3