Skip to content

Commit

Permalink
Merge OnDemand branch into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cturano committed Apr 1, 2016
2 parents 50230de + b8be7d8 commit 13961a9
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@
#*.rtf diff=astextplain
#*.RTF diff=astextplain

*.item -text

# Do not adjust line endings on Sitecore .item files
*.item -text
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ If there are changes to the Sitecore configs or binaries during the installation

If Sitecore is restarting, the Sitecore Package Deployer will make an HTTP request to the cms website just before shutting down to attempt to restart the server automatically. In some cases, the url for the server can't be determined, so the url from the setting **SitecorePackageDeployer.RestartUrl** is used instead.

Upon completion of the package install, the package deployer will deposit a .json file in the Sitecore Package Deployer folder with the same name as the update package. This .json file contains the results of the package installation. The contents look something like:

{
"Status": "Success",
"ServerName": "[Server]",
"DeployHistoryPath": "[Path to Sitecore]\\Website\\temp\\__UpgradeHistory\\Upgrade_TestUpdatePackage_20160401_1316_20160401T171959991"
}

# Config files
One of the most popular questions the TDS support team receives about update packages questions the way Sitecore handles config files. When the update package installer determines that a config file needs to be replaced, the Sitecore installer creates config with a new name and leaves the original file in place. The replacement of the file is done manually by the developer performing the install. This makes it much more difficult to automate the installation process.

To make the deployment fully automatic, the Sitecore Package Deployer finds the new .config file(s), makes a backup of the existing .config file(s) and performs the replacement automatically. This happens before the post steps are run, and will cause the AppPool to recycle.

# On Demand Deployment
The package deployer can also run in an "On Demand" mode. This allows you to have more control over when the deployer runs. To use On Demand mode, you need to do two things:

1. Remove the scheduled job line in the config file
1. Have the ability to make an Http request to the url [server]/sitecore/admin/StartSitecorePackageDeployer.aspx


