@@ -21,7 +21,7 @@ namespace Microsoft.Azure.WebJobs.Script
2121 public class ScriptHost : JobHost
2222 {
2323 private const string HostAssemblyName = "ScriptHost" ;
24- private const string HostFileName = "host.json" ;
24+ private const string HostConfigFileName = "host.json" ;
2525 internal const string FunctionConfigFileName = "function.json" ;
2626 private readonly TraceWriter _traceWriter ;
2727 private readonly AutoResetEvent _restartEvent = new AutoResetEvent ( false ) ;
@@ -125,7 +125,14 @@ protected virtual void Initialize()
125125 }
126126
127127 // read host.json and apply to JobHostConfiguration
128- string hostConfigFilePath = Path . Combine ( ScriptConfig . RootScriptPath , HostFileName ) ;
128+ string hostConfigFilePath = Path . Combine ( ScriptConfig . RootScriptPath , HostConfigFileName ) ;
129+
130+ // If it doesn't exist, create an empty JSON file
131+ if ( ! File . Exists ( hostConfigFilePath ) )
132+ {
133+ File . WriteAllText ( hostConfigFilePath , "{}" ) ;
134+ }
135+
129136 _traceWriter . Verbose ( string . Format ( "Reading host configuration file '{0}'" , hostConfigFilePath ) ) ;
130137 string json = File . ReadAllText ( hostConfigFilePath ) ;
131138 JObject hostConfig = JObject . Parse ( json ) ;
@@ -370,12 +377,16 @@ internal static void ApplyConfiguration(JObject config, ScriptHostConfiguration
370377 {
371378 JobHostConfiguration hostConfig = scriptConfig . HostConfig ;
372379
380+ // We may already have a host id, but the one from the JSON takes precedence
373381 JToken hostId = ( JToken ) config [ "id" ] ;
374- if ( hostId == null )
382+ if ( hostId != null )
383+ {
384+ hostConfig . HostId = ( string ) hostId ;
385+ }
386+ else if ( hostConfig . HostId == null )
375387 {
376388 throw new InvalidOperationException ( "An 'id' must be specified in the host configuration." ) ;
377389 }
378- hostConfig . HostId = ( string ) hostId ;
379390
380391 JToken watchFiles = ( JToken ) config [ "watchFiles" ] ;
381392 if ( watchFiles != null && watchFiles . Type == JTokenType . Boolean )
@@ -465,7 +476,7 @@ private void OnFileChanged(object sender, FileSystemEventArgs e)
465476 {
466477 string fileName = Path . GetFileName ( e . Name ) ;
467478
468- if ( ( ( string . Compare ( fileName , HostFileName , ignoreCase : true ) == 0 ) || string . Compare ( fileName , FunctionConfigFileName , ignoreCase : true ) == 0 ) ||
479+ if ( ( ( string . Compare ( fileName , HostConfigFileName , ignoreCase : true ) == 0 ) || string . Compare ( fileName , FunctionConfigFileName , ignoreCase : true ) == 0 ) ||
469480 ( ( Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) . Count ( ) != _directoryCountSnapshot ) ) )
470481 {
471482 // a host level configuration change has been made which requires a
0 commit comments