- Added Role and Environment to be cscfg configurable. ChefClient_ServerUrl, ChefClient_Role, 
        and ChefClient_Environment are now configurable from loud service config updates.
        - Add a set instance busy check file and configuarable path in ChefClient_SetBusyCheck

git-tfs-id: [http://vstfmsn:8080/tfs/MSN01]$/PubServices/Deployment/InstallationSDK/Main/src/Modules/InstallationSDK.ChefClientInstaller;C1148229
This commit is contained in:
Matt Schmidt 2015-02-08 04:11:40 +00:00
Родитель 4e5bd58e51
Коммит 6648f30f64
4 изменённых файлов: 65 добавлений и 20 удалений

Просмотреть файл

@ -86,12 +86,13 @@ function Get-ChefClientConfig
"client_key" = "";
"node_name" = "";
"chef_server_url" = "";
"encrypted_data_bag_secret" = "";
"encrypted_data_bag_secret" = "";
"validation_client_name" = "";
"validation_key" = "";
"interval" = "";
"json_attribs" = "";
"ssl_verify_mode" = ""}
"ssl_verify_mode" = "";
"environment" = "_default"}
if ($Path -and (Test-Path -Path $Path))
{

Просмотреть файл

@ -4,7 +4,7 @@
"Module": {
"Id": "461F01C0-4131-4D08-B26A-77BFA521923B",
"Name": "InstallationSDK.ChefClientInstaller",
"Version": "0.1.4",
"Version": "0.1.5",
"Author": "icechef@microsoft.com",
"CompanyName": "Microsoft",
"Description": "PowerShell Cmdlets for installing Chef-Client.",

Просмотреть файл

@ -5,6 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.OnlinePublishing.Chef
{
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using System;
using System.Diagnostics;
@ -16,6 +17,11 @@ namespace Microsoft.OnlinePublishing.Chef
/// </summary>
public static class ClientService
{
/// <summary>
/// Path to find the status check file for determining if instance should be busy
/// </summary>
private static string statusCheckFilePath;
/// <summary>
/// Stop the Chef Client windows service with the default wait time of 1 minute.
/// </summary>
@ -50,11 +56,11 @@ namespace Microsoft.OnlinePublishing.Chef
}
catch (System.ServiceProcess.TimeoutException)
{
Trace.TraceInformation("Chef Client - failed to stop Chef Client in time alloted [{0}].", timeToWait);
Trace.TraceInformation("Chef Client - failed to stop Chef Client in time allotted [{0}].", timeToWait);
}
catch (InvalidOperationException e)
{
Trace.TraceInformation("Chef Client - Invalid Operation, is the role running with elevated privledges. Ex:{0}.", e.ToString());
Trace.TraceInformation("Chef Client - Invalid Operation, is the role running with elevated privileges. Ex:{0}.", e.ToString());
}
}
@ -65,7 +71,8 @@ namespace Microsoft.OnlinePublishing.Chef
{
try
{
RoleEnvironment.Changing += ChefServerURLChanging;
RoleEnvironment.Changing += ChefConfigChanging;
RoleEnvironment.StatusCheck += Chef_StatusCheck;
// Start Chef Client - wait 30 seconds
Trace.TraceInformation("Chef Client - Attempting to start Chef-Client.");
@ -82,6 +89,8 @@ namespace Microsoft.OnlinePublishing.Chef
Trace.TraceInformation("Chef Client - Chef-Client previously running.");
}
}
ClientService.statusCheckFilePath = CloudConfigurationManager.GetSetting("ChefClient_SetBusyCheck");
}
catch (System.ServiceProcess.TimeoutException)
{
@ -89,23 +98,46 @@ namespace Microsoft.OnlinePublishing.Chef
}
catch (InvalidOperationException e)
{
Trace.TraceInformation("Chef Client - Invalid Operation, is the role running with elevated privledges. Ex:{0}.", e.ToString());
Trace.TraceInformation("Chef Client - Invalid Operation, is the role running with elevated privileges. Ex:{0}.", e.ToString());
}
}
/// <summary>
/// Handle configuration change events for ChefClient_ServerURL. This will canccel the event and force a
/// Role Restart so that the client scripts (main.ps1) will reset a new connection and client registration with the new Server.
/// Handle Azure status check events to set the role as busy if the lock file is missing.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void ChefServerURLChanging(object sender, RoleEnvironmentChangingEventArgs e)
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
static void Chef_StatusCheck(object sender, RoleInstanceStatusCheckEventArgs e)
{
if (string.IsNullOrWhiteSpace(ClientService.statusCheckFilePath) ||
System.IO.File.Exists(ClientService.statusCheckFilePath))
{
return;
}
e.SetBusy();
}
/// <summary>
/// Handle configuration change events for ChefClient_ServerURL, ChefClient_Role, or ChefClient_Environment.
/// This will cancel the event and force a Role Restart so that the client scripts (main.ps1) will reset a new
/// connection and client registration with the new Server.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private static void ChefConfigChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
var configurationChanges = e.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().ToList();
if (!configurationChanges.Any()) return;
if (configurationChanges.Any(c => c.ConfigurationSettingName == "ChefClient_ServerUrl"))
if (configurationChanges.Any(c => c.ConfigurationSettingName == "ChefClient_SetBusyCheck"))
{
ClientService.statusCheckFilePath = CloudConfigurationManager.GetSetting("ChefClient_SetBusyCheck");
}
if (configurationChanges.Any(c => c.ConfigurationSettingName == "ChefClient_ServerUrl" ||
c.ConfigurationSettingName == "ChefClient_Role" ||
c.ConfigurationSettingName == "ChefClient_Environment" ))
{
Stop(new TimeSpan(0, 0, 5));
e.Cancel = true;

Просмотреть файл

@ -90,30 +90,30 @@ if ($config -and $config.sslVerifyMode)
$encryptedDataBagSecret = Get-CloudServiceConfigurationSettingValue "ChefClient_EncryptedDataBagSecret"
if ($encryptedDataBagSecret)
{
$pathToEncryptedDataBagSecret = Join-path -Path $RootPath -ChildPath "encrypted_data_bag_secret"
$pathToEncryptedDataBagSecret = Join-path -Path $RootPath -ChildPath "encrypted_data_bag_secret"
$encryptedDataBagSecret | Set-Content -Path $pathToEncryptedDataBagSecret -Force
Write-Output "Encrypted Data Bag Secret set to: $encryptedDataBagSecret"
}
elseif ($config -and $config.encrypted_data_bag_secret_file)
{
$encryptedDataBagSecretFile = $config.encrypted_data_bag_secret_file
$encryptedDataBagSecretFile = $config.encrypted_data_bag_secret_file
# Ensure the secret exists with that filename
# Ensure the secret exists with that filename
$encryptedDataBagSecretFileTemp = Join-Path $PSScriptRoot $encryptedDataBagSecretFile
if (-not (Test-Path $encryptedDataBagSecretFileTemp))
{
throw "Did not find the encrypted_data_bag_secret at path $encryptedDataBagSecretFileTemp"
}
$pathToEncryptedDataBagSecret = Join-path -Path $RootPath -ChildPath $encryptedDataBagSecretFile
$pathToEncryptedDataBagSecret = Join-path -Path $RootPath -ChildPath $encryptedDataBagSecretFile
Copy-Item $encryptedDataBagSecretFileTemp $pathToEncryptedDataBagSecret -Force
}
if ($pathToEncryptedDataBagSecret)
{
$ClientRbObject.encrypted_data_bag_secret = $pathToEncryptedDataBagSecret
$ClientRbObject.encrypted_data_bag_secret = $pathToEncryptedDataBagSecret
Write-Output "Set encrypted_data_bag to: $pathToEncryptedDataBagSecret"
}
@ -240,11 +240,16 @@ else
Write-Output "chef url not set in configuration file. Node will not register with Chef Server."
}
# Value from Cloud Service CsCfg always wins.
$chefRole = Get-CloudServiceConfigurationSettingValue "ChefClient_Role"
# Create first-run-bootstrap.json to register new node with Chef Server
if ($config -and $config.role)
if ($chefRole -or ($config -and $config.role))
{
# Register with the correct update domain role [role name]
$chefRole = $($config.role)
if (-not $chefRole)
{
$chefRole = $($config.role)
}
$bootStrapperFile = "first-run-bootstrap.json"
$bootStrapper = "{`r`n `"run_list`": [ `"role[$chefRole]`" ]`r`n}"
Write-Output "Setting bootstrap content: $bootStrapper"
@ -256,6 +261,13 @@ if ($config -and $config.role)
Write-Output "Set bootstrapper path to: '$pathToBootStrapper'"
}
# Value from Cloud Service CsCfg always wins.
$chefEnvironment = Get-CloudServiceConfigurationSettingValue "ChefClient_Environment"
if ($chefEnvironment)
{
$ClientRbObject.environment = $chefEnvironment
}
Copy-Item -Path $TemplateClientRb -Destination $pathToClientRb -Force
$ClientRbObject | Save-ChefClientConfig -Path $pathToClientRb -Append