|
2 | 2 | // Licensed under the MIT License. See License.txt in the project root for license information. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections.Generic; |
5 | 6 | using System.IO; |
6 | 7 | using System.Linq; |
7 | 8 | using System.Reflection; |
| 9 | +using System.Threading.Tasks; |
8 | 10 | using Microsoft.Azure.WebJobs.Script.Config; |
9 | 11 | using Microsoft.Azure.WebJobs.Script.WebHost.WebHooks; |
10 | 12 |
|
@@ -110,7 +112,7 @@ private void EnsureInitialized(WebHostSettings settings) |
110 | 112 | _activeSecretManager = GetSecretManager(_settingsManager, settings.SecretsPath); |
111 | 113 | _activeReceiverManager = new WebHookReceiverManager(_activeSecretManager); |
112 | 114 | _activeHostManager = new WebScriptHostManager(_activeScriptHostConfig, _activeSecretManager, _settingsManager, settings); |
113 | | - |
| 115 | + |
114 | 116 | (_standbySecretManager as IDisposable)?.Dispose(); |
115 | 117 | _standbyHostManager?.Dispose(); |
116 | 118 | _standbyReceiverManager?.Dispose(); |
@@ -149,22 +151,7 @@ private static void ReinitializeAppSettings() |
149 | 151 |
|
150 | 152 | private static ScriptHostConfiguration GetScriptHostConfiguration(string scriptPath, string logPath) |
151 | 153 | { |
152 | | - string home = _settingsManager.GetSetting(EnvironmentSettingNames.AzureWebsiteHomePath); |
153 | | - if (!string.IsNullOrEmpty(home)) |
154 | | - { |
155 | | - // Create the tools folder if it doesn't exist |
156 | | - string toolsPath = Path.Combine(home, @"site\tools"); |
157 | | - Directory.CreateDirectory(toolsPath); |
158 | | - } |
159 | | - |
160 | | - Directory.CreateDirectory(scriptPath); |
161 | | - |
162 | | - // Delete hostingstart.html if any. Azure creates that in all sites by default |
163 | | - string hostingStart = Path.Combine(scriptPath, "hostingstart.html"); |
164 | | - if (File.Exists(hostingStart)) |
165 | | - { |
166 | | - File.Delete(hostingStart); |
167 | | - } |
| 154 | + InitializeFileSystem(scriptPath); |
168 | 155 |
|
169 | 156 | var scriptHostConfig = new ScriptHostConfiguration() |
170 | 157 | { |
@@ -193,6 +180,50 @@ private static ScriptHostConfiguration GetScriptHostConfiguration(string scriptP |
193 | 180 | return scriptHostConfig; |
194 | 181 | } |
195 | 182 |
|
| 183 | + private static void InitializeFileSystem(string scriptPath) |
| 184 | + { |
| 185 | + if (ScriptSettingsManager.Instance.IsAzureEnvironment) |
| 186 | + { |
| 187 | + // When running on Azure, we kick this off on the background |
| 188 | + Task.Run(() => |
| 189 | + { |
| 190 | + string home = ScriptSettingsManager.Instance.GetSetting(EnvironmentSettingNames.AzureWebsiteHomePath); |
| 191 | + if (!string.IsNullOrEmpty(home)) |
| 192 | + { |
| 193 | + // Delete hostingstart.html if any. Azure creates that in all sites by default |
| 194 | + string hostingStart = Path.Combine(scriptPath, "hostingstart.html"); |
| 195 | + if (File.Exists(hostingStart)) |
| 196 | + { |
| 197 | + File.Delete(hostingStart); |
| 198 | + } |
| 199 | + |
| 200 | + // Create the tools folder if it doesn't exist |
| 201 | + string toolsPath = Path.Combine(home, @"site\tools"); |
| 202 | + Directory.CreateDirectory(toolsPath); |
| 203 | + |
| 204 | + var folders = new List<string>(); |
| 205 | + folders.Add(Path.Combine(home, @"site\tools")); |
| 206 | + |
| 207 | + string path = Environment.GetEnvironmentVariable("PATH"); |
| 208 | + string additionalPaths = String.Join(";", folders); |
| 209 | + |
| 210 | + // Make sure we haven't already added them. This can happen if the appdomain restart (since it's still same process) |
| 211 | + if (!path.Contains(additionalPaths)) |
| 212 | + { |
| 213 | + path = additionalPaths + ";" + path; |
| 214 | + |
| 215 | + Environment.SetEnvironmentVariable("PATH", path); |
| 216 | + } |
| 217 | + } |
| 218 | + }); |
| 219 | + } |
| 220 | + else |
| 221 | + { |
| 222 | + // Ensure we have our scripts directory in non-Azure scenarios |
| 223 | + Directory.CreateDirectory(scriptPath); |
| 224 | + } |
| 225 | + } |
| 226 | + |
196 | 227 | private static ISecretManager GetSecretManager(ScriptSettingsManager settingsManager, string secretsPath) => new SecretManager(settingsManager, secretsPath); |
197 | 228 |
|
198 | 229 | public void Dispose() |
|
0 commit comments