Exemple #1
0
func (s *ServerApp) Run(exit chan interface{}) {
	go manners.ListenAndServe(fmt.Sprintf(":%s", s.Port), s.Mux)

	<-exit

	manners.Close()
}
Exemple #2
0
// main is the entry point for the application.
func main() {
	log.Println("main : Started")

	// Check the environment for a configured port value.
	port := os.Getenv("PORT")
	if port == "" {
		port = "3000"
	}

	// Create this goroutine to run the web server.
	go func() {
		log.Println("listener : Started : Listening on: http://localhost:" + port)
		manners.ListenAndServe(":"+port, routes.API())
	}()

	// Listen for an interrupt signal from the OS.
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, os.Interrupt)
	<-sigChan

	log.Println("main : Shutting down...")
	manners.Close()

	log.Println("main : Completed")
}
Exemple #3
0
func StopServer() {

	l4g.Info("Stopping Server...")

	manners.Close()
	Srv.Store.Close()
	hub.Stop()

	l4g.Info("Server stopped")
}
Exemple #4
0
func StopServer() {

	l4g.Info(utils.T("api.server.stop_server.stopping.info"))

	manners.Close()
	Srv.Store.Close()
	hub.Stop()

	l4g.Info(utils.T("api.server.stop_server.stopped.info"))
}
Exemple #5
0
func runServerWithGui(chain *nigella.Nigella) {
	var wg sync.WaitGroup

	listener, err := net.Listen("tcp", `127.0.0.1:0`)
	if err != nil {
		log.Fatalf("ERROR: %s", err.Error())
		return
	}
	port := listener.Addr().(*net.TCPAddr).Port
	portAsString := strconv.Itoa(port)

	log.Infof("Server Listing on http://localhost:%s ", portAsString)

	ServerFunc := func() {
		defer wg.Done()
		log.Info("Running Server")
		manners.Serve(listener, chain)
	}

	//===== start the GUI ===========
	GuiFunc := func() {
		defer wg.Done()

		time.Sleep(1 * time.Second)

		var exeRoot string
		var err error

		exeRoot, err = osext.ExecutableFolder()
		if err != nil {
			log.Fatalf("ERROR: %s", err.Error())
		} else {
			log.Info("EXE Root: " + exeRoot)
		}

		ClientFilePath := filepath.Join(exeRoot, `client`, `Malkovich Client.exe`)

		ClientCmd := exec.Command(ClientFilePath, portAsString)
		err = ClientCmd.Run()
		if err != nil {
			log.Fatal(err)
		}

		manners.Close()
	}

	wg.Add(1)
	wg.Add(1)
	go ServerFunc()
	go GuiFunc()
	wg.Wait()

	log.Info("Everything has finished.")
}
Exemple #6
0
//Stop stops GohanAPIServer
func (server *Server) Stop() {
	server.running = false
	if server.sync != nil {
		stopSyncProcess(server)
		stopStateUpdatingProcess(server)
		stopSyncWatchProcess(server)
	}
	stopAMQPProcess(server)
	stopSNMPProcess(server)
	stopCRONProcess(server)
	manners.Close()
	server.queue.Stop()
}
func cant_take_it_anymore(max int) {
	pingTicker := time.NewTicker(1 * time.Second)
	defer func() {
		pingTicker.Stop()
	}()

	for {
		select {
		case <-pingTicker.C:
			if atomic.LoadUint64(&ops) >= uint64(max) {
				manners.Close()
			}
		}
	}
}
Exemple #8
0
Fichier : ran.go Projet : mix3/ran
func (srv *server) ListenAndServe() error {
	l, err := srv.newListener()
	if err != nil {
		return err
	}

	go func() {
		sigchan := make(chan os.Signal, 1)
		signal.Notify(sigchan, srv.sigs...)
		<-sigchan
		log.Println("Shutting down...")
		manners.Close()
	}()

	log.Println("listen and server on " + srv.m.Addr)
	return srv.m.Serve(l)
}
Exemple #9
0
func main() {
	var err error

	// Connect to the local nats server.
	rawConn, err = nats.Connect(nats.DefaultURL)
	if err != nil {
		log.Println("ERROR: Unable to connect to NATS")
		return
	}

	// Create an encoded connection
	conn, err = nats.NewEncodedConn(rawConn, nats.JSON_ENCODER)
	if err != nil {
		log.Println("ERROR: Unable to create an encoded connection")
		return
	}

	// Support for shutting down cleanly.
	go func() {

		// Listen for an interrupt signal from the OS.
		sigChan := make(chan os.Signal, 1)
		signal.Notify(sigChan, os.Interrupt)
		<-sigChan

		log.Println("Starting shutdown...")
		log.Println("Waiting on requests to complete...")

		// We have been asked to shutdown the server.
		manners.Close()
	}()

	// Bind routes.
	http.HandleFunc("/users", GetUsers)

	// Start the web service.
	const host = "localhost:8080"
	log.Printf("Listening on: %s\n", host)
	manners.ListenAndServe(host, http.DefaultServeMux)

	// Close the connection to the NATS server.
	log.Println("Waiting on NATS to close...")
	conn.Close()
}
Exemple #10
0
func waitShutdown(app application.Application) {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)

	go func() {
		<-c
		fmt.Println()
		log.Info.Pf("gracefully shutting down")

		log.Info.Pf("stopping http listener")
		manners.Close()
		log.Info.Pf("http listener stopped")

		app.Cleanup()

		log.Info.Pf("shutdown finished")
		os.Exit(1)
	}()
}
Exemple #11
0
// Stop stops the registered service matching the given prefix key.
//
func (s *Srv) Stop(key string) error {
	app, ok := s.list[key]
	if !ok {
		return errors.New("stop webservice: key not found")
	}
	if !app.started {
		return nil
	}

	app.started = false

	started := false
	for _, v := range s.list {
		started = started || v.started
	}

	if !started {
		manners.Close()
	}
	return nil
}
Exemple #12
0
func (m *MxpSink) Start(sigs <-chan bool, done chan<- bool) {
	log.Printf("* Starting MxpSink on port %d", m.Port)

	r := mux.NewRouter().StrictSlash(false)

	r.HandleFunc("/", m.rootHandler).Methods("GET")

	r.HandleFunc("/track", m.trackGetHandler).Methods("GET")
	r.HandleFunc("/track", m.trackPostHandler).Methods("POST")

	r.HandleFunc("/import", m.importGetHandler).Methods("GET")
	r.HandleFunc("/import", m.importPostHandler).Methods("POST")

	incomingBeaconKiller := make(chan bool)
	incomingBeaconStopped := make(chan bool)

	incomingAliasKiller := make(chan bool)
	incomingAliasStopped := make(chan bool)

	go m.incomingBeaconConsumer(incomingBeaconKiller, incomingBeaconStopped)
	go m.incomingAliasConsumer(incomingAliasKiller, incomingAliasStopped)

	go func() {
		sig := <-sigs
		log.Println("Stopping MxpSink", sig)
		incomingBeaconKiller <- true
		incomingAliasKiller <- true
		manners.Close()
	}()

	if err := manners.ListenAndServe(fmt.Sprintf(":%d", m.Port), r); err != nil {
		log.Fatal(err)
	}

	<-incomingAliasStopped
	<-incomingBeaconStopped

	done <- true
}
Exemple #13
0
func run() error {
	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, syscall.SIGTERM)
	go func() {
		for {
			s := <-signalChan
			if s == syscall.SIGTERM {
				manners.Close()
			}
		}
	}()

	listeners, err := listener.ListenAll()
	if err != nil {
		return err
	}

	var l net.Listener
	if len(listeners) > 0 {
		l = listeners[0]
	} else {
		l, err = net.Listen("tcp", ":13000")
		if err != nil {
			return err
		}
	}

	mux := http.NewServeMux()

	entries := []struct {
		Path   string
		Source scraper.Source
	}{
		{"/character-show", scraper.NewCharacterShowSource()},
		{"/fukoku-life", scraper.NewFukokuLifeEventSource()},
		{"/harmonyland-info", scraper.NewHarmonylandInfoSource()},
		{"/kittychan-info", scraper.NewKittychanInfoSource()},
		{"/memoirs-of-shibasaki-saki", scraper.NewMemoirsOfShibasakiSakiSource()},
		{"/prtimes-sanrio", scraper.NewPRTimesSource()},
		{"/puroland-info", scraper.NewPurolandInfoSource()},
		{"/sanrio-news-release", scraper.NewSanrioNewsReleaseSource()},
		{"/seibuen-event", scraper.NewSeibuenEventSource()},
		{"/value-press-sanrio", scraper.NewValuePressSource()},
	}
	for _, entry := range entries {
		mux.HandleFunc(entry.Path, sourceRenderer(entry.Source))
	}

	mux.HandleFunc("/facebook", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		id := query.Get("id")
		if id == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewFacebookSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	mux.HandleFunc("/google-calendar", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		id := query.Get("id")
		if id == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewGoogleCalendarSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	mux.HandleFunc("/instagram", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		id := query.Get("id")
		if id == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewInstagramSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	mux.HandleFunc("/twitter", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		idStr := query.Get("id")
		if idStr == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		id, err := strconv.ParseInt(idStr, 10, 64)
		if err != nil {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewTwitterSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	manners.Serve(l, mux)
	return nil
}
Exemple #14
0
//Stop gracefully stops the API and the callback listener
func (c2b *C2B) Stop() {
	server.Close()
	c2b.callback <- nil
	fmt.Println("C2B stopped")
}
Exemple #15
0
// Stop stops the http server api
func (cli *HTTPAPIServer) Stop() {
	logrus.Infof("Plugin: httpapi: requesting shutdown")
	manners.Close()
}
Exemple #16
0
func listenForShutdown(shutdown <-chan struct{}) {
	log.Println("http.graceful.await")
	<-shutdown
	log.Println("http.graceful.shutdown")
	manners.Close()
}
func listenForShutdown(ch <-chan os.Signal) {
	<-ch
	manners.Close()
}
Exemple #18
0
// Intended to be run as a goroutine.
func StopSoon(t time.Duration, done chan bool) {
	time.Sleep(t * time.Second)
	manners.Close()

	done <- true
}
Exemple #19
0
func Stop() {
	LogInfo("Stopping Server...")
	manners.Close()
}