Beispiel #1
0
// Starts up Luminos.
func main() {
	flag.Parse()

	if *flagHelp == true {
		fmt.Printf("Showing %v usage.\n", os.Args[0])
		flag.PrintDefaults()
		return
	}

	if *flagVersion == true {
		fmt.Printf("%v version: %s\n", os.Args[0], version)
		return
	}

	hosts = make(map[string]*host.Host)

	settings = yaml.Open(*flagSettings)

	serverType := settings.GetString("server/type")

	domain := "unix"
	address := settings.GetString("server/socket")

	if address == "" {
		domain = "tcp"
		address = fmt.Sprintf("%s:%d", settings.GetString("server/bind"), settings.GetInt("server/port"))
	}

	listener, err := net.Listen(domain, address)

	if err != nil {
		log.Fatalf("Failed to bind on %s.", address)
	}

	defer listener.Close()

	switch serverType {
	case "fastcgi":
		if err == nil {
			log.Printf("FastCGI server listening at %s.", address)
			fcgi.Serve(listener, &Server{})
		} else {
			log.Fatalf("Failed to start FastCGI server.")
		}
	case "standalone":
		if err == nil {
			log.Printf("HTTP server listening at %s.", address)
			http.Serve(listener, &Server{})
		} else {
			log.Fatalf("Failed to start HTTP server.")
		}
	default:
		log.Fatalf("Unknown server type %s.", serverType)
	}

	log.Printf("Exiting...")
}
Beispiel #2
0
// Loads settings into Host.Settings
func (host *Host) loadSettings() bool {
	file := host.DocumentRoot + PS + "luminos.yaml"
	_, err := os.Stat(file)
	if err == nil {
		host.Settings = yaml.Open(file)
		return true
	} else {
		log.Printf("%s: seems like %s does not exists.\n", host.Name, file)
	}
	return false
}