# Installing the Sitecore Package Deployer
The update package installer can be downloaded as an update package from [here](https://github.com/HedgehogDevelopment/SitecorePackageDeployer/blob/master/Hhogdev.SitecorePackageDeployer_v1.0.update?raw=true). This is an update package and can be installed using the Update Installation Wizard in Sitecore. Once it is installed, the deploy folder will automatically be created in the default location of **$(dataFolder)\SitecorePackageDeployer**. Simply drop your update packages in that location and they will be automatically installed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</pipelines>
<scheduling>
<!-- Agent to install update packages -->
<!-- Comment this out if using the OnDemand url to install a package -->
<agent type="Hhogdev.SitecorePackageDeployer.Tasks.InstallPackage, Hhogdev.SitecorePackageDeployer" method="Run" interval="00:01:00"/>
</scheduling>
<settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="sitecore\admin\StartSitecorePackageDeployer.aspx.cs">
<DependentUpon>StartSitecorePackageDeployer.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="sitecore\admin\StartSitecorePackageDeployer.aspx.designer.cs">
<DependentUpon>StartSitecorePackageDeployer.aspx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="App_Config\Include\Hhogdev.SitecorePackageDeployer.config">
<SubType>Designer</SubType>
</Content>
<Content Include="sitecore\admin\StartSitecorePackageDeployer.aspx" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SitecorePackageDeployer\Hhogdev.SitecorePackageDeployer.csproj">
Expand Down Expand Up @@ -99,7 +107,8 @@
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
<PostBuildEvent>del "$(TargetDir)$(TargetName).*"</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StartSitecorePackageDeployer.aspx.cs" Inherits="Hhogdev.SitecorePackageDeployer.Web.sitecore.admin.StartSitecorePackageDeployer" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Sitecore Package Deployer started
</div>
</form>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Hhogdev.SitecorePackageDeployer.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hhogdev.SitecorePackageDeployer.Web.sitecore.admin
{
public partial class StartSitecorePackageDeployer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem((ctx) =>
{
InstallPackage installer = new InstallPackage();
installer.Run();
});
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<HintPath>..\packages\SitecoreKernel.7.0.0.131127\lib\Lucene.Net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.Kernel, Version=7.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SitecoreKernel.7.0.0.131127\lib\Sitecore.Kernel.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -66,6 +71,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Logging\InstallLogger.cs" />
<Compile Include="Metadata\CompletionNotification.cs" />
<Compile Include="Metadata\PostStepDetails.cs" />
<Compile Include="Pipelines\Initialize\RunPostInstallSteps.cs" />
<Compile Include="Pipelines\Shutdown\ShutdownIndicator.cs" />
Expand Down
16 changes: 16 additions & 0 deletions SitecorePackageDeployer/Metadata/CompletionNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hhogdev.SitecorePackageDeployer.Metadata
{
[Serializable]
public class CompletionNotification
{
public string Status { get; set; }
public string ServerName { get; set; }
public string DeployHistoryPath { get; set; }
}
}
1 change: 1 addition & 0 deletions SitecorePackageDeployer/Metadata/PostStepDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class PostStepDetails
{
public string PostStepPackageFilename { get; set; }
public string HistoryPath { get; set; }
public string ResultFileName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Sitecore.SecurityModel;
using System;
using System.IO;
using System.Threading;
using System.Xml.Serialization;

namespace Hhogdev.SitecorePackageDeployer.Pipelines.Initialize
Expand All @@ -32,13 +33,24 @@ public void Process(PipelineArgs args)
try
{
RunPostInitializeStepsIfNeeded();

InstallAdditionalPackages();
}
catch(Exception ex)
{
Log.Error("Failed to complete post initialize steps", ex, this);
}
}

private void InstallAdditionalPackages()
{
ThreadPool.QueueUserWorkItem((ctx) =>
{
InstallPackage installer = new InstallPackage();
installer.Run();
});
}

private void RunPostInitializeStepsIfNeeded()
{
string startupPostStepPackageFile = Path.Combine(_packageSource, InstallPackage.STARTUP_POST_STEP_PACKAGE_FILENAME);
Expand All @@ -63,6 +75,14 @@ private void RunPostInitializeStepsIfNeeded()
try
{
InstallPackage.ExecutePostSteps(installLogger, details);

InstallPackage.NotifiyPackageComplete(InstallPackage.SUCCESS, details);
}
catch(Exception ex)
{
Log.Fatal("An error occured when running post steps", ex, this);

InstallPackage.NotifiyPackageComplete(InstallPackage.FAIL, details);
}
finally
{
Expand Down
64 changes: 51 additions & 13 deletions SitecorePackageDeployer/Tasks/InstallPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace Hhogdev.SitecorePackageDeployer.Tasks
public class InstallPackage
{
internal const string STARTUP_POST_STEP_PACKAGE_FILENAME = "StartPostStepPackage.xml";
internal const string SUCCESS = "Success";
internal const string FAIL = "Fail";

//Points at the folder where new packages will be stored
string _packageSource;
Expand Down Expand Up @@ -122,10 +124,19 @@ private void InstallPackages()
string installationHistoryRoot = null;
List<ContingencyEntry> logMessages = new List<ContingencyEntry>();

PostStepDetails postStepDetails = new PostStepDetails
{
PostStepPackageFilename = updatePackageFilename,
ResultFileName = Path.Combine(Path.GetDirectoryName(updatePackageFilename), Path.GetFileNameWithoutExtension(updatePackageFilename) + ".json")
};

string installStatus = null;

try
{
//Run the installer
logMessages = UpdateHelper.Install(installationInfo, installLogger, out installationHistoryRoot);
postStepDetails.HistoryPath = installationHistoryRoot;

if (_updateConfigurationFiles)
{
Expand All @@ -138,23 +149,22 @@ private void InstallPackages()
//Abort if Sitecore is shutting down. The install post steps will have to be completed later
if (ShutdownDetected)
{
RunPostStepsAtStartup(updatePackageFilename, installationHistoryRoot);
RunPostStepsAtStartup(updatePackageFilename, installationHistoryRoot, postStepDetails);

RestartSitecoreServer();

break;
}
else
{
ExecutePostSteps(installLogger, new PostStepDetails
{
HistoryPath = installationHistoryRoot,
PostStepPackageFilename = updatePackageFilename
});
ExecutePostSteps(installLogger, postStepDetails);
installStatus = SUCCESS;
}
}
catch (PostStepInstallerException ex)
{
installStatus = FAIL;

logMessages = ex.Entries;
installationHistoryRoot = ex.HistoryPath;
installLogger.Fatal("Package install failed", ex);
Expand All @@ -163,6 +173,7 @@ private void InstallPackages()
}
catch (Exception ex)
{
installStatus = FAIL;
Log.Error("Package install failed", ex, this);
installLogger.Fatal("Package install failed", ex);

Expand Down Expand Up @@ -196,6 +207,12 @@ private void InstallPackages()

SaveInstallationMessages(installationHistoryRoot, logMessages);
}

//Send the status if there is one
if (installStatus != null)
{
NotifiyPackageComplete(installStatus, postStepDetails);
}
}
}
}
Expand Down Expand Up @@ -241,7 +258,7 @@ private void RestartSitecoreServer()
/// </summary>
/// <param name="updatePackageFilename"></param>
/// <param name="historyPath"></param>
private void RunPostStepsAtStartup(string updatePackageFilename, string historyPath)
private void RunPostStepsAtStartup(string updatePackageFilename, string historyPath, PostStepDetails details)
{
string startupPostStepPackageFile = Path.Combine(_packageSource, STARTUP_POST_STEP_PACKAGE_FILENAME);

Expand All @@ -251,12 +268,6 @@ private void RunPostStepsAtStartup(string updatePackageFilename, string historyP
File.Delete(startupPostStepPackageFile);
}

PostStepDetails details = new PostStepDetails
{
HistoryPath = historyPath,
PostStepPackageFilename = updatePackageFilename,
};

XmlSerializer serializer = new XmlSerializer(typeof(PostStepDetails));
using (TextWriter writer = new StreamWriter(startupPostStepPackageFile))
{
Expand Down Expand Up @@ -373,5 +384,32 @@ private void SaveInstallationMessages(string installationHistoryRoot, List<Conti
Log.Fatal("Error saving installation messages", ex, typeof(InstallPackage));
}
}

/// <summary>
/// Writes the notification .json to the install folder
/// </summary>
/// <param name="status"></param>
/// <param name="postStepDetails"></param>
public static void NotifiyPackageComplete(string status, PostStepDetails postStepDetails)
{
try
{
using (StreamWriter sw = File.CreateText(postStepDetails.ResultFileName))
{
CompletionNotification completionNotification = new CompletionNotification
{
Status = status,
ServerName = Environment.MachineName,
DeployHistoryPath = postStepDetails.HistoryPath
};

sw.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(completionNotification));
}
}
catch(Exception ex)
{
Log.Fatal("Error posting to notification url", ex, typeof(InstallPackage));
}
}
}
}
1 change: 1 addition & 0 deletions SitecorePackageDeployer/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="SitecoreKernel" version="7.0.0.131127" targetFramework="net45" />
</packages>
12 changes: 12 additions & 0 deletions TestUpdatePackage/TestUpdatePackage.scproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,17 @@
<ItemDeployment>DeployOnce</ItemDeployment>
</SitecoreItem>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PostDeployAction Include="HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor.BuiltIn.PublishDeployedItems, HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor">
<Parameter>Internet</Parameter>
<Order>3</Order>
</PostDeployAction>
<PostDeployAction Include="HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor.BuiltIn.TriggerSaveEventsForPublishedItems, HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor">
<Order>1</Order>
</PostDeployAction>
<PostDeployAction Include="HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor.BuiltIn.UpdateLinkDatabaseForDeployedItems, HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor">
<Order>2</Order>
</PostDeployAction>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets" Condition="Exists('$(MSBuildExtensionsPath)\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets')" />
</Project>

0 comments on commit 13961a9

Please sign in to comment.