@@ -315,6 +315,8 @@ func indexConfigObjects(ptr any, configPath string, index map[string]string) err
315
315
// allowPersist is false, it will not be persisted to disk,
316
316
// even if it is configured to.
317
317
func unsyncedDecodeAndRun (cfgJSON []byte , allowPersist bool ) error {
318
+ fmt .Println ("[unsyncedDecodeAndRun] Into" )
319
+
318
320
// remove any @id fields from the JSON, which would cause
319
321
// loading to break since the field wouldn't be recognized
320
322
strippedCfgJSON := RemoveMetaFields (cfgJSON )
@@ -339,21 +341,31 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
339
341
return fmt .Errorf ("recursive config loading detected: pulled configs cannot pull other configs without positive load_delay" )
340
342
}
341
343
344
+ fmt .Println ("[unsyncedDecodeAndRun] before run()" )
345
+
342
346
// run the new config and start all its apps
343
347
ctx , err := run (newCfg , true )
344
348
if err != nil {
345
349
return err
346
350
}
347
351
352
+ fmt .Println ("[unsyncedDecodeAndRun] after run()" )
353
+ fmt .Println ("[unsyncedDecodeAndRun] newCfg:" , newCfg )
354
+
348
355
// swap old context (including its config) with the new one
349
356
currentCtxMu .Lock ()
350
357
oldCtx := currentCtx
351
358
currentCtx = ctx
352
359
currentCtxMu .Unlock ()
353
360
361
+ fmt .Println ("[unsyncedDecodeAndRun] before unsyncedStop(), oldCtx:" , oldCtx )
362
+
354
363
// Stop, Cleanup each old app
355
364
unsyncedStop (oldCtx )
356
365
366
+ fmt .Println ("[unsyncedDecodeAndRun] after unsyncedStop()" )
367
+ fmt .Println ("=============" )
368
+
357
369
// autosave a non-nil config, if not disabled
358
370
if allowPersist &&
359
371
newCfg != nil &&
@@ -379,6 +391,9 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
379
391
}
380
392
}
381
393
394
+ fmt .Println ("[unsyncedDecodeAndRun] after autosave config" )
395
+ fmt .Println ("=============/" )
396
+
382
397
return nil
383
398
}
384
399
@@ -397,7 +412,22 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
397
412
// will want to use Run instead, which also
398
413
// updates the config's raw state.
399
414
func run (newCfg * Config , start bool ) (Context , error ) {
415
+ fmt .Println ("----------" )
416
+ fmt .Println ("[run] Into" )
417
+
418
+ fmt .Println ("----------" )
419
+ fmt .Println ("Before provisionContext()" )
420
+ fmt .Println ("----------" )
421
+
400
422
ctx , err := provisionContext (newCfg , start )
423
+
424
+ fmt .Println ("----------" )
425
+ fmt .Println ("After provisionContext()" )
426
+ fmt .Println ("----------" )
427
+
428
+ // {context.Background.WithCancel map[events:[0xc0007039e0] http:[0xc0003f86c0] http.matchers.host:[0xc0002a4240] tls:[0xc0000cfe00]] 0xc0003a08a0 [] [] []}
429
+ fmt .Println ("[run] ctx:" , ctx )
430
+
401
431
if err != nil {
402
432
return ctx , err
403
433
}
@@ -413,11 +443,18 @@ func run(newCfg *Config, start bool) (Context, error) {
413
443
return ctx , err
414
444
}
415
445
446
+ fmt .Println ("[run] provisionAdminRouters after" )
447
+ fmt .Println ("----------" )
448
+
416
449
// Start
417
450
err = func () error {
418
451
started := make ([]string , 0 , len (ctx .cfg .apps ))
419
452
for name , a := range ctx .cfg .apps {
420
453
err := a .Start ()
454
+
455
+ fmt .Println ("[run]" , name , "Started" )
456
+ fmt .Println ("----------/" )
457
+
421
458
if err != nil {
422
459
// an app failed to start, so we need to stop
423
460
// all other apps that were already started
@@ -438,6 +475,9 @@ func run(newCfg *Config, start bool) (Context, error) {
438
475
return ctx , err
439
476
}
440
477
478
+ fmt .Println ("[run] Before finishSettingUp" )
479
+ fmt .Println ("[run] ctx.cfg :" , ctx .cfg )
480
+
441
481
// now that the user's config is running, finish setting up anything else,
442
482
// such as remote admin endpoint, config loader, etc.
443
483
return ctx , finishSettingUp (ctx , ctx .cfg )
@@ -509,6 +549,8 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
509
549
// prepare the new config for use
510
550
newCfg .apps = make (map [string ]App )
511
551
552
+ fmt .Println ("[provisionContext] set up global storage Before" )
553
+
512
554
// set up global storage and make it CertMagic's default storage, too
513
555
err = func () error {
514
556
if newCfg .StorageRaw != nil {
@@ -534,15 +576,22 @@ func provisionContext(newCfg *Config, replaceAdminServer bool) (Context, error)
534
576
return ctx , err
535
577
}
536
578
579
+ fmt .Println ("[provisionContext] set up global storage After" )
580
+ fmt .Println ("[provisionContext] Load and Provision each app and their submodules Before" )
581
+
537
582
// Load and Provision each app and their submodules
538
583
err = func () error {
539
584
for appName := range newCfg .AppsRaw {
585
+ fmt .Println ("appName:" , appName )
540
586
if _ , err := ctx .App (appName ); err != nil {
541
587
return err
542
588
}
543
589
}
544
590
return nil
545
591
}()
592
+
593
+ fmt .Println ("[provisionContext] Load and Provision each app and their submodules After" )
594
+
546
595
return ctx , err
547
596
}
548
597
@@ -557,6 +606,9 @@ func ProvisionContext(newCfg *Config) (Context, error) {
557
606
558
607
// finishSettingUp should be run after all apps have successfully started.
559
608
func finishSettingUp (ctx Context , cfg * Config ) error {
609
+ fmt .Println ("----====----" )
610
+ fmt .Println ("[finishSettingUp] Into" )
611
+
560
612
// establish this server's identity (only after apps are loaded
561
613
// so that cert management of this endpoint doesn't prevent user's
562
614
// servers from starting which likely also use HTTP/HTTPS ports;
@@ -566,14 +618,23 @@ func finishSettingUp(ctx Context, cfg *Config) error {
566
618
return fmt .Errorf ("provisioning remote admin endpoint: %v" , err )
567
619
}
568
620
621
+ fmt .Println ("[finishSettingUp] replaceRemoteAdminServer before" )
622
+
569
623
// replace any remote admin endpoint
570
624
err = replaceRemoteAdminServer (ctx , cfg )
571
625
if err != nil {
572
626
return fmt .Errorf ("provisioning remote admin endpoint: %v" , err )
573
627
}
574
628
629
+ fmt .Println ("[finishSettingUp] replaceRemoteAdminServer after" )
630
+ fmt .Println ("[finishSettingUp] The cfg:" , cfg )
631
+ fmt .Println ("[finishSettingUp] cfg.Admin:" , cfg .Admin )
632
+ fmt .Println ("[finishSettingUp] cfg.Admin.Config:" , cfg .Admin .Config )
633
+
575
634
// if dynamic config is requested, set that up and run it
576
635
if cfg != nil && cfg .Admin != nil && cfg .Admin .Config != nil && cfg .Admin .Config .LoadRaw != nil {
636
+ fmt .Println ("[finishSettingUp] cfg.Admin.Config.LoadDelay =" , cfg .Admin .Config .LoadDelay )
637
+
577
638
val , err := ctx .LoadModule (cfg .Admin .Config , "LoadRaw" )
578
639
if err != nil {
579
640
return fmt .Errorf ("loading config loader module: %s" , err )
@@ -639,6 +700,8 @@ func finishSettingUp(ctx Context, cfg *Config) error {
639
700
}
640
701
}
641
702
703
+ fmt .Println ("----====----/" )
704
+
642
705
return nil
643
706
}
644
707
0 commit comments