AutomaticUpdaterBackend not restarting service

I closely followed the instructions on the help pages, but upgrades are not working properly. It seems that an update is identified, and my service exits.... but it is never restarted... also, when I manually restart my service, it instantly shuts down thinking there is an update to install... Ideas?

Here is my code:

partial class OpexClientServiceMain : ServiceBase { private static readonly Logger Logger = LogManager.GetLogger("OpexClientServiceMain"); private readonly OpexUploadServiceCore _uploadService; private readonly HeartbeatServiceCore _heartbeatService; private readonly DicomIngestServiceCore _ingestService; private static AutomaticUpdaterBackend _auBackend;

public OpexClientServiceMain(OpexUploadServiceCore uploadService, HeartbeatServiceCore heartbeatService, DicomIngestServiceCore ingestService) { InitializeComponent(); _uploadService = uploadService; _heartbeatService = heartbeatService; _ingestService = ingestService; }

protected override void OnStart(string[] args) { Logger.Info("AutomaticUpdateWrapper called"); _auBackend = new AutomaticUpdaterBackend { GUID = "OpexClient-OnPointMD", UpdateType = UpdateType.Automatic, ServiceName = this.ServiceName };

_auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled; _auBackend.UpdateSuccessful += auBackend_UpdateSuccessful; _auBackend.CheckingFailed += auBackend_FailHandler; _auBackend.DownloadingFailed += auBackend_FailHandler; _auBackend.ExtractingFailed += auBackend_FailHandler; _auBackend.UpdateFailed += auBackend_FailHandler;

_auBackend.Initialize(); _auBackend.AppLoaded();

if (!_auBackend.ClosingForInstall) { if (_auBackend.UpdateStepOn == UpdateStepOn.Nothing) { _auBackend.ForceCheckForUpdate(); }

_ingestService.StartListening(); _uploadService.StartUploading(); _heartbeatService.StartBeating(); } }

protected override void OnStop() { _ingestService.StopListening(); _uploadService.StopUploading(); _heartbeatService.StopBeating(); }

#region update message handlers private void auBackend_FailHandler(object sender, FailArgs e) { Logger.Error("Autoupdate failure: {0} - {1}", e.ErrorTitle, e.ErrorMessage); }

private void auBackend_UpdateSuccessful(object sender, SuccessArgs e) { Logger.Info("Autoupdate succeeded. New version: {0}", e.Version); }

private void auBackend_ReadyToBeInstalled(object sender, EventArgs e) { Logger.Info("auBackend_ReadyToBeInstalled called"); if (_auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall) { Logger.Info("Autoupdate ready to be installed"); _ingestService.StopListening(); _uploadService.StopUploading(); _heartbeatService.StopBeating();

Logger.Info("Autoupdate installing!"); _auBackend.InstallNow(); } else if (_auBackend.UpdateStepOn == UpdateStepOn.UpdateDownloaded) { Logger.Info("Autoupdate successfully downloaded"); } } #endregion }

I made a bare windows service and have been unable to get it updating properly following the guide. I must be missing something very basic...

I'll post my my code for this spike project in this thread... I started the service after making an update available, got these log messages, then the service was never restarted:

Version 1.0 - 9/12/2011 12:13 PM - 9508 - StartupVersion 1.0 - 9/12/2011 12:13 PM - 9508 - Service ConstructorVersion 1.0 - 9/12/2011 12:13 PM - 9508 - Service OnStartVersion 1.0 - 9/12/2011 12:13 PM - 9508 - Program Not Closing for InstallVersion 1.0 - 9/12/2011 12:13 PM - 9508 - UpdateStep is: NothingVersion 1.0 - 9/12/2011 12:13 PM - 9508 - Forcing check for updateVersion 1.0 - 9/12/2011 12:13 PM - 9508 - auBackend_ReadyToBeInstalled calledVersion 1.0 - 9/12/2011 12:13 PM - 9508 - Update is ready to installVersion 1.0 - 9/12/2011 12:13 PM - 9508 - Calling InstallNow()Version 1.0 - 9/12/2011 12:13 PM - 9508 - Called InstallNow()

The service then exits and is never restarted. I don't see a 'WyUpdate.exe' running either. The service is running as 'Local System' so there should be no perm issues. The files are never updated either, It just exits after calling InstallNow().

Upon subsequent restarts, this is what is logged (the service instantly stops thinking it has an upgrade):Version 1.0 - 9/12/2011 12:14 PM - 5176 - StartupVersion 1.0 - 9/12/2011 12:14 PM - 5176 - Service ConstructorVersion 1.0 - 9/12/2011 12:14 PM - 5176 - Service OnStartVersion 1.0 - 9/12/2011 12:15 PM - 5176 - auBackend_ReadyToBeInstalled calledVersion 1.0 - 9/12/2011 12:15 PM - 5176 - Update is ready to installVersion 1.0 - 9/12/2011 12:15 PM - 5176 - Calling InstallNow()Version 1.0 - 9/12/2011 12:15 PM - 5176 - Called InstallNow()

All I did was slightly modify the 'check every 10 days' part of your Windows Service example... What am I doing wrong? Can I turn on debug logs for WyUpdate? Where does it log to?

Source file contents posted below....

Program.cs - (I changed the version string to 1.1 to check if the upgrade is taking place)

using System;using System.Diagnostics;using System.IO;using System.ServiceProcess;

namespace AutoUpgradeSpike{ static class Program { private const string Version = "Version 1.1";

public static void writeLogMessage(string message) { using (var fileWriter = File.Open("C:\\serviceSpikeLog.txt", FileMode.Append, FileAccess.Write, FileShare.Write)) { using (var streamWriter = new StreamWriter(fileWriter)) { streamWriter.WriteLine(String.Format("{0} - {1} {2} - {3} - {4}", Version, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), Process.GetCurrentProcess().Id.ToString(),message)); } } }

static void Main() { try { writeLogMessage("Startup"); var servicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(servicesToRun); writeLogMessage("Exiting Main"); } catch (Exception ex) { writeLogMessage("Top level exception caught: " + ex); throw; } } }}

