Improved the startup for a new environment

This commit is contained in:
Thorsten Sommer committed 2015-06-21 20:20:27 +02:00
1 parent 16ac349049
commit e1465c2fd0
7 files changed
+148 -85

No files matched your search

+11 -3
View File
@@ -7,6 +7,7 @@ import (
LM "github.com/SommerEngineering/Ocean/Log/Meta"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"os"
"strconv"
"strings"
"time"
@@ -14,6 +15,12 @@ import (
// Init the database for the logging.
func initDatabase() {
defer func() {
if err := recover(); err != nil {
fmt.Printf("[Error] Was not able to connect to the logging database: %s. Please read https://github.com/SommerEngineering/Ocean.\n", err)
os.Exit(0)
}
}()
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Checking and init the logging database collection.`)
defer Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Checking and init the logging database collection done.`)
@@ -49,7 +56,8 @@ func initDatabase() {
// Connect to MongoDB:
if newSession, errDial := mgo.Dial(databaseHost); errDial != nil {
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `It was not possible to connect to the MongoDB host `+databaseHost, errDial.Error())
return
fmt.Printf("[Error] Was not able to connect to the logging database: %s. Please read https://github.com/SommerEngineering/Ocean.\n", errDial.Error())
os.Exit(0)
} else {
logDBSession = newSession
}
@@ -60,7 +68,8 @@ func initDatabase() {
// Login:
if errLogin := logDB.Login(databaseUsername, databasePassword); errLogin != nil {
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelSECURITY, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `It was not possible to login the user `+databaseUsername, errLogin.Error())
return
fmt.Printf("[Error] Was not able to connect to the logging database: %s. Please read https://github.com/SommerEngineering/Ocean.\n", errLogin.Error())
os.Exit(0)
}
// Get the collection:
@@ -215,5 +224,4 @@ func initDatabase() {
indexTimeUTCMessageDescription := mgo.Index{}
indexProjectTimeUTCMessageDescription.Key = []string{`TimeUTC`, `MessageDescription`}
logDBCollection.EnsureIndex(indexTimeUTCMessageDescription)
}
+8 -4
View File
@@ -1,6 +1,7 @@
package Log
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -12,23 +13,26 @@ func readProjectName() {
// Try to get access to the working directory:
if currentDir, dirError := os.Getwd(); dirError != nil {
// Case: Error! Stop the server.
panic(`Cannot read the current working directory and therefore cannot read the project name!`)
fmt.Printf("[Error] Was not able to read the working directory. %s\n", dirError.Error())
os.Exit(0)
} else {
// Try to get access to the file:
filename := filepath.Join(currentDir, `project.name`)
if _, errFile := os.Stat(filename); errFile != nil {
// Cases: Error.
if os.IsNotExist(errFile) {
panic(`Cannot read the project name file 'project.name': File not found!`)
fmt.Printf("[Error] Cannot read the project name file 'project.name': File not found! Please read https://github.com/SommerEngineering/Ocean\n")
} else {
panic(`Cannot read the project name file 'project.name': ` + errFile.Error())
fmt.Printf("[Error] Cannot read the project name file 'project.name': %s. Please read https://github.com/SommerEngineering/Ocean\n", errFile.Error())
}
os.Exit(0)
}
// Try to read the file:
if projectNameBytes, errRead := ioutil.ReadFile(filename); errRead != nil {
// Case: Error.
panic(`Cannot read the project name file 'project.name': ` + errRead.Error())
fmt.Printf("[Error] Cannot read the project name file 'project.name': %s. Please read https://github.com/SommerEngineering/Ocean\n", errRead.Error())
os.Exit(0)
} else {
// Store the project name:
projectName = string(projectNameBytes)