Skip to content

Commit

Permalink
Changes to improve package deployer reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
cturano committed Mar 10, 2017
1 parent 49732be commit 801e0fa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<PackageAuthor>Charles Turano</PackageAuthor>
<PackagePublisher>Hedgehog Development</PackagePublisher>
<PackageReadme>Installs packages using a folder</PackageReadme>
<PackageVersion>1.6</PackageVersion>
<PackageVersion>1.8</PackageVersion>
<SitecoreAssemblyPath>..\packages\SitecoreKernel.7.0.0.131127\lib</SitecoreAssemblyPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
6 changes: 3 additions & 3 deletions SitecorePackageDeployer.Web/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Hhogdev.SitecorePackageDeployer.Web")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © 2015, 2016, 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Sitecore.Pipelines;
using Sitecore.SecurityModel;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Xml.Serialization;

Expand All @@ -30,6 +32,8 @@ private void LoadSettings()

public void Process(PipelineArgs args)
{
Log.Info("Sitecore package deployer starting. Version: " + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location). FileVersion, this);

//Check to see if we can run post steps
InstallPackage.InstallerState state = InstallPackage.GetInstallerState();
if (state == InstallPackage.InstallerState.InstallingPackage || state == InstallPackage.InstallerState.InstallingPostSteps)
Expand Down
4 changes: 2 additions & 2 deletions SitecorePackageDeployer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
63 changes: 34 additions & 29 deletions SitecorePackageDeployer/Tasks/InstallPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal enum InstallerState
internal const string STARTUP_POST_STEP_PACKAGE_FILENAME = "StartPostStepPackage.xml";
internal const string SUCCESS = "Success";
internal const string FAIL = "Fail";
internal const string INSTALLER_STATE_PROPERTY = "SPD_InstallerState";
internal const string INSTALLER_STATE_PROPERTY = "SPD_InstallerState_";

static string sitecoreUpdatePath = Assembly.GetAssembly(typeof(PackageInstallationInfo)).Location;
static Assembly sitecoreUpdateAssembly = Assembly.LoadFile(sitecoreUpdatePath);
Expand All @@ -57,9 +57,6 @@ internal enum InstallerState
//Determines if the config files should be updated
bool _updateConfigurationFiles;

//Indicates that a package is being installed


public static bool ShutdownDetected { get; set; }

public InstallPackage()
Expand Down Expand Up @@ -114,30 +111,38 @@ private void InstallPackages()
return;
}

//Block further package installs
SetInstallerState(InstallerState.InstallingPackage);

using (new SecurityDisabler())
//Prevent shutdown
using (new ShutdownGuard())
{
//Find pending packages. This loop may not complete if there were binary/config changes
foreach (string updatePackageFilename in Directory.GetFiles(_packageSource, "*.update", SearchOption.TopDirectoryOnly).OrderBy(f => f))
//If Sitecore is shutting down, don't start the installer
if (ShutdownDetected)
{
string updatePackageFilenameStripped = updatePackageFilename.Split('\\').Last();
if (ShutdownDetected)
{
Log.Info("Install packages aborting due to shutdown", this);
Log.Info("Skipping Install because shutdown is pending", this);

if (GetInstallerState() != InstallerState.WaitingForPostSteps)
{
SetInstallerState(InstallerState.Ready);
}
return;
}

break;
}
//Block further package installs
SetInstallerState(InstallerState.InstallingPackage);

//Prevent shutdown
using (new ShutdownGuard())
using (new SecurityDisabler())
{
//Find pending packages. This loop may not complete if there were binary/config changes
foreach (string updatePackageFilename in Directory.GetFiles(_packageSource, "*.update", SearchOption.TopDirectoryOnly).OrderBy(f => f))
{
string updatePackageFilenameStripped = updatePackageFilename.Split('\\').Last();
if (ShutdownDetected)
{
Log.Info("Install packages aborting due to shutdown", this);

if (GetInstallerState() != InstallerState.WaitingForPostSteps)
{
SetInstallerState(InstallerState.Ready);
}

break;
}

Log.Info(String.Format("Begin Installation: {0}", updatePackageFilenameStripped), this);

string installationHistoryRoot = null;
Expand Down Expand Up @@ -251,12 +256,12 @@ private void InstallPackages()
}
}
}
}

if (!ShutdownDetected)
{
//Allow additional installs
SetInstallerState(InstallerState.Ready);
if (!ShutdownDetected)
{
//Allow additional installs
SetInstallerState(InstallerState.Ready);
}
}
}
}
Expand All @@ -266,7 +271,7 @@ internal static void SetInstallerState(InstallerState installState)
Log.Info(string.Format("Setting installer state to {0}", installState), typeof(InstallPackage));

Database coreDb = Database.GetDatabase("core");
coreDb.Properties.SetIntValue(INSTALLER_STATE_PROPERTY, (int)installState);
coreDb.Properties.SetIntValue(INSTALLER_STATE_PROPERTY + Environment.MachineName, (int)installState);
}

/// <summary>
Expand All @@ -276,7 +281,7 @@ internal static void SetInstallerState(InstallerState installState)
internal static InstallerState GetInstallerState()
{
Database coreDb = Database.GetDatabase("core");
return (InstallerState)coreDb.Properties.GetIntValue(INSTALLER_STATE_PROPERTY, (int)InstallerState.Ready);
return (InstallerState)coreDb.Properties.GetIntValue(INSTALLER_STATE_PROPERTY + Environment.MachineName, (int)InstallerState.Ready);
}

/// <summary>
Expand Down

0 comments on commit 801e0fa

Please sign in to comment.