Service1.cs - From the help page...

using System;using System.ServiceProcess;using wyDay.Controls;

namespace AutoUpgradeSpike{ public partial class Service1 : ServiceBase { static AutomaticUpdaterBackend auBackend;

public Service1() { Program.writeLogMessage("Service Constructor"); InitializeComponent(); }

protected override void OnStart(string[] args) { Program.writeLogMessage("Service OnStart");

auBackend = new AutomaticUpdaterBackend { GUID = "AutoUpgradeSpike-Josh", UpdateType = UpdateType.Automatic, ServiceName = this.ServiceName };

auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled; auBackend.UpdateSuccessful += auBackend_UpdateSuccessful; auBackend.CheckingFailed += auBackend_FailHandler; auBackend.DownloadingFailed += auBackend_FailHandler; auBackend.ExtractingFailed += auBackend_FailHandler; auBackend.UpdateFailed += auBackend_FailHandler; auBackend.Initialize(); auBackend.AppLoaded();

if (!auBackend.ClosingForInstall) { Program.writeLogMessage("Program Not Closing for Install"); Program.writeLogMessage(String.Format("UpdateStep is: {0}", auBackend.UpdateStepOn.ToString())); if (auBackend.UpdateStepOn == UpdateStepOn.Nothing) { Program.writeLogMessage("Forcing check for update"); auBackend.ForceCheckForUpdate(); } } }

protected override void OnStop() { Program.writeLogMessage("Service OnStop"); }

static void auBackend_ReadyToBeInstalled(object sender, EventArgs e) { Program.writeLogMessage("auBackend_ReadyToBeInstalled called"); if (auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall) { Program.writeLogMessage("Update is ready to install"); Program.writeLogMessage("Calling InstallNow()"); auBackend.InstallNow(); Program.writeLogMessage("Called InstallNow()"); } }

private void auBackend_UpdateSuccessful(object sender, SuccessArgs e) { Program.writeLogMessage(String.Format("auBackend_UpdateSuccessful - Autoupdate succeeded. New version: {0}", e.Version)); }

private void auBackend_FailHandler(object sender, FailArgs e) { Program.writeLogMessage(String.Format("auBackend_FailHandler - Autoupdate failure: {0} - {1}", e.ErrorTitle, e.ErrorMessage)); } }}

I know you say the service isn't restarted, but is the service (or your app) ever updated? Also, are you including wyUpdate.exe and the client.wyc file in the same folder as the Windows Service?

Hey Sam,

Upon further inspection, my app is not being upgraded. I watched everything in process monitor and see that WyUpdate.exe is spawned as:

"C:\AutoUpgradeSpike\Active\wyUpdate.exe" /autoupdate

I tried running this myself, but it looks like it just hangs waiting for some IPC (probably from the spawning app).

Manually running wyUpdate with the gui DOES work. The service is upgraded and restarted. I would really like to have the auto-upgrade working though.

When you call Install(), is wyUpdate currently running in the task manager. If so, what happens after install is called and your service is shutdown -- is wyUpdate running or does it close immediately.

Lastly what version of wyUpdate.exe and the AutomaticUpdater are you using? Right click the file and click "Properties".