2014-11-06 16:49:04 +00:00
package WebServer
import (
2015-06-21 18:18:23 +00:00
"fmt"
2014-11-06 16:49:04 +00:00
"github.com/SommerEngineering/Ocean/ICCC"
2014-11-07 09:46:33 +00:00
"github.com/SommerEngineering/Ocean/ICCC/SystemMessages"
2014-11-06 16:49:04 +00:00
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
2015-07-10 14:20:10 +00:00
"github.com/SommerEngineering/Ocean/System/Version"
2014-11-06 16:49:04 +00:00
)
func Start ( ) {
2014-11-07 09:46:33 +00:00
// Tell the whole cluster, that we are up and ready:
2015-07-09 18:19:01 +00:00
data := SystemMessages . ICCCOceanStartUpMessage { }
2015-07-10 14:20:10 +00:00
data . OceanVersion = Version . GetVersion ( )
2014-11-07 09:46:33 +00:00
2015-06-17 15:44:52 +00:00
// Start the public web server:
2014-11-07 09:46:33 +00:00
if serverPublic != nil {
2015-07-09 18:19:01 +00:00
data . PublicIPAddressPort = serverPublicAddressPort
2014-11-07 09:46:33 +00:00
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameSTARTUP , ` Public web server is now listening. ` , ` Configuration for hostname and port. ` , serverPublicAddressPort )
2014-11-06 16:49:04 +00:00
go serverPublic . ListenAndServe ( )
}
2015-06-17 15:44:52 +00:00
// Start the private web server:
2014-11-06 16:49:04 +00:00
if serverAdmin != nil {
2015-07-09 18:19:01 +00:00
data . AdminIPAddressPort = serverAdminAddressPort
2014-11-07 09:46:33 +00:00
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameSTARTUP , ` Admin web server is now listening. ` , ` Configuration for hostname and port. ` , serverAdminAddressPort )
2014-11-06 16:49:04 +00:00
go serverAdmin . ListenAndServe ( )
}
2014-11-07 16:31:21 +00:00
2015-06-17 15:44:52 +00:00
// Notify the whole cluster, that this server is now up and ready:
2015-07-10 12:36:47 +00:00
answers := ICCC . WriteMessage2All ( ICCC . ChannelSTARTUP , ` System::OceanStart ` , data , SystemMessages . ICCCDefaultAnswer { } )
2015-06-21 18:18:23 +00:00
for n , obj := range answers {
if obj != nil {
2015-07-09 18:19:01 +00:00
answer := obj . ( SystemMessages . ICCCDefaultAnswer )
2015-06-21 18:18:23 +00:00
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameSTARTUP , fmt . Sprintf ( "An answer to the ICCC start up message: Successful=%v, Status=%d, Answer=%d/%d" , answer . CommandSuccessful , answer . CommandAnswer , n + 1 , len ( answers ) ) )
}
}
2014-11-06 16:49:04 +00:00
}