예제 #1
0
func (propertiesFileServiceImpl *propertiesFileServiceImpl) GetInfo(fileName string) (map[string]string, error) {
	if utils.IsEmptyStr(fileName) {
		return nil, errors.New("没有文件")
	}
	if !utils.IsFileExist(fileName) {
		return nil, errors.New(fmt.Sprintf("文件%s不存在", fileName))
	}
	fi, err := os.Open(fileName)
	if nil != err {
		return nil, err
	}
	defer fi.Close()
	r := bufio.NewReader(fi)
	result := make(map[string]string)
	for {
		//buf,err := r.ReadBytes('\n')
		str, err := r.ReadString('\n')
		if nil != err {
			if err == io.EOF {
				break
			}
			return nil, err
		}
		if !utils.IsEmptyStr(str) {
			strvs := strings.Split(str, "=")
			if len(strvs) > 1 {
			}
			result[strvs[0]] = strvs[1]
		}
	}
	return result, nil
}
예제 #2
0
func (routeServerSave *RouteServerSave) CheckServerSave(oServerName string, pServerInfo *model.ServerInfo) error {

	if !utils.IsFileExist(pServerInfo.Address) {
		return errors.New(fmt.Sprintf("没有找到服务器程序%s", pServerInfo.Address))
	}
	_, err := service.NewGetServerInfoConfigFileName().GetInfo(pServerInfo)
	return err
}
예제 #3
0
func (getAllProcessInfoLinux *GetAllProcessInfoLinux) getCmdLine(processInfo *model.ProcessInfo) (err error) {
	cmdline_file := fmt.Sprintf("/proc/%d/cmdline", processInfo.Id)
	if !utils.IsFileExist(cmdline_file) {
		err = errors.New("文件不存在")
		return
	}
	processInfo.Cmdline, err = utils.ReadFileToStringNoLn(cmdline_file)
	return
}
예제 #4
0
func (getAllProcessInfoLinux *GetAllProcessInfoLinux) getProcStatus(processInfo *model.ProcessInfo) (err error) {
	status_file := fmt.Sprintf("/proc/%d/status", processInfo.Id)
	if !utils.IsFileExist(status_file) {
		err = errors.New("文件不存在")
		return
	}
	var content []byte
	content, err = ioutil.ReadFile(status_file)
	if nil != err {
		return
	}
	want := map[string]bool{
		"Name:":   true,
		"State:":  true,
		"VmRSS:":  true,
		"VmSize:": true,
	}
	reader := bufio.NewReader(bytes.NewBuffer(content))
	for {
		bs, _, err := reader.ReadLine()
		if err == io.EOF {
			break
		}

		line := string(bs)
		fields := strings.Fields(string(line))
		if len(fields) < 1 {
			continue
		}
		_, ok := want[fields[0]]
		if !ok {
			continue
		}
		switch fields[0] {
		case "Name:":
			processInfo.Name = strings.TrimSpace(fields[1])
		case "State:":
			processInfo.State = strings.TrimSpace(fields[1])
		case "VmRSS:":
			processInfo.MemRealSize, err = strconv.ParseInt(fields[1], 10, 32)
			if nil != err {
				return err
			}
			processInfo.MemRealSize = processInfo.MemRealSize * common.KB_SIZE
		case "VmSize:":
			processInfo.MemVmSize, err = strconv.ParseInt(fields[1], 10, 32)
			if nil != err {
				return err
			}
			processInfo.MemVmSize = processInfo.MemVmSize * common.KB_SIZE
		}
	}

	return
}
func (serverConfigSaveHandleAPSImpl *serverConfigSaveHandleAPSImpl) Save(r *http.Request, serverInfo *model.ServerInfo) error {
	if nil == r {
		return errors.New("没有请求")
	}
	setupInfo, err := NewGetServerDetailSetupInfo().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	apsSetupInfo := setupInfo.(*model.APSServerSetupInfo)
	apsSetupInfo.APSInfo.Id = r.FormValue("serverId")
	apsSetupInfo.APSInfo.Password = r.FormValue("password")
	apsSetupInfo.APSInfo.RegisterInterval, err = strconv.Atoi(r.FormValue("registerInterval"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.DefaultHeartInterval, err = strconv.Atoi(r.FormValue("defaultHeartInterval"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.AddressInfo.IP = r.FormValue("address")
	apsSetupInfo.APSInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("port"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.LogInfo.Logcfgfile = r.FormValue("logcfgfile")
	if utils.IsEmptyStr(apsSetupInfo.APSInfo.LogInfo.Logcfgfile) {
		return errors.New("没有日志配置文件")
	}
	if !utils.IsFileExist(utils.GetFileDir(serverInfo.Address) + "/" + apsSetupInfo.APSInfo.LogInfo.Logcfgfile) {
		return errors.New("日志配置文件不存在")
	}
	apsSetupInfo.APSInfo.LogInfo.SaveCatalog = r.FormValue("saveCatalog")
	apsSetupInfo.SipServerInfo.Id = r.FormValue("sipServerId")
	apsSetupInfo.SipServerInfo.Domain = r.FormValue("sipServerDomain")
	apsSetupInfo.SipServerInfo.AddressInfo.IP = r.FormValue("sipServerAddress")
	apsSetupInfo.SipServerInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("sipServerPort"))
	if nil != err {
		return err
	}
	apsSetupInfo.CMSServerInfo.Address = r.FormValue("cmsServerAddress")
	cfgFileName, err := NewGetServerInfoConfigFileName().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	err = setup.NewSetupInfoService().SaveSetupInfo(apsSetupInfo, cfgFileName, common.XML_ENCODE_GB2312)
	return err

}
func (getServerInfoConfigFileNameImpl *getServerInfoConfigFileNameImpl) GetInfo(serverInfo *model.ServerInfo) (string, error) {
	if nil == serverInfo {
		return "", errors.New("没有服务器对象")
	}
	var configFileName string = ""
	switch serverInfo.Type {
	case common.SERVER_TYPE_APS, common.SERVER_TYPE_MTS, common.SERVER_TYPE_SIP:
		configFileName = utils.GetServerConfigFileName(serverInfo.Address)
	case common.SERVER_TYPE_CMS:
		configFileName = getCMSConfigFileName(serverInfo.Address)
	}
	if utils.IsEmptyStr(configFileName) {
		return "", errors.New("不支持的服务器类型")
	}
	if !utils.IsFileExist(configFileName) {
		return "", errors.New("服务器配置文件不存在")
	}
	return configFileName, nil
}