Example #1
0
func getConfig() Config {
	var conf Config
	if err := gcfg.ReadFileInto(&conf, "config.ini"); err != nil {
		log.Fatal("Error parsing configuration : ", err)
	}
	return conf
}
Example #2
0
func LoadConf(path string) (MqttConf, InfluxDBConf, error) {
	home := UserHomeDir()
	path = strings.Replace(path, "~", home, 1)

	var cfg Config
	err := gcfg.ReadFileInto(&cfg, path)
	if err != nil {
		return MqttConf{}, InfluxDBConf{}, err
	}

	em := MqttConf{}
	ei := InfluxDBConf{}

	if cfg.Mqtt == em {
		log.Fatal(`empty "mqforward-mqtt" configuration`)
	}
	if cfg.InfluxDB == ei {
		log.Fatal(`empty "mqforward-influxdb" configuration`)
	}

	if cfg.General.Debug {
		log.SetLevel(log.DebugLevel)
	}

	return cfg.Mqtt, cfg.InfluxDB, nil
}
Example #3
0
func loadConfig(cfgFile string) Config {
	var cfg configFile
	err := gcfg.ReadFileInto(&cfg, cfgFile)
	if err != nil {
		fmt.Errorf("Error reading config file: %s", err)
	}
	return cfg.Muzfinder
}
Example #4
0
func (master *Master) Init(config_path string) {
	err := gcfg.ReadFileInto(&master.config, config_path)
	if err != nil {
		panic(err)
	}
	master.job_queue = NewRedisQueue(master.config.Common.JobQueueAddr, master.config.Common.JobQueuePwd)
	master.worker_map = make(map[string]*WorkerStatus)
	master.job_store = NewMysqlStore(master.config.Common.JobStoreAddr)
}
Example #5
0
func (worker *Worker) Init(config_path string) {
	err := gcfg.ReadFileInto(&worker.config, config_path)
	if err != nil {
		panic(err)
	}

	worker.ip = getAddr()
	fmt.Println("ip=", worker.ip)
	worker.job_list = make(map[string]*Job)
	worker.job_queue = NewRedisQueue(worker.config.Common.JobQueueAddr, worker.config.Common.JobQueuePwd)
}
Example #6
0
func ConfigLoadSecret(filename, keyfile string) (config Remote) {
	if err := gcfg.ReadFileInto(&config, filename); err != nil {
		log.Fatal(err.Error())
	}
	if keydata, err := ioutil.ReadFile(keyfile); err != nil {
		log.Fatal(err.Error())
	} else {
		SetKey(string(keydata))
		config.Public()
	}
	return
}
Example #7
0
func loadConfig(cfgFile string) Config {
	var cfg configFile
	err := gcfg.ReadFileInto(&cfg, cfgFile)
	if err != nil {
		fmt.Errorf("Error reading config file: %s", err)
	}
	if cfg.Fmdupes.CountDuplicates == 0 {
		cfg.Fmdupes.CountDuplicates = 2
	}

	return cfg.Fmdupes
}
Example #8
0
func main() {
	flag.Parse()
	daemon.AddCommand(daemon.StringFlag(signal, "quit"), syscall.SIGQUIT, termHandler)
	daemon.AddCommand(daemon.StringFlag(signal, "stop"), syscall.SIGTERM, termHandler)

	error := gcfg.ReadFileInto(&cfg, "config")
	if error != nil {
		fmt.Println(error)
		return
	}

	cntxt := &daemon.Context{
		PidFileName: cfg.General.PidFileName,
		PidFilePerm: 0644,
		LogFileName: cfg.General.LogFileName,
		LogFilePerm: 0640,
		WorkDir:     "./",
		Umask:       027,
		Args:        []string{},
	}

	if len(daemon.ActiveFlags()) > 0 {
		d, err := cntxt.Search()
		if err != nil {
			log.Fatalln("Unable send signal to the daemon:", err)
		}
		daemon.SendCommands(d)
		return
	}

	d, err := cntxt.Reborn()
	if err != nil {
		log.Fatalln(err)
	}
	if d != nil {
		return
	}
	defer cntxt.Release()

	log.Println("- - - - - - - - - - - - - - -")
	log.Println("daemon started")

	go worker()

	err = daemon.ServeSignals()
	if err != nil {
		log.Println("Error:", err)
	}
	log.Println("daemon terminated")
}
Example #9
0
func NewConfig(p string) (*Config, error) {
	c := Config{
		Update_Interval_Seconds: defaultUpdateInterval,
		Storage_Location:        defaultStorageLocation,
		Live_Size:               defaultLiveSize,
		Web_Server_Bind_Address: defaultBindAddress,
		Web_Root:                defaultWebRoot,
	}
	fc := fconfig{
		Interface_Config: c,
	}
	if err := cfg.ReadFileInto(&fc, p); err != nil {
		return nil, err
	}
	return &fc.Interface_Config, nil
}
Example #10
0
func ReadModuleConfig(cfg interface{}, path string, module string) bool {
	environ := os.Getenv("TKPENV")
	if environ == "" {
		environ = "development"
	}

	debug := Debug.Println

	fname := path + "/" + module + "." + environ + ".ini"
	err := gcfg.ReadFileInto(cfg, fname)
	if err == nil {
		debug("read config from ", fname)
		return true
	}
	debug(err)
	return false
}
Example #11
0
func main() {
	rand.Seed(time.Now().UTC().UnixNano())
	flag.Parse()

	var cfg Config
	err := gcfg.ReadFileInto(&cfg, *config)
	if err != nil {
		log.Fatalf("ERROR can't load config %s: %s", err)
	}

	addr := cfg.Server.Address
	templates, err := template.ParseGlob(cfg.Server.Templates + "/*")
	if err != nil {
		log.Fatalf("ERROR can't load templates: %s", err)
	}

	lobby := server.NewLobby(templates, cfg.Texts.File, cfg.Race.CountdownSeconds)

	r := pat.New()
	r.Get("/ws/{race_code}", lobby.Ws_handler)
	r.Get("/zavod/{race_code}", lobby.Race_handler)
	r.Get("/zavod", lobby.Race_creator_handler)
	r.Get("/", lobby.Lobby_handler)

	// get all static directories from config and create fileserver
	// for each one of them
	for _, s := range cfg.Server.Static {
		endpoint, dir, err := parse_static_location(s)
		if err != nil {
			log.Fatalf("ERROR %s", err)
		}

		fileserver := http.FileServer(http.Dir(dir))
		http.Handle(endpoint, http.StripPrefix(endpoint, fileserver))
		log.Printf("INFO serving static files from %s on %s", dir, endpoint)
	}

	http.Handle("/", r)

	log.Println("INFO serving on", addr)
	if err := http.ListenAndServe(addr, nil); err != nil {
		log.Fatal("ERROR ListenAndServe: ", err)
	}
}
Example #12
0
func updateFlagsByConfig(configFile string, flagSet *flag.FlagSet) error {
	config := struct {
		Fluentd_Forwarder struct {
			Retry_interval     string `retry-interval`
			Conn_timeout       string `conn-timeout`
			Write_timeout      string `write-timeout`
			Flush_interval     string `flush-interval`
			Listen_on          string `listen-on`
			To                 string `to`
			Buffer_path        string `buffer-path`
			Buffer_chunk_limit string `buffer-chunk-limit`
			Log_level          string `log-level`
			Ca_certs           string `ca-certs`
			Cpuprofile         string `cpuprofile`
			Log_file           string `log-file`
		}
	}{}
	err := gcfg.ReadFileInto(&config, configFile)
	if err != nil {
		return err
	}
	r := reflect.ValueOf(config.Fluentd_Forwarder)
	rt := r.Type()
	for i, l := 0, rt.NumField(); i < l; i += 1 {
		f := rt.Field(i)
		fv := r.Field(i)
		v := fv.String()
		if v != "" {
			err := flagSet.Set(string(f.Tag), v)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Example #13
0
func main() {
	// get config
	confPath := fmt.Sprintf("%s/.config/irkbot/irkbot.ini", os.Getenv("HOME"))
	cfg := lib.Config{}
	err := gcfg.ReadFileInto(&cfg, confPath)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	conn := goirc.IRC(cfg.User.Nick, cfg.User.User)
	err = conn.Connect(fmt.Sprintf(
		"%s:%s",
		cfg.Server.Host,
		cfg.Server.Port))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	conn.VerboseCallbackHandler = cfg.Connection.Verbose_callback_handler
	conn.Debug = cfg.Connection.Debug

	conn.AddCallback("001", func(e *goirc.Event) {
		conn.Join(cfg.Channel.Channelname)
	})

	conn.AddCallback("366", func(e *goirc.Event) {
		if len(cfg.Channel.Greeting) != 0 {
			conn.Privmsg(e.Arguments[1], cfg.Channel.Greeting)
		}
	})

	// register modules
	var pmMods []*lib.Module
	modpm.RegisterMods(func(m *lib.Module) {
		pmMods = append(pmMods, m)
		if m.Configure != nil {
			m.Configure(&cfg)
		}
	})

	// TODO: start multiple sayLoops, one per conn
	// TODO: pass conn to sayLoop instead of privmsg callbacks?
	sayChan := make(chan lib.SayMsg)
	go lib.SayLoop(sayChan)

	conn.AddCallback("PRIVMSG", func(e *goirc.Event) {
		p := lib.Privmsg{}
		p.Msg = e.Message()
		p.MsgArgs = strings.Split(p.Msg, " ")
		p.Dest = e.Arguments[0]
		if !strings.HasPrefix(p.Dest, "#") {
			p.Dest = e.Nick
		}
		p.Event = e
		p.Conn = conn
		p.SayChan = sayChan

		for _, mod := range pmMods {
			if mod.Run(&p) {
				break
			}
		}
	})

	// TODO: add time-based modules

	conn.Loop()
}
Example #14
0
func ConfigLoad(filename string) (config Remote, err error) {
	err = gcfg.ReadFileInto(&config, filename)
	return
}
Example #15
0
func main() {
	var (
		logfilename string
		logw        reopener
		pubtktKey   string
		fedoraAddr  string
		configFile  string
		config      config
		showVersion bool
	)

	flag.StringVar(&logfilename, "log", "", "name of log file. Defaults to stdout")
	flag.StringVar(&pubtktKey, "pubtkt-key", "",
		"filename of PEM encoded public key to use for pubtkt authentication")
	flag.StringVar(&fedoraAddr, "fedora", "",
		"url to use for fedora, includes username and password, if needed")
	flag.StringVar(&configFile, "config", "",
		"name of config file to use")
	flag.StringVar(&pidfilename, "pid", "", "file to store pid of server")
	flag.BoolVar(&showVersion, "version", false, "Display the version and exit")

	flag.Parse()

	if showVersion {
		fmt.Printf("disadis version %s\n", Version)
		return
	}

	// the config file stuff was grafted onto the command line options
	// this should be made pretty
	if configFile != "" {
		err := gcfg.ReadFileInto(&config, configFile)
		if err != nil {
			log.Println(err)
		}
		logfilename = config.General.Log_filename
		fedoraAddr = config.General.Fedora_addr
		pubtktKey = config.Pubtkt.Key_file
	}

	/* first set up the log file */
	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
	logw = newReopener(logfilename)
	logw.Reopen()
	log.Println("-----Starting Disadis Server", Version)

	/* set up signal handlers */
	sig := make(chan os.Signal, 5)
	signal.Notify(sig, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGUSR2)
	go signalHandler(sig, logw)

	/* Now set up the handler chains */
	if fedoraAddr == "" {
		log.Printf("Error: Fedora address must be set. (--fedora <server addr>)")
		os.Exit(1)
	}
	fedora := fedora.NewRemote(fedoraAddr, "")
	ha := auth.NewHydraAuth(fedoraAddr, "")
	ha.Admin = config.General.Admin
	log.Println("Admin users:", ha.Admin)
	switch {
	case pubtktKey != "":
		log.Printf("Using pubtkt %s", pubtktKey)
		ha.CurrentUser = auth.NewPubtktAuthFromKeyFile(pubtktKey)
	default:
		log.Printf("Warning: No authorization method given.")
	}
	if len(config.Handler) == 0 {
		log.Printf("No Handlers are defined. Exiting.")
		return
	}

	if pidfilename != "" {
		writePID(pidfilename)
	}

	runHandlers(config, fedora, ha)

	if pidfilename != "" {
		os.Remove(pidfilename)
	}
}