Downloads  |  Buy

Stopping a service before update

Stopping a service before update

Postby AdiGri » June 28th, 2010, 2:38 pm

Hello,

I have a .Net application that between other executables, has a service that may have to be updated. Before being able to replace it, the service has to be stopped. Would I be using one of the events raised by AutomaticUpdater, such as ReadyToBeInstalled (and stop the service myself, before the update takes place and restart it using the UpdateSuccessful event)?
AdiGri
 

Re: Stopping a service before update

Postby Wyatt » June 28th, 2010, 3:37 pm

We plan to add this directly in wyBuild in the future, but yes, for now you need to stop the service within your own code before it can be updated. You can do this a few ways (including using AutomaticUpdater events), but by far the best way is this:

[b:qxubuoil]Stop the services before updating using a batch file[/b:qxubuoil]

Simply add 2 batch files to your update in the Temporary folder. One batch file will stop the service before an update. The other batch file will stop the service after an update:


[attachment=0:qxubuoil]
executing-batch.png
executing-batch.png (64.63 KiB) Viewed 3770 times
[/attachment:qxubuoil]

Simply check the "Execute file" checkbox to execute the batch files. Read more about [url=http://wyday.com/wybuild/help/executing-files.php:qxubuoil]Executing files in your update[/url:qxubuoil]. There are several article online describing how to start and stop services as part of a batch file. Here are a couple that I found in a quick search:

[list:qxubuoil]
[*:qxubuoil][url=http://stackoverflow.com/questions/133883/stop-and-start-a-service-via-batch-or-cmd-file:qxubuoil]Stop and Start a service via batch or cmd file?[/url:qxubuoil][/*:m:qxubuoil]
[*:qxubuoil][url=http://www.tech-recipes.com/rx/235/create-batch-file-to-start-or-end-window-services/:qxubuoil]Create Batch File to Start or End Windows Services[/url:qxubuoil][/*:m:qxubuoil][/list:u:qxubuoil]


Tell me if this helps.
User avatar
Wyatt
Site Admin
 
Posts: 5991
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Stopping a service before update

Postby AdiGrio » August 26th, 2010, 3:03 pm

Hello,

I have finally tried to use these suggestions and I found that wyUpdate is first asking me close the process (the actual service) and only after that is running the batch file that was configured to stop it. I've put a "PAUSE" command in the batch file just to see when it runs. The "stop_service.cmd" file that I use is configured in wyBuild to be executed before the update begins and to wait for the executions to finish before continuing. Am I doing something wrong?

The start_service.cmd works fine and at least the service is restarted even though the user has to kill the process during the update.
AdiGrio
 
Posts: 2
Joined: August 26th, 2010, 2:56 pm

Re: Stopping a service before update

Postby Sam » August 27th, 2010, 3:58 am

You're right, there's no proper way to update services. We're going to add this in wyBuild 2.6.8 or 2.6.9.
User avatar
Sam
 
Posts: 3126
Joined: March 8th, 2010, 3:01 am
Location: New Hampshire

Re: Stopping a service before update

Postby AdiGrio » August 27th, 2010, 2:46 pm

Thank you the reply. I will try to see if I can embed the service stopping/restarting in the application itself before the AutomaticUpdater starts.
AdiGrio
 
Posts: 2
Joined: August 26th, 2010, 2:56 pm

Re: Stopping a service before update

Postby Sam » September 30th, 2010, 3:46 am

Now in wyBuild 2.6.7 you can Start and Stop services. Simply go to the "Update Actions" and add an action to stop the services before the update, and add another action to start the services after the update.

See [url=http://wyday.com/wybuild/help/services.php:18g6sr82]Starting and Stopping Windows Services[/url:18g6sr82].
User avatar
Sam
 
Posts: 3126
Joined: March 8th, 2010, 3:01 am
Location: New Hampshire

Re: Stopping a service before update

Postby jake » October 4th, 2010, 9:08 am

Woot! This is great, thanks.
jake
 


Return to wyBuild, wyUpdate, & AutomaticUpdater Support