Maintenance Rake tasks

Maintenance Rake tasks

GitLab 提供 Rake 任务进行常规维护.

该命令收集有关您的 GitLab 安装及其运行系统的信息. 这些在寻求帮助或报告问题时可能很有用.

全部安装

源安装

输出示例:

  1. System information
  2. System: Debian 7.8
  3. Current User: git
  4. Using RVM: no
  5. Ruby Version: 2.1.5p273
  6. Gem Version: 2.4.3
  7. Bundler Version: 1.7.6
  8. Rake Version: 10.3.2
  9. Redis Version: 3.2.5
  10. Sidekiq Version: 2.17.8
  11. GitLab information
  12. Version: 7.7.1
  13. Revision: 41ab9e1
  14. Directory: /home/git/gitlab
  15. DB Adapter: postgresql
  16. URL: https://gitlab.example.com
  17. HTTP Clone URL: https://gitlab.example.com/some-project.git
  18. SSH Clone URL: git@gitlab.example.com:some-project.git
  19. Using Omniauth: no
  20. GitLab Shell
  21. Version: 2.4.1
  22. Repositories: /home/git/repositories/
  23. Hooks: /home/git/gitlab-shell/hooks/
  24. Git: /usr/bin/git

Show GitLab license information

在 GitLab Starter 12.6 中引入 .

该命令显示有关您的以及使用了多少个席位的信息. 它仅在 GitLab Enterprise 安装中可用:许可证无法安装到 GitLab Community Edition 中.

当通过支持人员举票或以编程方式检查许可证参数时,这些选项可能很有用.

全部安装

  1. sudo gitlab-rake gitlab:license:info

源安装

  1. bundle exec rake gitlab:license:info RAILS_ENV=production

输出示例:

  1. Today's Date: 2020-02-29
  2. Current User Count: 30
  3. Max Historical Count: 30
  4. Max Users in License: 40
  5. License valid from: 2019-11-29 to 2020-11-28
  6. Email associated with license: user@example.com

Check GitLab configuration

gitlab:check Rake 任务运行以下 Rake 任务:

  • gitlab:gitlab_shell:check
  • gitlab:gitaly:check
  • gitlab:sidekiq:check
  • gitlab:app:check

它将检查是否已根据安装指南设置了每个组件,并针对发现的问题提出了修复建议. 此命令必须从您的应用程序服务器运行,并且在类的组件服务器上将无法正常运行.

您还可以查看我们的故障排除指南,以了解:

要运行 ,请运行:

  1. sudo gitlab-rake gitlab:check

源安装

注意:gitlab:check使用SANITIZE=true gitlab:check是否要从输出中省略项目名称.

输出示例:

  1. Checking Environment ...
  2. Git configured for git user? ... yes
  3. Has python2? ... yes
  4. python2 is supported version? ... yes
  5. Checking Environment ... Finished
  6. Checking GitLab Shell ...
  7. GitLab Shell version? ... OK (1.2.0)
  8. Repo base directory exists? ... yes
  9. Repo base directory is a symlink? ... no
  10. Repo base owned by git:git? ... yes
  11. Repo base access is drwxrws---? ... yes
  12. post-receive hook up-to-date? ... yes
  13. post-receive hooks in repos are links: ... yes
  14. Checking GitLab Shell ... Finished
  15. Checking Sidekiq ...
  16. Running? ... yes
  17. Checking Sidekiq ... Finished
  18. Checking GitLab ...
  19. Database config exists? ... yes
  20. Database is SQLite ... no
  21. All migrations up? ... yes
  22. GitLab config exists? ... yes
  23. GitLab config outdated? ... no
  24. Log directory writable? ... yes
  25. Tmp directory writable? ... yes
  26. Init script exists? ... yes
  27. Redis version >= 2.0.0? ... yes
  28. Checking GitLab ... Finished

在某些情况下,有必要重建authorized_keys文件. 为此,请运行:

全部安装

  1. sudo gitlab-rake gitlab:shell:setup

源安装

  1. cd /home/git/gitlab
  2. sudo -u git -H bundle exec rake gitlab:shell:setup RAILS_ENV=production

输出示例:

  1. This will rebuild an authorized_keys file.
  2. You will lose any data stored in authorized_keys file.
  3. Do you want to continue (yes/no)? yes

Clear Redis cache

如果出于某种原因,仪表板显示了错误的信息,则可能需要清除 Redis 的缓存. 为此,请运行:

全部安装

  1. sudo gitlab-rake cache:clear

源安装

  1. cd /home/git/gitlab
  2. sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production

Precompile the assets

有时,在版本升级期间,您可能会遇到一些错误的 CSS 或缺少某些图标的情况. 在这种情况下,请尝试再次重新编译资产.

这仅适用于源安装,不适用于 Omnibus 软件包.

源安装

对于多功能版本,未优化的资产(JavaScript,CSS)在上游 GitLab 发行时被冻结. 多功能版本包括这些资产的优化版本. 除非在安装软件包之后在生产机器上修改 JavaScript / CSS 代码,否则应该没有理由在生产机器上重做rake gitlab:assets:compile . 如果您怀疑资产已损坏,则应重新安装 omnibus 软件包.

有时您需要知道您的 GitLab 安装是否可以连接到另一台机器上的 TCP 服务-也许是 PostgreSQL 或 HTTPS 服务器. 包含一个 Rake 任务可以帮助您:

  1. sudo gitlab-rake gitlab:tcp_check[example.com,80]

源安装

  1. cd /home/git/gitlab
  2. sudo -u git -H bundle exec rake gitlab:tcp_check[example.com,80] RAILS_ENV=production

Clear exclusive lease (DANGER)

GitLab 使用共享锁机制: ExclusiveLease防止共享资源中的同时操作. 一个示例是在存储库上运行定期垃圾收集.

在非常特殊的情况下,如果不释放锁定,则由专有租赁锁定的操作可能会失败. 如果您不能等待它过期,可以运行此任务以手动清除它.

要清除所有专有租赁:

危险:请勿在 GitLab 或 Sidekiq 运行时运行它

  1. sudo gitlab-rake gitlab:exclusive_lease:clear

要指定租约type或租约type + id ,请指定范围:

  1. # to clear all leases for repository garbage collection:
  2. sudo gitlab-rake gitlab:exclusive_lease:clear[project_housekeeping:*]
  3. # to clear a lease for repository garbage collection in a specific project: (id=4)
  4. sudo gitlab-rake gitlab:exclusive_lease:clear[project_housekeeping:4]

Display status of database migrations

请参阅升级文档 ,以了解在升级 GitLab 时如何检查迁移是否完成.

要检查特定迁移的状态,可以使用以下 Rake 任务:

  1. sudo gitlab-rake db:migrate:status

这将为每个迁移 ID 输出一个Statusupdown的表.

  1. database: gitlabhq_production
  2. Status Migration ID Migration Name
  3. --------------------------------------------------
  4. up migration_id migration_name

数据库迁移可能会停留在不完整的状态. 也就是说,它们在sudo gitlab-rake db:migrate:status命令的输出中将处于down状态.

要完成这些迁移,请使用以下 Rake 任务:

命令完成后,运行sudo gitlab-rake db:migrate:status来检查是否所有迁移都已完成(具有up状态).

Import common metrics

有时,您可能需要重新导入为”指标”仪表板提供动力的通用指标.

这可能是由于更新现有指标或作为 .

要重新导入指标,可以运行:

  1. sudo gitlab-rake metrics:setup_common_metrics