Fix #102
This commit is contained in:
@@ -55,9 +55,8 @@ var ServerCmd = &cobra.Command{
|
|||||||
os.Setenv("KAPOW_CONTROL_URL", "http://"+sConf.DataBindAddr)
|
os.Setenv("KAPOW_CONTROL_URL", "http://"+sConf.DataBindAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
go server.StartServer(sConf)
|
server.StartServer(sConf)
|
||||||
|
|
||||||
// start sub shell + ENV(KAPOW_CONTROL_URL)
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
powfile := args[0]
|
powfile := args[0]
|
||||||
_, err := os.Stat(powfile)
|
_, err := os.Stat(powfile)
|
||||||
|
|||||||
@@ -18,10 +18,22 @@ package control
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run Starts the control server listening in bindAddr
|
// Run Starts the control server listening in bindAddr
|
||||||
func Run(bindAddr string) {
|
func Run(bindAddr string, wg *sync.WaitGroup) {
|
||||||
log.Fatal(http.ListenAndServe(bindAddr, configRouter()))
|
|
||||||
|
listener, err := net.Listen("tcp", bindAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal startup
|
||||||
|
log.Printf("ControlServer listening at %s\n", bindAddr)
|
||||||
|
wg.Done()
|
||||||
|
|
||||||
|
log.Fatal(http.Serve(listener, configRouter()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ package data
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/server/httperror"
|
"github.com/BBVA/kapow/internal/server/httperror"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -43,7 +45,7 @@ func configRouter(rs []routeSpec) (r *mux.Router) {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(bindAddr string) {
|
func Run(bindAddr string, wg *sync.WaitGroup) {
|
||||||
rs := []routeSpec{
|
rs := []routeSpec{
|
||||||
// request
|
// request
|
||||||
{"/handlers/{handlerID}/request/method", "GET", getRequestMethod},
|
{"/handlers/{handlerID}/request/method", "GET", getRequestMethod},
|
||||||
@@ -65,5 +67,15 @@ func Run(bindAddr string) {
|
|||||||
{"/handlers/{handlerID}/response/body", "PUT", lockResponseWriter(setResponseBody)},
|
{"/handlers/{handlerID}/response/body", "PUT", lockResponseWriter(setResponseBody)},
|
||||||
{"/handlers/{handlerID}/response/stream", "PUT", lockResponseWriter(setResponseBody)},
|
{"/handlers/{handlerID}/response/stream", "PUT", lockResponseWriter(setResponseBody)},
|
||||||
}
|
}
|
||||||
log.Fatal(http.ListenAndServe(bindAddr, configRouter(rs)))
|
|
||||||
|
listener, err := net.Listen("tcp", bindAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal startup
|
||||||
|
log.Printf("DataServer listening at %s\n", bindAddr)
|
||||||
|
wg.Done()
|
||||||
|
|
||||||
|
log.Fatal(http.Serve(listener, configRouter(rs)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/server/control"
|
"github.com/BBVA/kapow/internal/server/control"
|
||||||
"github.com/BBVA/kapow/internal/server/data"
|
"github.com/BBVA/kapow/internal/server/data"
|
||||||
"github.com/BBVA/kapow/internal/server/user"
|
"github.com/BBVA/kapow/internal/server/user"
|
||||||
@@ -35,10 +37,12 @@ type ServerConfig struct {
|
|||||||
|
|
||||||
// StartServer Starts one instance of each server in a goroutine and remains listening on a channel for trace events generated by them
|
// StartServer Starts one instance of each server in a goroutine and remains listening on a channel for trace events generated by them
|
||||||
func StartServer(config ServerConfig) {
|
func StartServer(config ServerConfig) {
|
||||||
go control.Run(config.ControlBindAddr)
|
var wg = sync.WaitGroup{}
|
||||||
go data.Run(config.DataBindAddr)
|
wg.Add(3)
|
||||||
go user.Run(config.UserBindAddr, config.CertFile, config.KeyFile, config.ClientCaFile, config.ClientAuth)
|
go control.Run(config.ControlBindAddr, &wg)
|
||||||
|
go data.Run(config.DataBindAddr, &wg)
|
||||||
|
go user.Run(config.UserBindAddr, &wg, config.CertFile, config.KeyFile, config.ClientCaFile, config.ClientAuth)
|
||||||
|
|
||||||
// Wait for ever
|
// Wait for servers signals in order to return
|
||||||
select {}
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/server/user/mux"
|
"github.com/BBVA/kapow/internal/server/user/mux"
|
||||||
)
|
)
|
||||||
@@ -33,12 +35,17 @@ var Server = http.Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run finishes configuring Server and runs ListenAndServe on it
|
// Run finishes configuring Server and runs ListenAndServe on it
|
||||||
func Run(bindAddr, certFile, keyFile, cliCaFile string, cliAuth bool) {
|
func Run(bindAddr string, wg *sync.WaitGroup, certFile, keyFile, cliCaFile string, cliAuth bool) {
|
||||||
Server = http.Server{
|
Server = http.Server{
|
||||||
Addr: bindAddr,
|
Addr: bindAddr,
|
||||||
Handler: mux.New(),
|
Handler: mux.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listener, err := net.Listen("tcp", bindAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if (certFile != "") && (keyFile != "") {
|
if (certFile != "") && (keyFile != "") {
|
||||||
if cliAuth {
|
if cliAuth {
|
||||||
if Server.TLSConfig == nil {
|
if Server.TLSConfig == nil {
|
||||||
@@ -59,13 +66,17 @@ func Run(bindAddr, certFile, keyFile, cliCaFile string, cliAuth bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := Server.ListenAndServeTLS(certFile, keyFile); err != http.ErrServerClosed {
|
// Signal startup
|
||||||
log.Fatalf("UserServer failed: %s", err)
|
log.Printf("UserServer listening at %s\n", bindAddr)
|
||||||
}
|
wg.Done()
|
||||||
|
|
||||||
|
log.Fatal(Server.ServeTLS(listener, certFile, keyFile))
|
||||||
} else {
|
} else {
|
||||||
if err := Server.ListenAndServe(); err != http.ErrServerClosed {
|
// Signal startup
|
||||||
log.Fatalf("UserServer failed: %s", err)
|
log.Printf("UserServer listening at %s\n", bindAddr)
|
||||||
}
|
wg.Done()
|
||||||
|
|
||||||
|
log.Fatal(Server.Serve(listener))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user