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

Conversation

guillep2k
Copy link
Member

@guillep2k guillep2k commented Jan 29, 2020

This PR adds some basic app.ini and path checking to the doctor command.

In particular, it won't proceed if app.ini doesn't look healthy enough, and will provide information about the application paths the user may find useful.

Normal run

$ gitea doctor
[ 1 ] Check paths and basic configuration
- Configuration File Path:   '/home/gittest/etc/app.ini'
- Repository Root Path:      '/home/gittest/gitea-repositories'
- Data Root Path:            '/home/gittest/data'
- Custom File Root Path:     '/home/gittest/custom'
- Work directory:            '/home/gittest'
- Log Root Path:             '/home/gittest/log'
OK.

[ 2 ] Check if OpenSSH authorized_keys file id correct
OK.

Run with an empty app.ini

$ gitea --config `pwd`/empty.app.ini doctor
[ 1 ] Check paths and basic configuration
- Configuration File Path:   '/home/gittest/tmp/empty.app.ini'
- Repository Root Path:      '/home/gittest/gitea-repositories'
- Data Root Path:            '/home/gittest/tmp/data'
-     ERROR: not writable: open /home/gittest/tmp/data/doctors-order772291956: permission denied
- Custom File Root Path:     '/home/gittest/tmp/custom'
-     NOTICE: not accessible (stat /home/gittest/tmp/custom: no such file or directory)
- Work directory:            '/home/gittest/tmp'
- Log Root Path:             '/home/gittest/tmp/log'
-     ERROR: stat /home/gittest/tmp/log: no such file or directory
Error: Please check your configuration file and try again.

Run with no app.ini at all

$ gitea doctor
[ 1 ] Check paths and basic configuration
- Failed to find configuration file at '/home/gittest/tmp/custom/conf/app.ini'.
- If you've never ran Gitea yet, this is normal and '/home/gittest/tmp/custom/conf/app.ini' will be created for you.
- Otherwise check that you are running this command from the correct path and/or provide the `--config` option.
Error: Can't proceed without a configuration file

Note: I've "silenced" the default logger since its output (being asynchronous) was mixing in between the doctor's output and I find it confusing:

$ gitea doctor
[ 1 ] Check paths and basic configuration
- Configuration File Path:   '/home/gittest/etc/app.ini'
- Repository Root Path:      '/home/gittest/gitea-repositories'
2020/01/29 15:52:04 ...dules/setting/git.go:91:newGit() [I] Git Version: 2.22.0, Wire Protocol Version 2 Enabled
- Data Root Path:            '/home/gittest/data'
- Custom File Root Path:     '/home/gittest/custom'
- Work directory:            '/home/gittest'
- Log Root Path:             '/home/gittest/log'
2020/01/29 15:52:04 ...dules/setting/git.go:91:newGit() [I] Git Version: 2.22.0, Wire Protocol Version 2 Enabled
2020/01/29 15:52:04 ...dules/setting/log.go:185:generateNamedLogger() [I] Xorm Log: File(file:trace)
2020/01/29 15:52:04 ...dules/setting/log.go:185:generateNamedLogger() [I] Xorm Log: Console(console:error)
OK.

[ 2 ] Check if OpenSSH authorized_keys file id correct
OK.

I think it will be best to create a separate log for all of doctor's activities, but I leave that for another PR.

@6543
Copy link
Member

6543 commented Jan 29, 2020

O I had a issue once a time:
instead of ; i had a : as comment indicator -> witch result in a gitea crash without any information left where I could find the issue ...

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 29, 2020
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 29, 2020
@6543
Copy link
Member

6543 commented Jan 29, 2020

@guillep2k is there a chance to add : config checker?

cmd/doctor.go Outdated Show resolved Hide resolved
@guillep2k
Copy link
Member Author

@guillep2k is there a chance to add : config checker?

Maybe next time. I'd need to investigate all the possible valid syntaxes for app.ini lines and make a regex for that. It might not be a trivial task.

cmd/doctor.go Outdated Show resolved Hide resolved
cmd/doctor.go Outdated Show resolved Hide resolved
cmd/doctor.go Outdated Show resolved Hide resolved
Copy link
Member

@jolheiser jolheiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, otherwise LGTM

cmd/doctor.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 29, 2020
Co-Authored-By: John Olheiser <[email protected]>
@zeripath zeripath added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jan 29, 2020
@zeripath zeripath added this to the 1.12.0 milestone Jan 29, 2020
modules/options/static.go Show resolved Hide resolved
modules/options/dynamic.go Show resolved Hide resolved
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@3509a7b). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #10064   +/-   ##
=========================================
  Coverage          ?    42.3%           
=========================================
  Files             ?      618           
  Lines             ?    80850           
  Branches          ?        0           
=========================================
  Hits              ?    34200           
  Misses            ?    42440           
  Partials          ?     4210
Impacted Files Coverage Δ
cmd/doctor.go 0% <ø> (ø)
modules/options/dynamic.go 68.62% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3509a7b...9b0d6fe. Read the comment docs.

@lunny lunny merged commit 04cbdf5 into go-gitea:master Jan 30, 2020
@guillep2k
Copy link
Member Author

Related: #8781 (comment)

@guillep2k guillep2k deleted the doctor-info branch January 30, 2020 02:02
techknowlogick pushed a commit that referenced this pull request Apr 6, 2020
…#10991)

* Mulitple Gitea Doctor improvements (#10943)

Backport #10943

* Add `gitea doctor --list` flag to list the checks that will be run, including those by default
* Add `gitea doctor --run` to run specific checks
* Add `gitea doctor --all` to run all checks
* Add db version checker
* Add non-default recalculate merge bases check/fixer to doctor
* Add hook checker (Fix #9878) and ensure hooks are executable (Fix #6319)
* Fix authorized_keys checker - slight change of functionality here because parsing the command is fragile and we should just check if the authorized_keys file is essentially the same as what gitea would produce. (This is still not perfect as order matters - we should probably just md5sum the two files.)
* Add SCRIPT_TYPE check (Fix #10977)
* Add `gitea doctor --fix` to attempt to fix what is possible to easily fix
* Add `gitea doctor --log-file` to set the log-file, be it a file, stdout or to switch off completely. (Fixes previously undetected bug with certain xorm logging configurations - see @6543 comment.)

Signed-off-by: Andrew Thornton <[email protected]>

* Switch to io.Writer instead of io.StringWriter

Signed-off-by: Andrew Thornton <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants