示例#1
0
//由于bash过度难用,直接安装kmg的时候又会遇到很复杂的情况,此处用于处理某些复杂情况
func selfInstallCmd() {
	//迁移代码,从/bin/kmg迁移到/usr/local/bin/kmg
	if kmgFile.MustFileExist("/bin/kmg") {
		kmgCmd.MustRunInBash("sudo rm /bin/kmg;hash -r")
	}
	kmgFile.MustEnsureBinPath("/usr/local/bin/kmg")
}
示例#2
0
func selfUpdate() {
	baseFileContent, err := kmgHttp.UrlGetContent("http://kmgtools.qiniudn.com/v1/installKmg.bash?v=" + kmgRand.MustCryptoRandToAlphaNum(16))
	kmgConsole.ExitOnErr(err)

	baseFilePath := "/tmp/installKmg.bash"
	kmgFile.MustDeleteFile(baseFilePath)
	kmgFile.MustAppendFile(baseFilePath, baseFileContent)
	kmgCmd.MustRunInBash(baseFilePath)
}
示例#3
0
func SshCertCopyLocalToRemote(remote *RemoteServer) {
	if remote.Address == "" {
		return
	}
	isReachable, havePermission := AvailableCheck(remote)
	if !isReachable {
		panic("[kmgSsh SshCertCopyLocalToRemote]" + remote.String() + " unreachable!")
	}
	if havePermission {
		return
	}
	if remote.Password == "" {
		kmgCmd.MustRunInBash("ssh-copy-id " + remote.String())
		return
	}
	//p := filepath.Join(kmgSys.GetCurrentUserHomeDir(), ".ssh", "id_rsa.pub")
	RunCmdWithPassword(
		//strings.Join([]string{"ssh-copy-id", "-i", p, remote.String()}, " "),
		"ssh-copy-id "+remote.String(),
		remote.Password,
	)
}
示例#4
0
文件: command.go 项目: keysonZZZ/kmg
func AddCommandList() {
	cmdGroup := kmgConsole.NewCommandGroup().
		AddCommand(kmgConsole.Command{
			Name:   "setAndRestart",
			Desc:   "install the service,and restart the service,uninstall and stop if need",
			Runner: setAndRestartCmd,
		}).AddCommandWithName(
		"setAndRestartV1",
		setAndRestartCmdV1,
	).AddCommand(kmgConsole.Command{
		Name:   "install",
		Desc:   "install the service",
		Runner: installCmd,
	}).AddCommand(kmgConsole.Command{
		Name:   "uninstall",
		Desc:   "uninstall the serivce",
		Runner: newNameCmd(Uninstall),
	}).AddCommand(kmgConsole.Command{
		Name:   "start",
		Desc:   "start the service",
		Runner: newNameCmd(Start),
	}).AddCommand(kmgConsole.Command{
		Name:   "stop",
		Desc:   "stop the service",
		Runner: newNameCmd(Stop),
	}).AddCommand(kmgConsole.Command{
		Name:   "restart",
		Desc:   "restart the service",
		Runner: newNameCmd(Restart),
	})
	kmgConsole.AddCommand(kmgConsole.Command{
		Name:   "Service",
		Runner: cmdGroup.Main,
	})
	kmgConsole.AddCommand(kmgConsole.Command{
		Name:   "Service.Process",
		Runner: processCmd,
		Hidden: true,
	})
	kmgConsole.AddCommandWithName("Service.RunTest", func() {
		cmd := ""
		flag.StringVar(&cmd, "c", "kmg service restart kmgServiceTest", "")
		flag.Parse()
		wg := sync.WaitGroup{}
		wg.Add(10)
		for i := 0; i < 10; i++ {
			go func() {
				kmgCmd.MustRunInBash("setsid " + cmd)
				wg.Done()
			}()
		}
		wg.Wait()
	})
	kmgConsole.AddCommandWithName("Service.TestJob", func() {
		time.Sleep(time.Second * 3)
		ServiceStartSuccess()
	})
	kmgConsole.AddCommandWithName("Service.TestJobTimeout", func() {
		time.Sleep(time.Minute * 10)
		ServiceStartSuccess()
	})
}