Exemple #1
0
func main() {
	flag.Parse()

	if *fPow {
		*fDomains = "dev"
		*fDir = "~/.pow"
	}

	domains := strings.Split(*fDomains, ":")

	if *fCleanup {
		dev.Cleanup()
		return
	}

	if *fUninstall {
		dev.Uninstall(domains)
		return
	}

	if *fInstall {
		err := dev.InstallIntoSystem(*fInstallPort, *fInstallTLS, *fDir, *fDomains, (*fTimeout).String())
		if err != nil {
			log.Fatalf("Unable to install into system: %s", err)
		}
		return
	}

	if *fSetup {
		err := dev.Setup()
		if err != nil {
			log.Fatalf("Unable to configure OS X resolver: %s", err)
		}
		return
	}

	dir, err := homedir.Expand(*fDir)
	if err != nil {
		log.Fatalf("Unable to expand dir: %s", err)
	}

	err = os.MkdirAll(dir, 0755)
	if err != nil {
		log.Fatalf("Unable to create dir '%s': %s", dir, err)
	}

	var pool dev.AppPool
	pool.Dir = dir
	pool.IdleTime = *fTimeout

	purge := make(chan os.Signal, 1)

	signal.Notify(purge, syscall.SIGUSR1)

	go func() {
		for {
			<-purge
			pool.Purge()
		}
	}()

	stop := make(chan os.Signal, 1)

	signal.Notify(stop, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM)

	go func() {
		<-stop
		fmt.Printf("! Shutdown requested\n")
		pool.Purge()
		os.Exit(0)
	}()

	err = dev.ConfigureResolver(domains, *fPort)
	if err != nil {
		log.Fatalf("Unable to configure OS X resolver: %s", err)
	}

	err = dev.SetupOurCert()
	if err != nil {
		log.Fatalf("Unable to setup TLS cert: %s", err)
	}

	fmt.Printf("* Directory for apps: %s\n", dir)
	fmt.Printf("* Domains: %s\n", strings.Join(domains, ", "))
	fmt.Printf("* DNS Server port: %d\n", *fPort)

	if *fLaunch {
		fmt.Printf("* HTTP Server port: inherited from launchd\n")
		fmt.Printf("* HTTPS Server port: inherited from launchd\n")
	} else {
		fmt.Printf("* HTTP Server port: %d\n", *fHTTPPort)
		fmt.Printf("* HTTPS Server port: %d\n", *fTLSPort)
	}

	var dns dev.DNSResponder

	dns.Address = fmt.Sprintf("127.0.0.1:%d", *fPort)

	go dns.Serve(domains)

	var http dev.HTTPServer

	http.Address = fmt.Sprintf("127.0.0.1:%d", *fHTTPPort)
	http.TLSAddress = fmt.Sprintf("127.0.0.1:%d", *fTLSPort)
	http.Pool = &pool

	http.Setup()

	var (
		socketName    string
		tlsSocketName string
	)

	if *fLaunch {
		socketName = "Socket"
		tlsSocketName = "SocketTLS"
	}

	fmt.Printf("! Puma dev listening on http and https\n")

	go http.ServeTLS(tlsSocketName)

	err = http.Serve(socketName)
	if err != nil {
		log.Fatalf("Error listening: %s", err)
	}
}
Exemple #2
0
func main() {
	flag.Parse()

	domains := strings.Split(*fDomains, ":")

	if *fSysBind {
		*fHTTPPort = 80
		*fTLSPort = 443
	}

	dir, err := homedir.Expand(*fDir)
	if err != nil {
		log.Fatalf("Unable to expand dir: %s", err)
	}

	err = os.MkdirAll(dir, 0755)
	if err != nil {
		log.Fatalf("Unable to create dir '%s': %s", dir, err)
	}

	var pool dev.AppPool
	pool.Dir = dir
	pool.IdleTime = *fTimeout

	purge := make(chan os.Signal, 1)

	signal.Notify(purge, syscall.SIGUSR1)

	go func() {
		for {
			<-purge
			pool.Purge()
		}
	}()

	stop := make(chan os.Signal, 1)

	signal.Notify(stop, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM)

	go func() {
		<-stop
		fmt.Printf("! Shutdown requested\n")
		pool.Purge()
		os.Exit(0)
	}()

	err = dev.SetupOurCert()
	if err != nil {
		log.Fatalf("Unable to setup TLS cert: %s", err)
	}

	fmt.Printf("* Directory for apps: %s\n", dir)
	fmt.Printf("* Domains: %s\n", strings.Join(domains, ", "))
	fmt.Printf("* HTTP Server port: %d\n", *fHTTPPort)
	fmt.Printf("* HTTPS Server port: %d\n", *fTLSPort)

	var http dev.HTTPServer

	http.Address = fmt.Sprintf("127.0.0.1:%d", *fHTTPPort)
	http.TLSAddress = fmt.Sprintf("127.0.0.1:%d", *fTLSPort)
	http.Pool = &pool

	http.Setup()

	fmt.Printf("! Puma dev listening on http and https\n")

	go http.ServeTLS()

	err = http.Serve()
	if err != nil {
		log.Fatalf("Error listening: %s", err)
	}
}