Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Ccmd = &cobra.Command{ Use: fmt.Sprintf("service %v %v", installableServices, availableCommands), Short: "Manage immu services", Long: fmt.Sprintf(`Manage immudb related services. Available services: immudb and immugw. Root permission are required in order to make administrator operations. %s`, service.UsageDet), ValidArgs: availableCommands, Example: service.UsageExamples, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { return errors.New("required a service name") } if stringInSlice("--remove-files", os.Args) { return nil } if len(args) < 2 { return errors.New("required a command name") } if !stringInSlice(args[0], installableServices) { return fmt.Errorf("invalid service argument specified: %s. Available list is %v", args[0], installableServices) } if !stringInSlice(args[1], availableCommands) { return fmt.Errorf("invalid command argument specified: %s. Available list is %v", args[1], availableCommands) } return nil }, RunE: func(cmd *cobra.Command, args []string) (err error) { if ok, e := service.CheckPrivileges(); !ok { return e } t, _ := cmd.Flags().GetInt("time") if t > 0 { // if t is present we relaunch same command with --delayed flag set var argi []string for i, k := range os.Args { if k == "--time" || k == "-t" { continue } if _, err = strconv.ParseFloat(k, 64); err == nil { continue } if i != 0 { argi = append(argi, k) } } argi = append(argi, "--delayed") argi = append(argi, strconv.Itoa(t)) if err = launch(os.Args[0], argi); err != nil { return err } return nil } d, _ := cmd.Flags().GetInt("delayed") if d > 0 { time.Sleep(time.Duration(d) * time.Second) } var msg string var localFile string var execPath string if args[1] == "install" { if localFile, err = cmd.Flags().GetString("local-file"); err != nil { return err } if localFile, err = service.GetExecutable(localFile, args[0]); err != nil { return err } } execPath = service.GetDefaultExecPath(localFile) if stringInSlice("--remove-files", os.Args) { if localFile, err = cmd.Flags().GetString("local-file"); err != nil { return err } } if args[1] == "install" { if execPath, err = service.CopyExecInOsDefault(localFile); err != nil { return err } } if remove, _ := cmd.Flags().GetBool("remove-files"); remove { if err = os.Remove(execPath); err != nil { return err } return nil } daemon, err := service.NewDaemon(args[0], args[0], execPath) if err != nil { return err } var u string switch args[1] { case "install": if args[0] == "immugw" { fmt.Printf("To provide the maximum level of security, we recommend running immugw on a different machine than immudb server. Continue ? [Y/n]") if u, err = c.ReadFromTerminalYN("Y"); err != nil { return err } if u != "y" { fmt.Println("No action") return } } fmt.Println("installing " + localFile + "...") if err = service.InstallSetup(args[0]); err != nil { return err } if msg, err = daemon.Install("--config", service.GetDefaultConfigPath(args[0])); err != nil { return err } fmt.Println(msg) if msg, err = daemon.Start(); err != nil { return err } fmt.Println(msg) return nil case "uninstall": // check if already installed var status string if status, err = daemon.Status(); err != nil { if err == daem.ErrNotInstalled { return err } } if service.IsRunning(status) { if msg, err = daemon.Stop(); err != nil { return err } fmt.Println(msg) } fmt.Printf("Are you sure you want to uninstall %s? [y/N]", args[0]) if u, err = c.ReadFromTerminalYN("N"); err != nil { return err } if u != "y" { fmt.Println("No action") return } if msg, err = daemon.Remove(); err != nil { return err } fmt.Println(msg) if args[0] == "immudb" { fmt.Printf("Erase data? [y/N]") if u, err = c.ReadFromTerminalYN("N"); err != nil { return err } if u != "y" { fmt.Println("No data removed") } if err = service.EraseData(args[0]); err != nil { return err } fmt.Println("Data folder removed") } if err = service.RemoveProgramFiles(args[0]); err != nil { return err } fmt.Println("Program files removed") if err = service.UninstallSetup(args[0]); err != nil { return err } return nil case "start": if msg, err = daemon.Start(); err != nil { return err } fmt.Println(msg) return nil case "stop": if msg, err = daemon.Stop(); err != nil { return err } fmt.Println(msg) return nil case "restart": if _, err = daemon.Stop(); err != nil { return err } fmt.Println(msg) if msg, err = daemon.Start(); err != nil { return err } fmt.Println(msg) return nil case "status": if msg, err = daemon.Status(); err != nil { return err } fmt.Println(msg) return nil } return nil }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.