@@ -21,7 +21,7 @@ namespace Microsoft.Azure.WebJobs.Script
21
21
public class ScriptHost : JobHost
22
22
{
23
23
private const string HostAssemblyName = "ScriptHost" ;
24
- private const string HostFileName = "host.json" ;
24
+ private const string HostConfigFileName = "host.json" ;
25
25
internal const string FunctionConfigFileName = "function.json" ;
26
26
private readonly TraceWriter _traceWriter ;
27
27
private readonly AutoResetEvent _restartEvent = new AutoResetEvent ( false ) ;
@@ -125,7 +125,14 @@ protected virtual void Initialize()
125
125
}
126
126
127
127
// 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
+
129
136
_traceWriter . Verbose ( string . Format ( "Reading host configuration file '{0}'" , hostConfigFilePath ) ) ;
130
137
string json = File . ReadAllText ( hostConfigFilePath ) ;
131
138
JObject hostConfig = JObject . Parse ( json ) ;
@@ -370,12 +377,16 @@ internal static void ApplyConfiguration(JObject config, ScriptHostConfiguration
370
377
{
371
378
JobHostConfiguration hostConfig = scriptConfig . HostConfig ;
372
379
380
+ // We may already have a host id, but the one from the JSON takes precedence
373
381
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 )
375
387
{
376
388
throw new InvalidOperationException ( "An 'id' must be specified in the host configuration." ) ;
377
389
}
378
- hostConfig . HostId = ( string ) hostId ;
379
390
380
391
JToken watchFiles = ( JToken ) config [ "watchFiles" ] ;
381
392
if ( watchFiles != null && watchFiles . Type == JTokenType . Boolean )
@@ -465,7 +476,7 @@ private void OnFileChanged(object sender, FileSystemEventArgs e)
465
476
{
466
477
string fileName = Path . GetFileName ( e . Name ) ;
467
478
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 ) ||
469
480
( ( Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) . Count ( ) != _directoryCountSnapshot ) ) )
470
481
{
471
482
// a host level configuration change has been made which requires a
0 commit comments