mirror of
https://github.com/gophish/gophish
synced 2024-11-14 16:27:23 +00:00
Wait for db (#1402)
Added a loop that attempts to connect to the configured database.
This commit is contained in:
parent
5c753465d1
commit
af4c8f61da
1 changed files with 17 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/liamstask/goose/lib/goose"
|
"bitbucket.org/liamstask/goose/lib/goose"
|
||||||
|
|
||||||
|
@ -17,6 +18,8 @@ import (
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
var conf *config.Config
|
var conf *config.Config
|
||||||
|
|
||||||
|
const MaxDatabaseConnectionAttempts int = 10
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CampaignInProgress string = "In progress"
|
CampaignInProgress string = "In progress"
|
||||||
CampaignQueued string = "Queued"
|
CampaignQueued string = "Queued"
|
||||||
|
@ -94,7 +97,20 @@ func Setup(c *config.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Open our database connection
|
// Open our database connection
|
||||||
db, err = gorm.Open(conf.DBName, conf.DBPath)
|
i := 0
|
||||||
|
for {
|
||||||
|
db, err = gorm.Open(conf.DBName, conf.DBPath)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil && i >= MaxDatabaseConnectionAttempts {
|
||||||
|
log.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
log.Warn("waiting for database to be up...")
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
db.LogMode(false)
|
db.LogMode(false)
|
||||||
db.SetLogger(log.Logger)
|
db.SetLogger(log.Logger)
|
||||||
db.DB().SetMaxOpenConns(1)
|
db.DB().SetMaxOpenConns(1)
|
||||||
|
|
Loading…
Reference in a new issue