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 26, 2018
1 parent 80b720b commit 402e26c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
30 changes: 18 additions & 12 deletions src/WebJobs.Script.WebHost/WebHostResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internal void EnsureInitialized(WebHostSettings settings)
_activeHostManager = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings,
_router, loggerProviderFactory: _loggerProviderFactory, loggerFactory: _loggerFactory);
//_activeReceiverManager = new WebHookReceiverManager(_activeHostManager.SecretManager);
InitializeFileSystem();
InitializeFileSystem(_settingsManager.FileSystemIsReadOnly);

if (_standbyHostManager != null)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ internal void EnsureInitialized(WebHostSettings settings)
_router, loggerProviderFactory: _loggerProviderFactory, loggerFactory: _loggerFactory);
// _standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager);

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

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

private static void InitializeFileSystem()
private static void InitializeFileSystem(bool readOnlyFileSystem)
{
if (ScriptSettingsManager.Instance.IsAzureEnvironment)
{
Expand All @@ -258,20 +258,26 @@ 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);
string toolsPath = Path.Combine(home, @"site\tools");
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"));
folders.Add(Path.Combine(home, @"site\tools"));

string path = Environment.GetEnvironmentVariable("PATH");
string additionalPaths = string.Join(";", folders);
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 @@ -40,6 +40,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 @@ -292,9 +292,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 402e26c

Please sign in to comment.