// UninstallCommand configures the Uninstall struct and calls it based on the // given codegangsta/cli context. // // TODO: remove all artifacts, ie bolt db, ssh keys, kd etc. func UninstallCommand(c *cli.Context, log logging.Logger, _ string) (string, int) { warnings := []string{} // Ensure /etc/kite/kite.key is migrated to konfig.bolt before // old klient gets uninstalled. The endpoint/config package // performs lazy migrations, so it's enough to call any of // its methods and disregard the result. _ = configcli.List() s, err := newService(nil) if err != nil { log.Warning("Failed creating Service for uninstall. err:%s", err) warnings = append(warnings, FailedUninstallingKlientWarn) } uninstaller := &Uninstall{ ServiceUninstaller: s, KlientName: config.KlientName, KlientctlName: config.Name, KlientctlPath: filepath.Join(KlientctlDirectory, KlientctlBinName), // TODO: Store the klient directory structure(s) somewhere KlientParentDirectory: "/opt", KlientDirectory: "kite/klient", KlientFilename: "klient", KlientshFilename: "klient.sh", remover: os.Remove, warnings: warnings, log: log, } return uninstaller.Uninstall() }
func startKlient(log logging.Logger, s service.Service) error { // For debug purposes, run a health check before we even attempt to start. This // will help give us a sense of what this machine's health check was before // klient tried to start. if res, ok := defaultHealthChecker.CheckAllExceptRunning(); !ok { log.Warning("before attempting to start klient health check returned not-okay. reason: %s", res) } if err := s.Start(); err != nil { log.Error("Error starting Service. err:%s", err) fmt.Println(FailedStartKlient) return err } fmt.Println("Starting...") err := WaitUntilStarted(config.Konfig.Endpoints.Klient.Private.String(), CommandAttempts, CommandWaitTime) if err != nil { log.Error( "Timed out while waiting for Klient to start. attempts:%d, err:%s", CommandAttempts, err, ) if s, ok := defaultHealthChecker.CheckAllExceptRunning(); !ok { fmt.Printf(`Failed to start %s in time. A health check found the following issue: %s `, config.KlientName, s) } else { fmt.Println(FailedStartKlient) } return err } return nil }
// restoreLoadedMachineFromKite takes an old loaded machine and applies meta // changes to it, while also creating a valid machine instance with a proper // transport/etc. func (r *Remote) restoreLoadedMachineFromKite(c *KodingClient, loadedMachine *machine.Machine, log logging.Logger) (bool, error) { // metaChanged is our return value, which lets the caller know if any of the meta // for this machine changed from the given kite. If it does, the caller will // want to save the machines to the local db. var metaChanged bool host, err := r.hostFromClient(c.Client) if err != nil { log.Error("Unable to extract host from *kite.Client. err:%s", err) return false, err } // Get our old machine meta, loaded from the DB machineMeta := loadedMachine.MachineMeta if machineMeta.MachineLabel != c.MachineLabel { machineMeta.MachineLabel = c.MachineLabel metaChanged = true } if machineMeta.URL == "" && c.URL != "" { log.Warning("Machine missing MachineMeta.URL, updating it to %q", c.URL) machineMeta.URL = c.URL metaChanged = true } if machineMeta.IP == "" && host != "" { log.Warning("Machine missing MachineMeta.IP, updating it to %q", host) machineMeta.IP = host metaChanged = true } if machineMeta.Hostname != c.Hostname { machineMeta.Hostname = c.Hostname metaChanged = true } if machineMeta.Username != c.Username { machineMeta.Username = c.Username metaChanged = true } // Remove the machine, because we're going to be creating a new machine instance // below. err = r.machines.Remove(loadedMachine) if err != nil && err != machine.ErrMachineNotFound { log.Error("Unable to Remove old machine from *machine.Machines. err:%s", err) return false, err } restoredMachine, err := machine.NewMachine(machineMeta, r.log, c.Client) if err != nil { return false, err } // Add our newly created machine instance. if err = r.machines.Add(restoredMachine); err != nil { log.Error("Unable to Add new machine to *machine.Machines. err:%s", err) return false, err } return metaChanged, nil }