Exemplo n.º 1
0
// Run is a convenience function that runs Engine as an HTTP
// server.
func (e *Engine) rawStart(ssl bool, certFile string, keyFile string) error {
	go func() {
		logutils.PrintH1("Server ready and listening on port%s", e.HttpServer.Addr)
		if ssl {
			e.errorC <- e.HttpServer.ListenAndServeTLS(certFile, keyFile)
		} else {
			e.errorC <- e.HttpServer.ListenAndServe()
		}

	}()

	//Block until either a signal or an error is received
	// based on service.go of vulcand project
	signal.Notify(e.sigC, syscall.SIGTERM, syscall.SIGINT, os.Kill, syscall.SIGUSR2, syscall.SIGCHLD)

	for {
		select {
		case signal := <-e.sigC:
			switch signal {
			case syscall.SIGTERM, syscall.SIGINT:
				fmt.Printf("\n")
				logutils.PrintH2("Received signal: %s!, shutting down gracefully...", signal)
				// put me a supevisor here
				logutils.PrintH1("Server stopped")
				//cleanupDone <- true
				return nil
			case syscall.SIGUSR1:
				return nil
				//default:
				//	fmt.Printf("Ignoring signal: `%s`", signal)
			}
		case err := <-e.errorC:
			logutils.PrintH1("Internal HttpServer Error: %s", err)
		}
	}
}
Exemplo n.º 2
0
func (e *Engine) OnChangeProxy(target proxy.ApiProxySpec) {
	e.GetHandler().GetRouter().Register(target)
	logutils.PrintH2("Setting up api (%s) ... done", target.GetId())
}