Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
3f187751
Commit
3f187751
authored
May 30, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed and improved some existing checks and SystemCheck library
parent
bca56037
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
61 additions
and
77 deletions
+61
-77
lib/system_check.rb
lib/system_check.rb
+3
-12
lib/system_check/app/database_config_exists_check.rb
lib/system_check/app/database_config_exists_check.rb
+1
-7
lib/system_check/app/git_config_check.rb
lib/system_check/app/git_config_check.rb
+12
-20
lib/system_check/app/gitlab_config_up_to_date_check.rb
lib/system_check/app/gitlab_config_up_to_date_check.rb
+3
-5
lib/system_check/app/projects_have_namespace_check.rb
lib/system_check/app/projects_have_namespace_check.rb
+1
-1
lib/system_check/app/ruby_version_check.rb
lib/system_check/app/ruby_version_check.rb
+1
-1
lib/system_check/base_check.rb
lib/system_check/base_check.rb
+0
-3
lib/system_check/helpers.rb
lib/system_check/helpers.rb
+11
-2
lib/system_check/simple_executor.rb
lib/system_check/simple_executor.rb
+15
-15
lib/tasks/gitlab/check.rake
lib/tasks/gitlab/check.rake
+1
-1
lib/tasks/gitlab/task_helpers.rb
lib/tasks/gitlab/task_helpers.rb
+10
-9
spec/lib/system_check/base_executor_spec.rb
spec/lib/system_check/base_executor_spec.rb
+3
-1
No files found.
lib/system_check.rb
View file @
3f187751
...
@@ -9,22 +9,13 @@ module SystemCheck
...
@@ -9,22 +9,13 @@ module SystemCheck
#
#
# @param [String] component name of the component relative to the checks being executed
# @param [String] component name of the component relative to the checks being executed
# @param [Array<BaseCheck>] checks classes of corresponding checks to be executed in the same order
# @param [Array<BaseCheck>] checks classes of corresponding checks to be executed in the same order
# @param [BaseExecutor] executor_klass optionally specifiy a different executor class
def
self
.
run
(
component
,
checks
=
[])
def
self
.
run
(
component
,
checks
=
[],
executor_klass
=
SimpleExecutor
)
executor
=
SimpleExecutor
.
new
(
component
)
unless
executor_klass
<
BaseExecutor
raise
ArgumentError
,
'Invalid executor'
end
prepare
(
component
,
checks
,
executor_klass
).
execute
end
def
self
.
prepare
(
component
,
checks
=
[],
executor_klass
=
SimpleExecutor
)
executor
=
executor_klass
.
new
(
component
)
checks
.
each
do
|
check
|
checks
.
each
do
|
check
|
executor
<<
check
executor
<<
check
end
end
executor
executor
.
execute
end
end
private_class_method
:prepare
end
end
lib/system_check/app/database_config_exists_check.rb
View file @
3f187751
...
@@ -15,17 +15,11 @@ module SystemCheck
...
@@ -15,17 +15,11 @@ module SystemCheck
'Check that the information in config/database.yml is correct'
'Check that the information in config/database.yml is correct'
)
)
for_more_information
(
for_more_information
(
see_database_guide
,
'doc/install/databases.md'
,
'http://guides.rubyonrails.org/getting_started.html#configuring-a-database'
'http://guides.rubyonrails.org/getting_started.html#configuring-a-database'
)
)
fix_and_rerun
fix_and_rerun
end
end
private
def
see_database_guide
'doc/install/databases.md'
end
end
end
end
end
end
end
lib/system_check/app/git_config_check.rb
View file @
3f187751
...
@@ -5,7 +5,7 @@ module SystemCheck
...
@@ -5,7 +5,7 @@ module SystemCheck
'core.autocrlf'
=>
'input'
'core.autocrlf'
=>
'input'
}.
freeze
}.
freeze
set_name
'Git configured
with autocrlf=input
?'
set_name
'Git configured
correctly
?'
def
check?
def
check?
correct_options
=
OPTIONS
.
map
do
|
name
,
value
|
correct_options
=
OPTIONS
.
map
do
|
name
,
value
|
...
@@ -15,8 +15,18 @@ module SystemCheck
...
@@ -15,8 +15,18 @@ module SystemCheck
correct_options
.
all?
correct_options
.
all?
end
end
# Tries to configure git itself
#
# Returns true if all subcommands were successful (according to their exit code)
# Returns false if any or all subcommands failed.
def
repair!
def
repair!
auto_fix_git_config
(
OPTIONS
)
return
false
unless
is_gitlab_user?
command_success
=
OPTIONS
.
map
do
|
name
,
value
|
system
(
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
config --global
#{
name
}
#{
value
}
)
)
end
command_success
.
all?
end
end
def
show_error
def
show_error
...
@@ -27,24 +37,6 @@ module SystemCheck
...
@@ -27,24 +37,6 @@ module SystemCheck
see_installation_guide_section
'GitLab'
see_installation_guide_section
'GitLab'
)
)
end
end
private
# Tries to configure git itself
#
# Returns true if all subcommands were successfull (according to their exit code)
# Returns false if any or all subcommands failed.
def
auto_fix_git_config
(
options
)
if
!
@warned_user_not_gitlab
command_success
=
options
.
map
do
|
name
,
value
|
system
(
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
config --global
#{
name
}
#{
value
}
)
)
end
command_success
.
all?
else
false
end
end
end
end
end
end
end
end
lib/system_check/app/gitlab_config_
not_outdated
_check.rb
→
lib/system_check/app/gitlab_config_
up_to_date
_check.rb
View file @
3f187751
module
SystemCheck
module
SystemCheck
module
App
module
App
class
GitlabConfigNotOutdatedCheck
<
SystemCheck
::
BaseCheck
class
GitlabConfigUpToDateCheck
<
SystemCheck
::
BaseCheck
set_name
'GitLab config outdated?'
set_name
'GitLab config up to date?'
set_check_pass
'no'
set_check_fail
'yes'
set_skip_reason
"can't check because of previous errors"
set_skip_reason
"can't check because of previous errors"
def
skip?
def
skip?
...
@@ -18,7 +16,7 @@ module SystemCheck
...
@@ -18,7 +16,7 @@ module SystemCheck
def
show_error
def
show_error
try_fixing_it
(
try_fixing_it
(
'Backup your config/gitlab.yml'
,
'Back
-
up your config/gitlab.yml'
,
'Copy config/gitlab.yml.example to config/gitlab.yml'
,
'Copy config/gitlab.yml.example to config/gitlab.yml'
,
'Update config/gitlab.yml to match your setup'
'Update config/gitlab.yml to match your setup'
)
)
...
...
lib/system_check/app/projects_have_namespace_check.rb
View file @
3f187751
module
SystemCheck
module
SystemCheck
module
App
module
App
class
ProjectsHaveNamespaceCheck
<
SystemCheck
::
BaseCheck
class
ProjectsHaveNamespaceCheck
<
SystemCheck
::
BaseCheck
set_name
'
projects have namespace:
'
set_name
'
Projects have namespace:
'
set_skip_reason
"can't check, you have no projects"
set_skip_reason
"can't check, you have no projects"
def
skip?
def
skip?
...
...
lib/system_check/app/ruby_version_check.rb
View file @
3f187751
...
@@ -5,7 +5,7 @@ module SystemCheck
...
@@ -5,7 +5,7 @@ module SystemCheck
set_check_pass
->
{
"yes (
#{
self
.
current_version
}
)"
}
set_check_pass
->
{
"yes (
#{
self
.
current_version
}
)"
}
def
self
.
required_version
def
self
.
required_version
@required_version
||=
Gitlab
::
VersionInfo
.
new
(
2
,
1
,
0
)
@required_version
||=
Gitlab
::
VersionInfo
.
new
(
2
,
3
,
3
)
end
end
def
self
.
current_version
def
self
.
current_version
...
...
lib/system_check/base_check.rb
View file @
3f187751
require
'tasks/gitlab/task_helpers'
module
SystemCheck
module
SystemCheck
# Base class for Checks. You must inherit from here
# Base class for Checks. You must inherit from here
# and implement the methods below when necessary
# and implement the methods below when necessary
class
BaseCheck
class
BaseCheck
include
::
Gitlab
::
TaskHelpers
include
::
SystemCheck
::
Helpers
include
::
SystemCheck
::
Helpers
# Define a custom term for when check passed
# Define a custom term for when check passed
...
...
lib/system_check/helpers.rb
View file @
3f187751
require
'tasks/gitlab/task_helpers'
module
SystemCheck
module
SystemCheck
module
Helpers
module
Helpers
include
::
Gitlab
::
TaskHelpers
# Display a message telling to fix and rerun the checks
# Display a message telling to fix and rerun the checks
def
fix_and_rerun
def
fix_and_rerun
$stdout
.
puts
' Please fix the error above and rerun the checks.'
.
color
(
:red
)
$stdout
.
puts
' Please fix the error above and rerun the checks.'
.
color
(
:red
)
...
@@ -9,8 +13,6 @@ module SystemCheck
...
@@ -9,8 +13,6 @@ module SystemCheck
#
#
# @param [Array<String>] sources one or more references (documentation or links)
# @param [Array<String>] sources one or more references (documentation or links)
def
for_more_information
(
*
sources
)
def
for_more_information
(
*
sources
)
sources
=
sources
.
shift
if
sources
.
first
.
is_a?
(
Array
)
$stdout
.
puts
' For more information see:'
.
color
(
:blue
)
$stdout
.
puts
' For more information see:'
.
color
(
:blue
)
sources
.
each
do
|
source
|
sources
.
each
do
|
source
|
$stdout
.
puts
"
#{
source
}
"
$stdout
.
puts
"
#{
source
}
"
...
@@ -73,5 +75,12 @@ module SystemCheck
...
@@ -73,5 +75,12 @@ module SystemCheck
def
sudo_gitlab
(
command
)
def
sudo_gitlab
(
command
)
"sudo -u
#{
gitlab_user
}
-H
#{
command
}
"
"sudo -u
#{
gitlab_user
}
-H
#{
command
}
"
end
end
def
is_gitlab_user?
return
@is_gitlab_user
unless
@is_gitlab_user
.
nil?
current_user
=
run_command
(
%w(whoami)
).
chomp
@is_gitlab_user
=
current_user
==
gitlab_user
end
end
end
end
end
lib/system_check/simple_executor.rb
View file @
3f187751
...
@@ -18,32 +18,32 @@ module SystemCheck
...
@@ -18,32 +18,32 @@ module SystemCheck
# Executes a single check
# Executes a single check
#
#
# @param [SystemCheck::BaseCheck] check
# @param [SystemCheck::BaseCheck] check
_klass
def
run_check
(
check
)
def
run_check
(
check
_klass
)
$stdout
.
print
"
#{
check
.
display_name
}
... "
$stdout
.
print
"
#{
check
_klass
.
display_name
}
... "
c
=
check
.
new
c
heck
=
check_klass
.
new
# When implements skip method, we run it first, and if true, skip the check
# When implements skip method, we run it first, and if true, skip the check
if
c
.
can_skip?
&&
c
.
skip?
if
c
heck
.
can_skip?
&&
check
.
skip?
$stdout
.
puts
check
.
skip_reason
.
color
(
:magenta
)
$stdout
.
puts
check
_klass
.
skip_reason
.
color
(
:magenta
)
return
return
end
end
# When implements a multi check, we don't control the output
# When implements a multi check, we don't control the output
if
c
.
is_multi_check?
if
c
heck
.
is_multi_check?
c
.
multi_check
c
heck
.
multi_check
return
return
end
end
if
c
.
check?
if
c
heck
.
check?
$stdout
.
puts
check
.
check_pass
.
color
(
:green
)
$stdout
.
puts
check
_klass
.
check_pass
.
color
(
:green
)
else
else
$stdout
.
puts
check
.
check_fail
.
color
(
:red
)
$stdout
.
puts
check
_klass
.
check_fail
.
color
(
:red
)
if
c
.
can_repair?
if
c
heck
.
can_repair?
$stdout
.
print
'Trying to fix error automatically. ...'
$stdout
.
print
'Trying to fix error automatically. ...'
if
c
.
repair!
if
c
heck
.
repair!
$stdout
.
puts
'Success'
.
color
(
:green
)
$stdout
.
puts
'Success'
.
color
(
:green
)
return
return
else
else
...
@@ -51,7 +51,7 @@ module SystemCheck
...
@@ -51,7 +51,7 @@ module SystemCheck
end
end
end
end
c
.
show_error
c
heck
.
show_error
end
end
end
end
...
...
lib/tasks/gitlab/check.rake
View file @
3f187751
...
@@ -21,7 +21,7 @@ namespace :gitlab do
...
@@ -21,7 +21,7 @@ namespace :gitlab do
SystemCheck
::
App
::
MigrationsAreUpCheck
,
SystemCheck
::
App
::
MigrationsAreUpCheck
,
SystemCheck
::
App
::
OrphanedGroupMembersCheck
,
SystemCheck
::
App
::
OrphanedGroupMembersCheck
,
SystemCheck
::
App
::
GitlabConfigExistsCheck
,
SystemCheck
::
App
::
GitlabConfigExistsCheck
,
SystemCheck
::
App
::
GitlabConfig
NotOutdated
Check
,
SystemCheck
::
App
::
GitlabConfig
UpToDate
Check
,
SystemCheck
::
App
::
LogWritableCheck
,
SystemCheck
::
App
::
LogWritableCheck
,
SystemCheck
::
App
::
TmpWritableCheck
,
SystemCheck
::
App
::
TmpWritableCheck
,
SystemCheck
::
App
::
UploadsDirectoryExistsCheck
,
SystemCheck
::
App
::
UploadsDirectoryExistsCheck
,
...
...
lib/tasks/gitlab/task_helpers.rb
View file @
3f187751
...
@@ -99,16 +99,17 @@ module Gitlab
...
@@ -99,16 +99,17 @@ module Gitlab
end
end
def
warn_user_is_not_gitlab
def
warn_user_is_not_gitlab
unless
@warned_user_not_gitlab
return
if
@warned_user_not_gitlab
gitlab_user
=
Gitlab
.
config
.
gitlab
.
user
unless
is_gitlab_user?
current_user
=
run_command
(
%w(whoami)
).
chomp
current_user
=
run_command
(
%w(whoami)
).
chomp
unless
current_user
==
gitlab_user
puts
" Warning "
.
color
(
:black
).
background
(
:yellow
)
puts
" Warning "
.
color
(
:black
).
background
(
:yellow
)
puts
" You are running as user
#{
current_user
.
color
(
:magenta
)
}
, we hope you know what you are doing."
puts
" You are running as user
#{
current_user
.
color
(
:magenta
)
}
, we hope you know what you are doing."
puts
" Things may work
\/
fail for the wrong reasons."
puts
" Things may work
\/
fail for the wrong reasons."
puts
" For correct results you should run this as user
#{
gitlab_user
.
color
(
:magenta
)
}
."
puts
" For correct results you should run this as user
#{
gitlab_user
.
color
(
:magenta
)
}
."
puts
""
puts
""
end
@warned_user_not_gitlab
=
true
@warned_user_not_gitlab
=
true
end
end
end
end
...
...
spec/lib/system_check/base_executor_spec.rb
View file @
3f187751
...
@@ -26,7 +26,7 @@ describe SystemCheck::BaseExecutor, lib: true do
...
@@ -26,7 +26,7 @@ describe SystemCheck::BaseExecutor, lib: true do
subject
<<
SimpleCheck
subject
<<
SimpleCheck
end
end
it
'returns a
n array
of classes'
do
it
'returns a
set
of classes'
do
expect
(
subject
.
checks
).
to
include
(
SimpleCheck
)
expect
(
subject
.
checks
).
to
include
(
SimpleCheck
)
end
end
end
end
...
@@ -39,12 +39,14 @@ describe SystemCheck::BaseExecutor, lib: true do
...
@@ -39,12 +39,14 @@ describe SystemCheck::BaseExecutor, lib: true do
it
'appends a new check to the Set'
do
it
'appends a new check to the Set'
do
subject
<<
OtherCheck
subject
<<
OtherCheck
stored_checks
=
subject
.
checks
.
to_a
stored_checks
=
subject
.
checks
.
to_a
expect
(
stored_checks
.
first
).
to
eq
(
SimpleCheck
)
expect
(
stored_checks
.
first
).
to
eq
(
SimpleCheck
)
expect
(
stored_checks
.
last
).
to
eq
(
OtherCheck
)
expect
(
stored_checks
.
last
).
to
eq
(
OtherCheck
)
end
end
it
'inserts unique itens only'
do
it
'inserts unique itens only'
do
subject
<<
SimpleCheck
subject
<<
SimpleCheck
expect
(
subject
.
checks
.
size
).
to
eq
(
1
)
expect
(
subject
.
checks
.
size
).
to
eq
(
1
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment