示例#1
0
// check users
func checkUsers(users []user.User) {
	for _, user := range users {
		Log.Debug("check user for ", user.GetPort())

		isExists, err := storage.Exists(user)
		if err != nil {
			Log.Error("check exists error: ", err)
			continue
		}
		if !isExists && user.IsEnable() {
			Log.Info("new user to run", user)
			err := storage.StoreUser(user.GetUserInfo())
			if err != nil {
				Log.Error("store  error: ", err)
			}
			go runWithCustomMethod(user)
			continue
		}
		if !user.IsEnable() && isExists {
			Log.Info("user would be disable,port:  ", user.GetPort())
			passwdManager.del(strconv.Itoa(user.GetPort()))
			err := storage.Del(user)
			if err != nil {
				Log.Error(err)
			}
			continue
		}

		if !user.IsEnable() {
			continue
		}

		sUser, err := storage.GetUserInfo(user)
		if err != nil {
			Log.Error("get user error: ", err)
			continue
		}
		if sUser.Passwd != user.GetPasswd() || sUser.Method != user.GetMethod() {
			Log.Info(fmt.Sprintf("user port [%v] passwd or method change ,restart user...", user.GetPort()))
			passwdManager.del(strconv.Itoa(user.GetPort()))
			err := storage.StoreUser(user.GetUserInfo())
			if err != nil {
				Log.Error("store  error: ", err)
			}
			go runWithCustomMethod(user)
		}
	}
}
示例#2
0
// 第一次启动
func bootUsers(users []user.User) {
	for _, user := range users {
		Log.Info(user.GetUserInfo())
		err := storage.StoreUser(user.GetUserInfo())
		if err != nil {
			Log.Error(err)
		}
		isExists, err := storage.Exists(user)
		if err != nil {
			Log.Error("check exists error: ", err)
			continue
		}
		if isExists {
			continue
		}
		go runWithCustomMethod(user)
	}
}