예제 #1
0
파일: slave.go 프로젝트: eeayiaia/scmt
func (slave *Slave) RunPluginInstaller(plugin string) error {
	slave.lock.Lock()
	defer slave.lock.Unlock()

	plugin = strings.ToLower(plugin)

	isInDB, _ := database.PluginInDB(plugin)
	if !isInDB {
		Log.WithFields(log.Fields{
			"plugin": plugin,
		}).Warn("Plugin not in database")
		return errors.New("Plugin not in database: " + plugin)
	}

	isInstalled := slave.pluginIsInstalled(plugin)
	if isInstalled {
		Log.WithFields(log.Fields{
			"MAC":    slave.HardwareAddress,
			"plugin": plugin,
		}).Info("Plugin already installed")
		return errors.New("Plugin already installed: " + plugin)
	}

	isEnabled := database.PluginIsEnabled(plugin)
	if !isEnabled {
		Log.WithFields(log.Fields{
			"plugin": plugin,
		}).Warn("Plugin not enabled")
		return errors.New("Plugin not enabled: " + plugin)
	}

	err := slave.installPlugin(plugin)
	if err != nil {
		Log.WithFields(log.Fields{
			"plugin": plugin,
		}).Warn("Failed with installation")
		return errors.New("Failed with installation of: " + plugin)
	}

	slave.setPluginInstalled(plugin)

	Log.WithFields(log.Fields{
		"plugin": plugin,
	}).Info("Successfully installed")

	return nil
}
예제 #2
0
파일: plugin.go 프로젝트: eeayiaia/scmt
func installPluginOnMaster(pluginName string) error {
	pluginName = strings.ToLower(pluginName)

	if tf, _ := database.PluginInDB(pluginName); !tf {
		Log.WithFields(log.Fields{
			"plugin": pluginName,
		}).Warn("Plugin not available on master.")
		return errors.New("Plugin not available on master:" + pluginName)
	}

	if tf := database.PluginIsEnabled(pluginName); !tf {
		Log.WithFields(log.Fields{
			"plugin": pluginName,
		}).Warn("Plugin not enabled")
		return errors.New("Plugin not enabled" + pluginName)
	}

	if tf, _ := PluginIsInstalled(pluginName); tf {
		Log.WithFields(log.Fields{
			"plugin": pluginName,
		}).Warn("Plugin already set to installed on master")
		return errors.New("Plugin already set to installed on master" + pluginName)
	}

	err := RunScriptsInDir("plugins.d/"+pluginName+"/master.init.d/", GetEnvVarGlob())

	if err != nil {
		Log.WithFields(log.Fields{
			"err": err,
		}).Warn("Failed to run script")
		return errors.New("Failed to install plugin:" + pluginName)
	}

	SetPluginInstalled(pluginName)

	Log.WithFields(log.Fields{
		"plugin": pluginName,
	}).Info("Plugin installed on master")

	return nil
}