@@ -115,13 +115,14 @@ func NewLocalUpdater(cfg LocalUpdaterConfig, ns *Namespace) (*Updater, error) {
115
115
validator := Validator {Log : cfg .Log }
116
116
debugClient := debug .NewClient (filepath .Join (ns .dataDir , debugSocketFileName ))
117
117
return & Updater {
118
- Log : cfg .Log ,
119
- Pool : certPool ,
120
- InsecureSkipVerify : cfg .InsecureSkipVerify ,
121
- UpdateConfigFile : filepath .Join (ns .Dir (), updateConfigName ),
122
- TeleportConfigFile : ns .configFile ,
123
- DefaultProxyAddr : ns .defaultProxyAddr ,
124
- DefaultPathDir : ns .defaultPathDir ,
118
+ Log : cfg .Log ,
119
+ Pool : certPool ,
120
+ InsecureSkipVerify : cfg .InsecureSkipVerify ,
121
+ UpdateConfigFile : filepath .Join (ns .Dir (), updateConfigName ),
122
+ TeleportConfigFile : ns .configFile ,
123
+ TeleportServiceName : filepath .Base (ns .serviceFile ),
124
+ DefaultProxyAddr : ns .defaultProxyAddr ,
125
+ DefaultPathDir : ns .defaultPathDir ,
125
126
Installer : & LocalInstaller {
126
127
InstallDir : filepath .Join (ns .Dir (), versionsDirName ),
127
128
TargetServiceFile : ns .serviceFile ,
@@ -204,6 +205,8 @@ type Updater struct {
204
205
UpdateConfigFile string
205
206
// TeleportConfigFile contains the path to Teleport's configuration.
206
207
TeleportConfigFile string
208
+ // TeleportServiceName contains the full name of the systemd service for Teleport
209
+ TeleportServiceName string
207
210
// DefaultProxyAddr contains Teleport's proxy address. This may differ from the updater's.
208
211
DefaultProxyAddr string
209
212
// DefaultPathDir contains the default path that Teleport binaries should be installed into.
@@ -274,6 +277,8 @@ var (
274
277
ErrNoBinaries = errors .New ("no binaries available to link" )
275
278
// ErrFilePresent is returned when a file is present.
276
279
ErrFilePresent = errors .New ("file present" )
280
+ // ErrNotInstalled is returned when Teleport is not installed.
281
+ ErrNotInstalled = errors .New ("not installed" )
277
282
)
278
283
279
284
// Process provides an API for interacting with a running Teleport process.
@@ -446,19 +451,40 @@ func (u *Updater) Remove(ctx context.Context, force bool) error {
446
451
}
447
452
448
453
// Do not link system package installation if the installation we are removing
449
- // is not installed into /usr/local/bin.
454
+ // is not installed into /usr/local/bin. In this case, we also need to make sure
455
+ // it is clear we are not going to recover the package's systemd service if it
456
+ // was overwritten.
450
457
if filepath .Clean (cfg .Spec .Path ) != filepath .Clean (defaultPathDir ) {
451
- return u .removeWithoutSystem (ctx , cfg , force )
458
+ if u .TeleportServiceName == serviceName {
459
+ if ! force {
460
+ u .Log .ErrorContext (ctx , "Default Teleport systemd service would be removed, and --force was not passed." )
461
+ u .Log .ErrorContext (ctx , "Refusing to remove Teleport from this system." )
462
+ return trace .Errorf ("unable to remove Teleport completely without --force" )
463
+ } else {
464
+ u .Log .WarnContext (ctx , "Default Teleport systemd service will be removed since --force was passed." )
465
+ u .Log .WarnContext (ctx , "Teleport will be removed from this system." )
466
+ }
467
+ }
468
+ return u .removeWithoutSystem (ctx , cfg )
452
469
}
453
470
revert , err := u .Installer .LinkSystem (ctx )
454
471
if errors .Is (err , ErrNoBinaries ) {
455
- return u .removeWithoutSystem (ctx , cfg , force )
472
+ if ! force {
473
+ u .Log .ErrorContext (ctx , "No packaged installation of Teleport was found, and --force was not passed." )
474
+ u .Log .ErrorContext (ctx , "Refusing to remove Teleport from this system." )
475
+ return trace .Errorf ("unable to remove Teleport completely without --force" )
476
+ } else {
477
+ u .Log .WarnContext (ctx , "No packaged installation of Teleport was found, and --force was passed." )
478
+ u .Log .WarnContext (ctx , "Teleport will be removed from this system." )
479
+ }
480
+ return u .removeWithoutSystem (ctx , cfg )
456
481
}
457
482
if err != nil {
458
483
return trace .Wrap (err , "failed to link" )
459
484
}
460
485
461
- u .Log .InfoContext (ctx , "Updater-managed installation of Teleport detected. Restoring packaged version of Teleport before removing." )
486
+ u .Log .InfoContext (ctx , "Updater-managed installation of Teleport detected." )
487
+ u .Log .InfoContext (ctx , "Restoring packaged version of Teleport before removing." )
462
488
463
489
revertConfig := func (ctx context.Context ) bool {
464
490
if ok := revert (ctx ); ! ok {
@@ -504,7 +530,8 @@ func (u *Updater) Remove(ctx context.Context, force bool) error {
504
530
u .Log .ErrorContext (ctx , "Reverting symlinks due to failed restart." )
505
531
if ok := revertConfig (ctx ); ok {
506
532
if err := u .Process .Reload (ctx ); err != nil && ! errors .Is (err , ErrNotNeeded ) {
507
- u .Log .ErrorContext (ctx , "Failed to reload Teleport after reverting. Installation likely broken." , errorKey , err )
533
+ u .Log .ErrorContext (ctx , "Failed to reload Teleport after reverting." , errorKey , err )
534
+ u .Log .ErrorContext (ctx , "Installation likely broken." )
508
535
} else {
509
536
u .Log .WarnContext (ctx , "Teleport updater detected an error with the new installation and successfully reverted it." )
510
537
}
@@ -519,14 +546,9 @@ func (u *Updater) Remove(ctx context.Context, force bool) error {
519
546
return nil
520
547
}
521
548
522
- func (u * Updater ) removeWithoutSystem (ctx context.Context , cfg * UpdateConfig , force bool ) error {
523
- if ! force {
524
- u .Log .ErrorContext (ctx , "No packaged installation of Teleport was found, and --force was not passed. Refusing to remove Teleport from this system." )
525
- return trace .Errorf ("unable to remove Teleport completely without --force" )
526
- } else {
527
- u .Log .WarnContext (ctx , "No packaged installation of Teleport was found, and --force was passed. Teleport will be removed from this system." )
528
- }
529
- u .Log .InfoContext (ctx , "Updater-managed installation of Teleport detected. Attempting to unlink and remove." )
549
+ func (u * Updater ) removeWithoutSystem (ctx context.Context , cfg * UpdateConfig ) error {
550
+ u .Log .InfoContext (ctx , "Updater-managed installation of Teleport detected." )
551
+ u .Log .InfoContext (ctx , "Attempting to unlink and remove." )
530
552
ok , err := u .Process .IsActive (ctx )
531
553
if err != nil && ! errors .Is (err , ErrNotSupported ) {
532
554
return trace .Wrap (err )
@@ -558,6 +580,9 @@ func (u *Updater) Status(ctx context.Context) (Status, error) {
558
580
if err := validateConfigSpec (& cfg .Spec , OverrideConfig {}); err != nil {
559
581
return out , trace .Wrap (err )
560
582
}
583
+ if cfg .Spec .Proxy == "" {
584
+ return out , ErrNotInstalled
585
+ }
561
586
out .UpdateSpec = cfg .Spec
562
587
out .UpdateStatus = cfg .Status
563
588
@@ -689,7 +714,11 @@ func (u *Updater) Update(ctx context.Context, now bool) error {
689
714
u .Log .InfoContext (ctx , "Update available. Initiating update." , targetKey , target , activeKey , active )
690
715
}
691
716
if ! now {
692
- time .Sleep (resp .Jitter )
717
+ select {
718
+ case <- time .After (resp .Jitter ):
719
+ case <- ctx .Done ():
720
+ return trace .Wrap (ctx .Err ())
721
+ }
693
722
}
694
723
695
724
updateErr := u .update (ctx , cfg , target , false , resp .AGPL )
@@ -941,15 +970,18 @@ func (u *Updater) notices(ctx context.Context) error {
941
970
}
942
971
if ! enabled && active {
943
972
u .Log .WarnContext (ctx , "Teleport is installed and started, but not configured to start on boot." )
944
- u .Log .WarnContext (ctx , "After configuring teleport.yaml, you can enable it with: systemctl enable teleport" )
973
+ u .Log .WarnContext (ctx , "After configuring teleport.yaml, you must enable it." ,
974
+ "command" , "systemctl enable " + u .TeleportServiceName )
945
975
}
946
976
if ! active && enabled {
947
977
u .Log .WarnContext (ctx , "Teleport is installed and enabled at boot, but not running." )
948
- u .Log .WarnContext (ctx , "After configuring teleport.yaml, you can start it with: systemctl start teleport" )
978
+ u .Log .WarnContext (ctx , "After configuring teleport.yaml, you must start it." ,
979
+ "command" , "systemctl start " + u .TeleportServiceName )
949
980
}
950
981
if ! active && ! enabled {
951
982
u .Log .WarnContext (ctx , "Teleport is installed, but not running or enabled at boot." )
952
- u .Log .WarnContext (ctx , "After configuring teleport.yaml, you can enable and start it with: systemctl enable teleport --now" )
983
+ u .Log .WarnContext (ctx , "After configuring teleport.yaml, you must enable and start." ,
984
+ "command" , "systemctl enable --now " + u .TeleportServiceName )
953
985
}
954
986
955
987
return nil
0 commit comments