@@ -532,6 +532,15 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
532
532
return xerrors .Errorf ("dial postgres: %w" , err )
533
533
}
534
534
defer sqlDB .Close ()
535
+
536
+ pingCtx , pingCancel := context .WithTimeout (ctx , 15 * time .Second )
537
+ defer pingCancel ()
538
+
539
+ err = sqlDB .PingContext (pingCtx )
540
+ if err != nil {
541
+ return xerrors .Errorf ("ping postgres: %w" , err )
542
+ }
543
+
535
544
// Ensure the PostgreSQL version is >=13.0.0!
536
545
version , err := sqlDB .QueryContext (ctx , "SHOW server_version;" )
537
546
if err != nil {
@@ -552,10 +561,6 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
552
561
}
553
562
logger .Debug (ctx , "connected to postgresql" , slog .F ("version" , versionStr ))
554
563
555
- err = sqlDB .Ping ()
556
- if err != nil {
557
- return xerrors .Errorf ("ping postgres: %w" , err )
558
- }
559
564
err = migrations .Up (sqlDB )
560
565
if err != nil {
561
566
return xerrors .Errorf ("migrate up: %w" , err )
@@ -793,9 +798,10 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
793
798
}()
794
799
795
800
hasFirstUser , err := client .HasFirstUser (ctx )
796
- if ! hasFirstUser && err == nil {
797
- cmd .Println ()
798
- cmd .Println ("Get started by creating the first user (in a new terminal):" )
801
+ if err != nil {
802
+ cmd .Println ("\n Failed to check for the first user: " + err .Error ())
803
+ } else if ! hasFirstUser {
804
+ cmd .Println ("\n Get started by creating the first user (in a new terminal):" )
799
805
cmd .Println (cliui .Styles .Code .Render ("coder login " + accessURLParsed .String ()))
800
806
}
801
807
0 commit comments