fix: Improve setup check logic and logging for system initialization
This commit is contained in:
@@ -57,22 +57,29 @@ func createRootAccountIfNeed() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkSetup() {
|
func checkSetup() {
|
||||||
if GetSetup() == nil {
|
setup := GetSetup()
|
||||||
|
if setup == nil {
|
||||||
|
// No setup record exists, check if we have a root user
|
||||||
if RootUserExists() {
|
if RootUserExists() {
|
||||||
common.SysLog("system is not initialized, but root user exists")
|
common.SysLog("system is not initialized, but root user exists")
|
||||||
// Create setup record
|
// Create setup record
|
||||||
setup := Setup{
|
newSetup := Setup{
|
||||||
Version: common.Version,
|
Version: common.Version,
|
||||||
InitializedAt: time.Now().Unix(),
|
InitializedAt: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
err := DB.Create(&setup).Error
|
err := DB.Create(&newSetup).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysLog("failed to create setup record: " + err.Error())
|
common.SysLog("failed to create setup record: " + err.Error())
|
||||||
}
|
}
|
||||||
constant.Setup = true
|
constant.Setup = true
|
||||||
} else {
|
} else {
|
||||||
|
common.SysLog("system is not initialized and no root user exists")
|
||||||
constant.Setup = false
|
constant.Setup = false
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Setup record exists, system is initialized
|
||||||
|
common.SysLog("system is already initialized at: " + time.Unix(setup.InitializedAt, 0).String())
|
||||||
|
constant.Setup = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user