Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BackupCmd = &cobra.Command{ Use: "backup", Short: "backup job & group data", Run: func(cmd *cobra.Command, args []string) { var err error var ea = NewExitAction() backupDir = strings.TrimSpace(backupDir) if len(backupDir) > 0 { err = os.MkdirAll(backupDir, 0755) if err != nil { ea.Exit("failed to make directory %s, err: %s", backupDir, err) } } backupFile = strings.TrimSpace(backupFile) if len(backupFile) == 0 { backupFile = time.Now().Format("20060102_150405") } backupFile += ".zip" name := path.Join(backupDir, backupFile) f, err := os.OpenFile(name, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0600) ea.ExitOnErr(err) ea.Defer = func() { f.Close() if err != nil { os.Remove(name) } } var waitForStore = [][]string{ []string{"job", conf.Config.Cmd}, []string{"node_group", conf.Config.Group}, } zw := zip.NewWriter(f) for i := range waitForStore { zf, err := zw.Create(waitForStore[i][0]) ea.ExitOnErr(err) storeKvs(zf, waitForStore[i][1]) } ea.ExitOnErr(zw.Close()) }, }
View Source
var NodeCmd = &cobra.Command{ Use: "node", Short: "Send some commands to nodes", Long: `Send a command to nodes and execute it. Available Commands: rmold: remove old version(< 0.3.0) node info from mongodb and etcd sync: sync node info to mongodb `, Run: func(cmd *cobra.Command, args []string) { ea := NewExitAction() ea.After = func() { fmt.Println() cmd.Help() } nc, err := cronsun.ToNodeCmd(nodeCmd) if err != nil { ea.Exit(err.Error() + ": " + nodeCmd) } var include, exclude []string if len(nodeInclude) > 0 { include = strings.Split(nodeInclude, spliter) } if len(nodeExclude) > 0 { exclude = strings.Split(nodeExclude, spliter) } err = cronsun.PutCsctl(&cronsun.CsctlCmd{ Cmd: nc, Include: include, Exclude: exclude, }) if err != nil { ea.ExitOnErr(err) } fmt.Printf("command[%s] send success\n", nodeCmd) }, }
View Source
var RestoreCmd = &cobra.Command{ Use: "restore", Short: "restore job & group data", Run: func(cmd *cobra.Command, args []string) { var err error var ea = NewExitAction() restoreFile = strings.TrimSpace(restoreFile) if len(restoreFile) == 0 { ea.Exit("backup file is required") } r, err := zip.OpenReader(restoreFile) ea.ExitOnErr(err) ea.Defer = func() { r.Close() } restoreChan, wg := startRestoreProcess() for _, f := range r.File { var keyPrefix string switch f.Name { case "job": keyPrefix = conf.Config.Cmd case "node_group": keyPrefix = conf.Config.Group } rc, err := f.Open() ea.ExitOnErr(err) ea.ExitOnErr(restoreKvs(rc, keyPrefix, restoreChan, wg)) rc.Close() } wg.Wait() close(restoreChan) }, }
View Source
var UpgradeCmd = &cobra.Command{ Use: "upgrade", Short: "upgrade will upgrade data to the current version(" + cronsun.VersionNumber + ")", Run: func(cmd *cobra.Command, args []string) { var ea = NewExitAction() prever = strings.TrimLeft(strings.TrimSpace(prever), "v") if len(prever) < 5 { ea.Exit("invalid version number") } nodesById := getIPMapper(ea, prever) if prever < "0.3.0" { fmt.Println("upgrading data to version 0.3.0") if to_0_3_0(ea, nodesById) { return } } if prever < "0.3.1" { fmt.Println("upgrading data to version 0.3.1") if to_0_3_1(ea, nodesById) { return } } }, }
Functions ¶
This section is empty.
Types ¶
type ExitAction ¶
type ExitAction struct { Defer func() After func() }
func NewExitAction ¶
func NewExitAction() *ExitAction
func (*ExitAction) Exit ¶
func (ea *ExitAction) Exit(format string, v ...interface{})
func (*ExitAction) ExitOnErr ¶
func (ea *ExitAction) ExitOnErr(err error)
Click to show internal directories.
Click to hide internal directories.