Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic app.ini and path checks to doctor cmd #10064

Merged
merged 13 commits into from
Jan 30, 2020
Prev Previous commit
Next Next commit
Fix message and improve interface
  • Loading branch information
guillep2k committed Jan 29, 2020
commit 63fe37320d161387e3eb8d1e9232b7fba52ced82
26 changes: 16 additions & 10 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@ import (
// CmdDoctor represents the available doctor sub-command.
var CmdDoctor = cli.Command{
Name: "doctor",
Usage: "Diagnose and repair problems",
Description: "A command to diagnose and repair problems of current gitea instance according the given configuration.",
Usage: "Diagnose problems",
Description: "A command to diagnose problems of current gitea instance according the given configuration.",
guillep2k marked this conversation as resolved.
Show resolved Hide resolved
Action: runDoctor,
}

type check struct {
title string
f func(ctx *cli.Context) ([]string, error)
abort bool
title string
f func(ctx *cli.Context) ([]string, error)
abortIfFailed bool
skipDatabaseInit bool
}

// checklist represents list for all checks
var checklist = []check{
{
title: "Check paths and basic configuration",
f: runDoctorPathInfo,
abort: true,
// NOTE: this check should be the first in the list
title: "Check paths and basic configuration",
f: runDoctorPathInfo,
abortIfFailed: true,
skipDatabaseInit: true,
},
{
title: "Check if OpenSSH authorized_keys file id correct",
Expand All @@ -57,14 +60,17 @@ func runDoctor(ctx *cli.Context) error {
log.DelNamedLogger("console")
log.DelNamedLogger(log.DEFAULT)

dbIsInit := false

for i, check := range checklist {
if i == 1 {
if !dbIsInit && !check.skipDatabaseInit {
// Only open database after the most basic configuration check
if err := initDB(); err != nil {
fmt.Println(err)
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
return nil
}
dbIsInit = true
}
fmt.Println("[", i+1, "]", check.title)
messages, err := check.f(ctx)
Expand All @@ -73,7 +79,7 @@ func runDoctor(ctx *cli.Context) error {
}
if err != nil {
fmt.Println("Error:", err)
if check.abort {
if check.abortIfFailed {
return nil
}
} else {
Expand Down