コード例 #1
0
func (a *Application) runWithTimeout(sshSetting sshclient.SshSetting, cmd string) (string, error) {
	timeout := time.Second * time.Duration(5)
	cRunCommand := make(chan string, 1)
	var res string

	go func(res *string) {
		temp, err := sshSetting.RunCommandSshAsMap(cmd)
		*res = temp[0].Output

		if err != nil {
			cRunCommand <- err.Error()
		} else {
			cRunCommand <- ""
		}
	}(&res)

	errorMessage := ""
	select {
	case receiveRunCommandOutput := <-cRunCommand:
		errorMessage = receiveRunCommandOutput
	case <-time.After(time.Second * time.Duration(timeout)):
		errorMessage = ""
	}

	if strings.TrimSpace(errorMessage) != "" {
		return "", errors.New(errorMessage)
	}

	return strings.TrimSpace(res), nil
}
コード例 #2
0
ファイル: server.go プロジェクト: kranjcarz/colony-manager
func (s *ServerController) SSHConnect(payload *colonycore.Server) (sshclient.SshSetting, *ssh.Client, error) {
	client := sshclient.SshSetting{}
	client.SSHHost = payload.Host

	if payload.SSHType == "File" {
		client.SSHAuthType = sshclient.SSHAuthType_Certificate
		client.SSHKeyLocation = payload.SSHFile
	} else {
		client.SSHAuthType = sshclient.SSHAuthType_Password
		client.SSHUser = payload.SSHUser
		client.SSHPassword = payload.SSHPass
	}

	theClient, err := client.Connect()

	return client, theClient, err
}
コード例 #3
0
ファイル: server.go プロジェクト: arfian/colony-core
func (s *Server) Connect() (sshclient.SshSetting, *ssh.Client, error) {
	client := sshclient.SshSetting{}
	client.SSHHost = s.Host

	if s.SSHType == "File" {
		client.SSHAuthType = sshclient.SSHAuthType_Certificate
		client.SSHKeyLocation = s.SSHFile
	} else {
		client.SSHAuthType = sshclient.SSHAuthType_Password
		client.SSHUser = s.SSHUser
		client.SSHPassword = s.SSHPass
	}

	theClient, err := client.Connect()

	return client, theClient, err
}
コード例 #4
0
ファイル: z3_test.go プロジェクト: novalagung/sedotan
func (s *ServerController) SSHConnect(payload *colonycore.Server) (sshclient.SshSetting, *ssh.Client, error) {
	client := sshclient.SshSetting{}
	client.SSHHost = "192.168.56.103:22"

	client.SSHAuthType = 0
	client.SSHUser = "******"
	client.SSHPassword = "******"

	//fmt.Println(client) {192.168.56.103:22 eaciit1 12345  0}

	theClient, err := client.Connect()

	return client, theClient, err
}
コード例 #5
0
func (l *LangenvironmentController) ProcessSetup(dataServers *colonycore.Server, query *dbox.Filter, serverPathSeparator string, sshSetting sshclient.SshSetting) ([]sshclient.RunCommandResult, error) {
	outputCmd := []sshclient.RunCommandResult{}

	dataLanguage := []colonycore.LanguageEnviroment{}
	cursor, err := colonycore.Find(new(colonycore.LanguageEnviroment), query)
	cursor.Fetch(&dataLanguage, 0, false)
	if err != nil {
		return outputCmd, err
	}
	defer cursor.Close()

	if cursor.Count() > 0 {
		for _, eachLang := range dataLanguage {
			for _, dataInstaller := range eachLang.Installer {
				var sourcePath string
				var destinationPath string
				pathstring := []string{dataServers.DataPath, "langenvironment", "installer"}

				var installShPath, uninstallShPath string

				if strings.ToLower(dataServers.OS) == strings.ToLower(dataInstaller.OS) {
					// targetLang := new(colonycore.InstalledLang)
					// targetLang.Lang = eachLang.Language

					// for _, eachLang := range dataServers.InstalledLang {
					// 	if eachLang.Lang == targetLang.Lang {
					// 		targetLang = eachLang
					// 		break
					// 	}
					// }

					if eachLang.Language == LANG_GO {
						pathstring = append(pathstring, LANG_GO)
						pathstring = append(pathstring, dataServers.OS)
						sourcePath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, dataInstaller.InstallerSource)
						destinationPath = strings.Join(pathstring, serverPathSeparator)
						installShPath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, "install.sh")
						uninstallShPath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, "uninstall.sh")
					} else if eachLang.Language == LANG_JAVA {
						pathstring = append(pathstring, LANG_JAVA)
						pathstring = append(pathstring, dataServers.OS)
						sourcePath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, dataInstaller.InstallerSource)
						destinationPath = strings.Join(pathstring, serverPathSeparator)
						installShPath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, "install.sh")
						uninstallShPath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, "uninstall.sh")
					} else if eachLang.Language == LANG_SCALA {
						pathstring = append(pathstring, LANG_SCALA)
						pathstring = append(pathstring, dataServers.OS)
						sourcePath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, dataInstaller.InstallerSource)
						destinationPath = strings.Join(pathstring, serverPathSeparator)
						installShPath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, "install.sh")
						uninstallShPath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, "uninstall.sh")
					}
					installShdestPath := strings.Join(append(pathstring, "install.sh"), serverPathSeparator)
					uninstallShdestPath := strings.Join(append(pathstring, "uninstall.sh"), serverPathSeparator)
					// installFilePath := strings.Join(append(pathstring, dataInstaller.InstallerSource), serverPathSeparator)

					err = sshSetting.SshCopyByPath(sourcePath, destinationPath)
					if err != nil {
						return outputCmd, err
					}

					err = sshSetting.SshCopyByPath(installShPath, destinationPath)
					if err != nil {
						return outputCmd, err
					}

					err = sshSetting.SshCopyByPath(uninstallShPath, destinationPath)
					if err != nil {
						return outputCmd, err
					}

					//sed -i 's/^M//' install.sh
					cmdSedInstall := fmt.Sprintf("sed -i 's/\r//g' %s", installShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdSedInstall)
					if err != nil {
						return outputCmd, err
					}
					//sed -i 's/^M//' uninstall.sh
					cmdSedUninstall := fmt.Sprintf("sed -i 's/\r//g' %s", uninstallShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdSedUninstall)
					if err != nil {
						return outputCmd, err
					}

					// // chmod +x install.sh
					cmdChmodCliInstall := fmt.Sprintf("chmod +x %s", installShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdChmodCliInstall)
					if err != nil {
						return outputCmd, err
					}
					// // chmod +x uninstall.sh
					cmdChmodCliUninstall := fmt.Sprintf("chmod +x %s", uninstallShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdChmodCliUninstall)
					if err != nil {
						return outputCmd, err
					}

					// // sh install.sh installFilePath DESTINSTALL_PATH projectpath
					cmdShCli := fmt.Sprintf("bash %s %s", uninstallShdestPath, DESTINSTALL_PATH)
					outputCmd, err = sshSetting.RunCommandSshAsMap(cmdShCli)
					if err != nil {
						return outputCmd, err
					}
					fmt.Println(" :: : ", outputCmd[0].Output)

					// targetLang.IsInstalled = true
					// dataServers.InstalledLang = append(dataServers.InstalledLang, targetLang)
					// colonycore.Save(dataServers)
				}
			}
		}
	}

	return outputCmd, nil
}