Exemplo n.º 1
1
Arquivo: db.go Projeto: imoapps/juju
// placeNewMongoService wraps placeNewMongo with the proper service stopping
// and starting before dumping the new mongo db, it is mainly to easy testing
// of placeNewMongo.
func placeNewMongoService(newMongoDumpPath string, ver version.Number) error {
	err := mongo.StopService("")
	if err != nil {
		return errors.Annotate(err, "failed to stop mongo")
	}

	if err := placeNewMongo(newMongoDumpPath, ver); err != nil {
		return errors.Annotate(err, "cannot place new mongo")
	}
	err = mongo.StartService("")
	return errors.Annotate(err, "failed to start mongo")
}
Exemplo n.º 2
0
func ensureMongoService(agentConfig agent.Config) error {
	var oplogSize int
	if oplogSizeString := agentConfig.Value(agent.MongoOplogSize); oplogSizeString != "" {
		var err error
		if oplogSize, err = strconv.Atoi(oplogSizeString); err != nil {
			return errors.Annotatef(err, "invalid oplog size: %q", oplogSizeString)
		}
	}

	var numaCtlPolicy bool
	if numaCtlString := agentConfig.Value(agent.NumaCtlPreference); numaCtlString != "" {
		var err error
		if numaCtlPolicy, err = strconv.ParseBool(numaCtlString); err != nil {
			return errors.Annotatef(err, "invalid numactl preference: %q", numaCtlString)
		}
	}

	si, ok := agentConfig.StateServingInfo()
	if !ok {
		return errors.Errorf("agent config has no state serving info")
	}

	if err := mongo.EnsureServiceInstalled(agentConfig.DataDir(),
		si.StatePort,
		oplogSize,
		numaCtlPolicy,
		agentConfig.MongoVersion(),
		true,
	); err != nil {
		return errors.Annotate(err, "cannot ensure that mongo service start/stop scripts are in place")
	}
	// Installing a service will not automatically restart it.
	if err := mongo.StartService(); err != nil {
		return errors.Annotate(err, "failed to start mongo")
	}
	return nil
}