mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Fix IcingaDB not starting without MySQL & Redis connection
fixes #9 fixes #10
This commit is contained in:
parent
379d3b7ba7
commit
e2eb43ec4d
3 changed files with 10 additions and 5 deletions
|
|
@ -32,6 +32,7 @@ type DbTransaction interface {
|
|||
}
|
||||
|
||||
func NewDBWrapper(dbDsn string) (*DBWrapper, error) {
|
||||
log.Info("Connecting to MySQL")
|
||||
db, err := mkMysql("mysql", dbDsn)
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -43,7 +44,10 @@ func NewDBWrapper(dbDsn string) (*DBWrapper, error) {
|
|||
|
||||
err = dbw.Db.Ping()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
log.WithFields(log.Fields{
|
||||
"context": "sql",
|
||||
"error": err,
|
||||
}).Error("Could not connect to SQL. Trying again")
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
oldlog "log"
|
||||
"reflect"
|
||||
|
|
@ -17,8 +16,6 @@ import (
|
|||
|
||||
// mkMysql creates a new MySQL client.
|
||||
func mkMysql(dbType string, dbDsn string) (*sql.DB, error) {
|
||||
log.Info("Connecting to MySQL")
|
||||
|
||||
sep := "?"
|
||||
|
||||
if dbDsn == "" {
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ func (rdbw *RDBWrapper) CompareAndSetConnected(connected bool) (swapped bool) {
|
|||
}
|
||||
|
||||
func NewRDBWrapper(address string) (*RDBWrapper, error) {
|
||||
log.Info("Connecting to Redis")
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: address,
|
||||
DialTimeout: time.Minute / 2,
|
||||
|
|
@ -110,7 +111,10 @@ func NewRDBWrapper(address string) (*RDBWrapper, error) {
|
|||
|
||||
_, err := rdbw.Rdb.Ping().Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
log.WithFields(log.Fields{
|
||||
"context": "redis",
|
||||
"error": err,
|
||||
}).Error("Could not connect to Redis. Trying again")
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue