debugd: start existing coordinator binary at boot if coordinator was deployed before reboot

This commit is contained in:
Malte Poll 2022-04-27 10:32:15 +02:00 committed by Malte Poll
parent 63d282f1ed
commit 5ac72c730d

View File

@ -136,10 +136,24 @@ func (s *ServiceManager) WriteSystemdUnitFile(ctx context.Context, unit SystemdU
return nil
}
// DeployDefaultServiceUnit will write the default "constellation.service" unit file.
// DeployDefaultServiceUnit will write the default "coordinator.service" unit file.
func DeployDefaultServiceUnit(ctx context.Context, serviceManager *ServiceManager) error {
return serviceManager.WriteSystemdUnitFile(ctx, SystemdUnit{
if err := serviceManager.WriteSystemdUnitFile(ctx, SystemdUnit{
Name: debugd.CoordinatorSystemdUnitName,
Contents: debugd.CoordinatorSystemdUnitContents,
})
}); err != nil {
return fmt.Errorf("writing systemd unit file %q failed: %w", debugd.CoordinatorSystemdUnitName, err)
}
// try to start the default service if the binary exists but ignore failure.
// this is meant to start the coordinator after a reboot
// if a coordinator binary was uploaded before.
if ok, err := afero.Exists(serviceManager.fs, debugd.CoordinatorDeployFilename); ok && err == nil {
_ = serviceManager.SystemdAction(ctx, ServiceManagerRequest{
Unit: debugd.CoordinatorSystemdUnitName,
Action: Start,
})
}
return nil
}