Ejemplo n.º 1
0
func init() {
	flag.Parse()

	log.PrintDebug = *debug
	log.Fileformat = func(now string, i int) string { return fmt.Sprintf("logs/%[1]s-%02[2]d.log", now, i) }
	log.Init()
	lang.Load()
	config.IndentConfig = *debug
	config.Load()

	if !*disableSafeShutdown {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, syscall.SIGTERM)
		go func() {
			<-c
			Shutdown("Interrupt/SIGTERM")
		}()
	}

	data, err := ioutil.ReadFile("/etc/hostname")
	if err != nil {
		log.Fatalln("Failed to read hostname: %s", err)
		return
	}
	hostname = strings.TrimSpace(string(data))
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	if !*disableSafeShutdown {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, syscall.SIGTERM)
		go func() {
			<-c
			os.Stdout.Write([]byte("\n"))
			log.Infof("Shutting down mauImageServer...")
			database.Unload()
			os.Exit(0)
		}()
	}

	// Configure the logger
	if *debug {
		log.PrintLevel = 0
	}
	os.MkdirAll(*logPath, 0755)
	log.Fileformat = func(date string, i int) string {
		return filepath.Join(*logPath, fmt.Sprintf("%[1]s-%02[2]d.log", date, i))
	}
	// Initialize the logger
	log.Init()

	log.Infof("Initializing mauImageServer " + version)
	loadConfig()
	loadDatabase()
	loadTemplates()

	handlers.Init(config, database, auth)

	log.Infof("Registering handlers")
	http.HandleFunc("/auth/login", handlers.Login)
	http.HandleFunc("/auth/register", handlers.Register)
	http.HandleFunc("/insert", handlers.Insert)
	http.HandleFunc("/delete", handlers.Delete)
	http.HandleFunc("/hide", handlers.Hide)
	http.HandleFunc("/search", handlers.Search)
	http.HandleFunc("/", handlers.Get)
	log.Infof("Listening on %s:%d", config.IP, config.Port)
	http.ListenAndServe(config.IP+":"+strconv.Itoa(config.Port), nil)
}
Ejemplo n.º 3
0
func main() {
	// Configure the logger
	log.PrintDebug = *debug
	log.Fileformat = func(date string, i int) string { return fmt.Sprintf("%[3]s/%[1]s-%02[2]d.log", date, i, *logPath) }

	// Initialize the logger
	log.Init()
	log.Infof("Initializing mau\\Lu")

	loadConfig()
	loadTemplates()
	loadDatabase()

	if *stdin {
		go stdinListen()
	}

	log.Infof("Listening on %s:%d", config.IP, config.Port)
	http.HandleFunc("/query/", query)
	http.HandleFunc("/", get)
	http.ListenAndServe(config.IP+":"+strconv.Itoa(config.Port), nil)
}