agent: scada client and HTTP server are tracked separately
This commit is contained in:
parent
f58bbd3c31
commit
1378fd93b0
|
@ -48,6 +48,7 @@ type Command struct {
|
||||||
httpServers []*HTTPServer
|
httpServers []*HTTPServer
|
||||||
dnsServer *DNSServer
|
dnsServer *DNSServer
|
||||||
scadaProvider *scada.Provider
|
scadaProvider *scada.Provider
|
||||||
|
scadaHttp *HTTPServer
|
||||||
}
|
}
|
||||||
|
|
||||||
// readConfig is responsible for setup of our configuration using
|
// readConfig is responsible for setup of our configuration using
|
||||||
|
@ -357,8 +358,8 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, logWriter *log
|
||||||
scadaList = list
|
scadaList = list
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Ports.HTTP > 0 || config.Ports.HTTPS > 0 || scadaList != nil {
|
if config.Ports.HTTP > 0 || config.Ports.HTTPS > 0 {
|
||||||
servers, err := NewHTTPServers(agent, config, scadaList, logOutput)
|
servers, err := NewHTTPServers(agent, config, logOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
agent.Shutdown()
|
agent.Shutdown()
|
||||||
c.Ui.Error(fmt.Sprintf("Error starting http servers: %s", err))
|
c.Ui.Error(fmt.Sprintf("Error starting http servers: %s", err))
|
||||||
|
@ -367,6 +368,10 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, logWriter *log
|
||||||
c.httpServers = servers
|
c.httpServers = servers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if scadaList != nil {
|
||||||
|
c.scadaHttp = newScadaHttp(agent, scadaList)
|
||||||
|
}
|
||||||
|
|
||||||
if config.Ports.DNS > 0 {
|
if config.Ports.DNS > 0 {
|
||||||
dnsAddr, err := config.ClientListener(config.Addresses.DNS, config.Ports.DNS)
|
dnsAddr, err := config.ClientListener(config.Addresses.DNS, config.Ports.DNS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -684,9 +689,16 @@ AFTER_MIGRATE:
|
||||||
for _, server := range c.httpServers {
|
for _, server := range c.httpServers {
|
||||||
defer server.Shutdown()
|
defer server.Shutdown()
|
||||||
}
|
}
|
||||||
if c.scadaProvider != nil {
|
|
||||||
defer c.scadaProvider.Shutdown()
|
// Check and shut down the SCADA listeners at the end
|
||||||
|
defer func() {
|
||||||
|
if c.scadaHttp != nil {
|
||||||
|
c.scadaHttp.Shutdown()
|
||||||
}
|
}
|
||||||
|
if c.scadaProvider != nil {
|
||||||
|
c.scadaProvider.Shutdown()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Join startup nodes if specified
|
// Join startup nodes if specified
|
||||||
if err := c.startupJoin(config); err != nil {
|
if err := c.startupJoin(config); err != nil {
|
||||||
|
@ -904,6 +916,24 @@ func (c *Command) handleReload(config *Config) *Config {
|
||||||
}(wp)
|
}(wp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reload the SCADA client
|
||||||
|
if c.scadaProvider != nil {
|
||||||
|
// Shut down the existing SCADA listeners
|
||||||
|
c.scadaProvider.Shutdown()
|
||||||
|
if c.scadaHttp != nil {
|
||||||
|
c.scadaHttp.Shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the new provider and listener
|
||||||
|
provider, list, err := NewProvider(newConf, c.logOutput)
|
||||||
|
if err != nil {
|
||||||
|
c.Ui.Error(fmt.Sprintf("Failed reloading SCADA client: %s", err))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
c.scadaProvider = provider
|
||||||
|
c.scadaHttp = newScadaHttp(c.agent, list)
|
||||||
|
}
|
||||||
|
|
||||||
return newConf
|
return newConf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ type HTTPServer struct {
|
||||||
|
|
||||||
// NewHTTPServers starts new HTTP servers to provide an interface to
|
// NewHTTPServers starts new HTTP servers to provide an interface to
|
||||||
// the agent.
|
// the agent.
|
||||||
func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput io.Writer) ([]*HTTPServer, error) {
|
func NewHTTPServers(agent *Agent, config *Config, logOutput io.Writer) ([]*HTTPServer, error) {
|
||||||
var servers []*HTTPServer
|
var servers []*HTTPServer
|
||||||
|
|
||||||
if config.Ports.HTTPS > 0 {
|
if config.Ports.HTTPS > 0 {
|
||||||
|
@ -142,7 +142,10 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput
|
||||||
servers = append(servers, srv)
|
servers = append(servers, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if scada != nil {
|
return servers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newScadaHttp(agent *Agent, list net.Listener) *HTTPServer {
|
||||||
// Create the mux
|
// Create the mux
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
@ -150,19 +153,15 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput
|
||||||
srv := &HTTPServer{
|
srv := &HTTPServer{
|
||||||
agent: agent,
|
agent: agent,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
listener: scada,
|
listener: list,
|
||||||
logger: log.New(logOutput, "", log.LstdFlags),
|
logger: agent.logger,
|
||||||
uiDir: config.UiDir,
|
|
||||||
addr: scadaHTTPAddr,
|
addr: scadaHTTPAddr,
|
||||||
}
|
}
|
||||||
srv.registerHandlers(false) // Never allow debug for SCADA
|
srv.registerHandlers(false) // Never allow debug for SCADA
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
go http.Serve(scada, mux)
|
go http.Serve(list, mux)
|
||||||
servers = append(servers, srv)
|
return srv
|
||||||
}
|
|
||||||
|
|
||||||
return servers, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
|
// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
|
||||||
|
|
|
@ -38,7 +38,7 @@ func makeHTTPServerWithConfig(t *testing.T, cb func(c *Config)) (string, *HTTPSe
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
conf.UiDir = uiDir
|
conf.UiDir = uiDir
|
||||||
servers, err := NewHTTPServers(agent, conf, nil, agent.logOutput)
|
servers, err := NewHTTPServers(agent, conf, agent.logOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) {
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
// Try to start the server with the same path anyways.
|
// Try to start the server with the same path anyways.
|
||||||
if _, err := NewHTTPServers(agent, conf, nil, agent.logOutput); err != nil {
|
if _, err := NewHTTPServers(agent, conf, agent.logOutput); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ func testAgentWithConfig(t *testing.T, cb func(c *agent.Config)) *agentWrapper {
|
||||||
|
|
||||||
conf.Addresses.HTTP = "127.0.0.1"
|
conf.Addresses.HTTP = "127.0.0.1"
|
||||||
httpAddr := fmt.Sprintf("127.0.0.1:%d", conf.Ports.HTTP)
|
httpAddr := fmt.Sprintf("127.0.0.1:%d", conf.Ports.HTTP)
|
||||||
http, err := agent.NewHTTPServers(a, conf, nil, os.Stderr)
|
http, err := agent.NewHTTPServers(a, conf, os.Stderr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(dir)
|
os.RemoveAll(dir)
|
||||||
t.Fatalf(fmt.Sprintf("err: %v", err))
|
t.Fatalf(fmt.Sprintf("err: %v", err))
|
||||||
|
|
Loading…
Reference in New Issue