示例#1
0
// loadSettings function is responsable for lading the configuration parameters from a
// file. It will be used when the system starts for the first time and when it receives a
// SIGHUP signal
func loadSettings() error {
	// TODO: Possible concurrent access problem while reloading the configuration file. And
	// we also should reload many structures that could change with the new configuration
	// files, like the network interfaces
	if err := config.LoadConfig(configFilePath); err != nil {
		return err
	}

	// Load languages to model. We don't do this in the configuration package, because we
	// don't want to create a dependency between the model and the config taht could become
	// a cross reference
	for _, language := range config.ShelterConfig.Languages {
		if err := model.AddLanguage(language); err != nil {
			return err
		}
	}

	return nil
}
示例#2
0
func Run(configFilePath, sampleConfigFilePath, keysPath string) {
	defer func() {
		if r := recover(); r != nil {
			log.Println(r)
		}
	}()

	if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
		// Initialize configuration file

		if err := config.LoadConfig(sampleConfigFilePath); err != nil {
			log.Fatalln(err)
			return
		}

		if !readEnabledModules() ||
			!readDatabaseParameters() ||
			!readRESTParameters(keysPath) ||
			!readWebClientParameters(keysPath) ||
			!readNotificationParameters() {

			return
		}

		jsonConfig, err := json.MarshalIndent(config.ShelterConfig, " ", " ")
		if err != nil {
			log.Fatalln(err)
			return
		}

		if err := ioutil.WriteFile(configFilePath, jsonConfig, 0664); err != nil {
			log.Fatalln(err)
			return
		}

	} else {
		// Update current configuration file
	}

	cmd := exec.Command("initctl", "stop", "shelter")
	cmd.Run() // We don't care about stop errors, because maybe the process wasn't there

	cmd = exec.Command("initctl", "start", "shelter")
	if err := cmd.Run(); err != nil {
		log.Println("Error starting shelter. Details:", err)
	}

	fmt.Println("==========================================================================")
	fmt.Printf("Edit advanced configurations on %s\n", configFilePath)

	if webClientModule && len(config.ShelterConfig.WebClient.Listeners) > 0 {
		ln := config.ShelterConfig.WebClient.Listeners[0]
		url := ""

		if ln.TLS {
			url = fmt.Sprintf("https://%s:%d", ln.IP, ln.Port)
		} else {
			url = fmt.Sprintf("http://%s:%d", ln.IP, ln.Port)
		}

		fmt.Printf("Check the web client on %s\n", url)
	}

	fmt.Println("==========================================================================")
}