Skip to content

Instantly share code, notes, and snippets.

@royki
Created August 12, 2019 12:31
Show Gist options
  • Save royki/c1ea85e2ccdce0dfd186bbaf5b8e8d67 to your computer and use it in GitHub Desktop.
Save royki/c1ea85e2ccdce0dfd186bbaf5b8e8d67 to your computer and use it in GitHub Desktop.
Useful gitlab command and links
  • gitlab omnibus

  • gitlab backup

  • gitlab create backup

  • gitlab restor

  • gitlab-raketask

  • gitlab-rake ldap

  • gitlab-rake maintenance

  • gitlab-rake check

  • omnibus - maintenance

  • Results of GitLab environment info

    • For Omnibus
      • gitlab-rake gitlab:env:info
    • For Source
      • bundle exec rake gitlab:env:info RAILS_ENV=production
  • Results of GitLab application Check

    • gitlab-rake gitlab:check SANITIZE=true
  • Check GitLab Configuration

    • Omnibus
      • gitlab-rake gitlab:check
      • gitlab-rake gitlab:check
      • gitlab-rake sidekiq:check
      • gitlab-rake app:check
    • Source Installation
      • bundle exec rake gitlab:check RAILS_ENV=production
  • Rebuild authorized_keys file

    • Omnibus
      • gitlab-rake gitlab:shell:setup
    • Source
      • cd /home/git/gitlab
      • sudo -u git -H bundle exec rake gitlab:shell:setup RAILS_ENV=production
  • Clear redis cache

    • Omnibus
      • gitlab-rake cache:clear
    • Source Installation
      • cd /home/git/gitlab
      • sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production
  • Precompile the assets (Sometimes during version upgrades you might end up with some wrong CSS or missing some icons.)

    • Source Installation
      • cd /home/git/gitlab
      • sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production
  • Tracking Deployments

    • Omnibus
      • gitlab-rake gitlab:track_deployment
    • Source Installation
      • cd /home/git/gitlab
      • sudo -u git -H bundle exec rake gitlab:track_deployment RAILS_ENV=production
  • Create or repair repository hooks symlink

    • Omnibus
      • gitlab-rake gitlab:shell:create_hooks
    • Source Installation
      • cd /home/git/gitlab
      • sudo -u git -H bundle exec rake gitlab:shell:create_hooks RAILS_ENV=production
  • Check TCP connectivity to a remote site

    • Omnibus
      • gitlab-rake gitlab:tcp_check[example.com,80]
    • Source Installation
      • cd /home/git/gitlab
      • sudo -u git -H bundle exec rake gitlab:tcp_check[example.com,80] RAILS_ENV=production
  • Clear exclusive lease (DANGER)

    • GitLab uses a shared lock mechanism: ExclusiveLease to prevent simultaneous operations in a shared resource. An example is running periodic garbage collection on repositories.
    • In very specific situations, a operation locked by an Exclusive Lease can fail without releasing the lock. If you can’t wait for it to expire, you can run this task to manually clear it.
      • To clear all exclusive leases: DANGER: Don’t run it while GitLab or Sidekiq is running
        • gitlab-rake gitlab:exclusive_lease:clear
        • gitlab-rake gitlab:exclusive_lease:clear[project_housekeeping:*] (to clear all leases for repository garbage collection:)
        • gitlab-rake gitlab:exclusive_lease:clear[project_housekeeping:4] (to clear a lease for repository garbage collection in a specific project: (id=4))
  • Check all GitLab repositories

    • Omnibus
      • gitlab-rake gitlab:git:fsck
    • Source Installation
      • sudo -u git -H bundle exec rake gitlab:git:fsck RAILS_ENV=production
  • Uploaded Files Integrity

    • Various types of files can be uploaded to a GitLab installation by users. These integrity checks can detect missing files. Additionally, for locally stored files, checksums are generated and stored in the database upon upload, and these checks will verify them against current files.
    • Currently, integrity checks are supported for the following types of file:
      • CI artifacts (Available from version 10.7.0)
      • LFS objects (Available from version 10.6.0)
      • User uploads (Available from version 10.6.0)
    • Omnibus
      • sudo gitlab-rake gitlab:artifacts:check
      • sudo gitlab-rake gitlab:lfs:check
      • sudo gitlab-rake gitlab:uploads:check
    • Source Installation
      • sudo -u git -H bundle exec rake gitlab:artifacts:check RAILS_ENV=production
      • sudo -u git -H bundle exec rake gitlab:lfs:check RAILS_ENV=production
      • sudo -u git -H bundle exec rake gitlab:uploads:check RAILS_ENV=production
    • These tasks also accept some environment variables which you can use to override certain values:
      • sudo gitlab-rake gitlab:artifacts:check BATCH=100 ID_FROM=50 ID_TO=250
      • sudo gitlab-rake gitlab:lfs:check BATCH=100 ID_FROM=50 ID_TO=250
      • sudo gitlab-rake gitlab:uploads:check BATCH=100 ID_FROM=50 ID_TO=250
    • Verbose
      • sudo gitlab-rake gitlab:uploads:check VERBOSE=1
  • After Installation

    • Get Server status
      • sudo gitlab-ctl status
      • sudo gitlab-ctl start
      • sudo gitlab-ctl stop
      • sudo gitlab-ctl restart
      • sudo gitlab-ctl restart sidekiq
      • sudo gitlab-ctl hub unicorn (Unicorn supports zero-downtime reloads.)
  • Starting a Rails console session

    • sudo gitlab-rails console
  • Starting a Postgres superuser psql session

    • sudo gitlab-psql -d gitlabhq_production
  • Container registry garbage collection

    • Container registry can use considerable amounts of disk space. To clear up some unused layers, registry includes a garbage collect command.
    • There are a couple of considerations you need to note before running the built in command:
      • The built in command will stop the registry before it starts garbage collect
      • The garbage collect command takes some time to complete, depending on the amount of data that exists
      • If you changed the location of registry configuration file, you will need to specify the path
      • After the garbage collect is done, registry should start up automatically
        • sudo gitlab-ctl registry-garbage-collect
        • sudo gitlab-ctl registry-garbage-collect /path/to/config.yml
    • Doing garbage collect without downtime
      • Do a garbage collect without stopping the Container registry by setting it into a read only mode. During this time, you will be able to pull from the Container registry but you will not be able to push.
      • In /etc/gitlab/gitlab.rb specify the read only mode
       registry['storage'] = {
        'maintenance' => {
          'readonly' => {
       	 'enabled' => true
       		}
       	}
       }	
      • Save and run sudo gitlab-ctl reconfigure. This will set the Container registry into the read only mode.
      • Next, trigger the garbage collect command:
        • sudo /opt/gitlab/embedded/bin/registry garbage-collect /var/opt/gitlab/registry/config.yml
        • This will start the garbage collection. The command will take some time to complete.
      • Once done, in /etc/gitlab/gitlab.rb change the configuration to:
       registry['storage'] = {
        'maintenance' => {
          'readonly' => {
       	 'enabled' => false
       		}
       	}
       }	
      
      • Then run sudo gitlab-ctl reconfigure
  • Administratively recycling unused tags

    • sudo gitlab-ctl registry-garbage-collect
  • GitLab API

    • curl "https://gitlab.example.com/api/v4/projects"
    • OAuth2 tokens
      • curl https://gitlab.example.com/api/v4/projects?access_token=OAUTH-TOKEN
    • curl --header "Authorization: Bearer OAUTH-TOKEN" https://gitlab.example.com/api/v4/projects
    • Personal access tokens
      • curl https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>
      • curl --header "Private-Token: <your_access_token>" https://gitlab.example.com/api/v4/projects
    • Example of a valid API call and a request using cURL with sudo request, providing a username:
      • GET /projects?private_token=<your_access_token>&sudo=username
      • curl --header "Private-Token: <your_access_token>" --header "Sudo: username" "https://gitlab.example.com/api/v4/projects"
    • Example of a valid API call and a request using cURL with sudo request, providing an ID:
      • GET /projects?private_token=<your_access_token>&sudo=23
      • curl --header "Private-Token: <your_access_token>" --header "Sudo: 23" "https://gitlab.example.com/api/v4/projects"
  • GitLab Commit API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment