Skip to content

Commit

Permalink
Run-From-Zip readonly file mode checks (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewc committed Feb 15, 2018
1 parent 19171d6 commit 5c7c54a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ internal void EnsureInitialized(WebHostSettings settings)
_activeScriptHostConfig = CreateScriptHostConfiguration(settings);
_activeHostManager = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings);
_activeReceiverManager = new WebHookReceiverManager(_activeHostManager.SecretManager);
InitializeFileSystem();
InitializeFileSystem(_settingsManager.FileSystemIsReadOnly);

if (_standbyHostManager != null)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ internal void EnsureInitialized(WebHostSettings settings)
_standbyHostManager = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, standbySettings);
_standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager);

InitializeFileSystem();
InitializeFileSystem(_settingsManager.FileSystemIsReadOnly);
StandbyManager.Initialize(_standbyScriptHostConfig);

// start a background timer to identify when specialization happens
Expand Down Expand Up @@ -285,7 +285,7 @@ private void OnSpecializationTimerTick(object state)
_activeHostManager?.EnsureInitialized();
}

private static void InitializeFileSystem()
private static void InitializeFileSystem(bool readOnlyFileSystem)
{
if (ScriptSettingsManager.Instance.IsAzureEnvironment)
{
Expand All @@ -294,17 +294,23 @@ private static void InitializeFileSystem()
string home = ScriptSettingsManager.Instance.GetSetting(EnvironmentSettingNames.AzureWebsiteHomePath);
if (!string.IsNullOrEmpty(home))
{
// Delete hostingstart.html if any. Azure creates that in all sites by default
string siteRootPath = Path.Combine(home, @"site\wwwroot");
string hostingStart = Path.Combine(siteRootPath, "hostingstart.html");
if (File.Exists(hostingStart))
if (!readOnlyFileSystem)
{
File.Delete(hostingStart);
// Delete hostingstart.html if any. Azure creates that in all sites by default
string siteRootPath = Path.Combine(home, @"site\wwwroot");
string hostingStart = Path.Combine(siteRootPath, "hostingstart.html");
if (File.Exists(hostingStart))
{
File.Delete(hostingStart);
}
}
// Create the tools folder if it doesn't exist
string toolsPath = Path.Combine(home, @"site\tools");
Directory.CreateDirectory(toolsPath);
if (!readOnlyFileSystem)
{
// Create the tools folder if it doesn't exist
Directory.CreateDirectory(toolsPath);
}
var folders = new List<string>();
folders.Add(Path.Combine(home, @"site\tools"));
Expand Down
2 changes: 2 additions & 0 deletions src/WebJobs.Script/Config/ScriptSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static ScriptSettingsManager Instance

public bool IsDynamicSku => WebsiteSku == ScriptConstants.DynamicSku;

public bool FileSystemIsReadOnly => IsZipDeployment;

public virtual string AzureWebsiteDefaultSubdomain
{
get
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Script/Host/ScriptHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ public void Initialize()
// read host.json and apply to JobHostConfiguration
string hostConfigFilePath = Path.Combine(ScriptConfig.RootScriptPath, ScriptConstants.HostMetadataFileName);

// If it doesn't exist, create an empty JSON file
if (!File.Exists(hostConfigFilePath))
if (!_settingsManager.FileSystemIsReadOnly && !File.Exists(hostConfigFilePath))
{
// If it doesn't exist, create an empty JSON file
File.WriteAllText(hostConfigFilePath, "{}");
}

Expand Down

0 comments on commit 5c7c54a

Please sign in to comment.