diff --git a/knowledge base/gitlab/README.md b/knowledge base/gitlab/README.md index 32c6357..c58c7a5 100644 --- a/knowledge base/gitlab/README.md +++ b/knowledge base/gitlab/README.md @@ -186,6 +186,14 @@ sudo yum check-update sudo gitlab-backup create tmux new-session -As 'gitlab-upgrade' "sudo yum update 'gitlab-ee'" +# DB version upgrade +sudo gitlab-ctl pg-upgrade +sudo gitlab-ctl pg-upgrade -V '16' +# Check there is enough disk space for two copies of the database +test $(( $(sudo du -s '/var/opt/gitlab/postgresql/data' | awk '{print $1}') * 2 )) -lt \ + $(sudo df --output='avail' --direct '/var/opt/gitlab/postgresql/data' | tail -n 1) \ +&& sudo gitlab-ctl pg-upgrade -V '16' + # Reset the root user's password. sudo gitlab-rake 'gitlab:password:reset[root]' sudo gitlab-rails console @@ -752,6 +760,7 @@ Solution: set the correct ownership with - [GitLab HA Scaling Runner Vending Machine for AWS EC2 ASG] - [GitLab maintenance mode] - [Forks] +- [Upgrade packaged PostgreSQL server] diff --git a/snippets/ansible/tasks.yml b/snippets/ansible/tasks.yml index 6055b0a..0d3582a 100644 --- a/snippets/ansible/tasks.yml +++ b/snippets/ansible/tasks.yml @@ -668,3 +668,13 @@ acme_version: 2 account_key_src: path/to/acme_account.key.pem certificate: path/to/certificate.crt.pem + +- name: GitLab + block: + - name: Install configured fleeting plugins + when: runner_executor in [ "docker-autoscaler", "instance" ] + become: true + ansible.builtin.command: + chdir: /root + cmd: gitlab-runner fleeting install + creates: /root/.config/fleeting/plugins diff --git a/snippets/curl.sh b/snippets/curl.sh index 48ba320..d772681 100644 --- a/snippets/curl.sh +++ b/snippets/curl.sh @@ -3,6 +3,7 @@ # Sources: # - https://everything.curl.dev/usingcurl/connections/name.html + # Use different names. # Kinda like '--resolve' but to aliases and supports ports. curl --connect-to 'super.fake.domain:443:localhost:8443' 'https://super.fake.domain' @@ -10,3 +11,14 @@ curl --connect-to 'super.fake.domain:443:localhost:8443' 'https://super.fake.dom # Forcefully resolve hosts to given addresses. # The resolution *must* be an address, not an FQDN. curl --resolve 'super.fake.domain:8443:127.0.0.1' 'https://super.fake.domain:8443' + + +curl -fs 'https://gitlab.com/api/v4/runners/all?per_page=100&paused=false' -H 'PRIVATE-TOKEN: glpat-m-…' +curl --url 'https://gitlab.com/api/v4/runners/all' \ + --fail --silent \ + --header 'PRIVATE-TOKEN: glpat-m-…' \ + --url-query 'per_page=100' --url-query 'paused=false' + +curl -fsX 'PUT' 'https://gitlab.com/api/v4/runners/{}' -H 'PRIVATE-TOKEN: glpat-m-…' -F 'paused=true' +curl --fail --silent --request 'PUT' 'https://gitlab.com/api/v4/runners/{}' \ + --header 'PRIVATE-TOKEN: glpat-m-…' --form 'paused=true' diff --git a/snippets/gitlab/gitlab-runner.sh b/snippets/gitlab/gitlab-runner.sh index 3311380..1212852 100644 --- a/snippets/gitlab/gitlab-runner.sh +++ b/snippets/gitlab/gitlab-runner.sh @@ -25,6 +25,7 @@ gitlab-runner register --url 'https://gitlab.example.com' --registration-token ' # Just list configured runners gitlab-runner list -c '/etc/gitlab-runner/config.toml' +curl -fs 'https://gitlab.com/api/v4/runners/all?per_page=100' -H 'PRIVATE-TOKEN: glpat-m-…' # Check configured runners can connect to the main instance gitlab-runner verify -c '/etc/gitlab-runner/config.toml' @@ -36,6 +37,20 @@ curl -fs 'https://gitlab.com/api/v4/runners/all?status=offline&per_page=100' -H | jq '.[].id' \ | xargs -I 'runner_id' curl -fsX 'DELETE' "https://gitlab.com/api/v4/runners/runner_id" 'PRIVATE-TOKEN: glpat-m-…' +# Force reloading the configuration file +sudo kill -HUP $(pidof 'gitlab-runner') +sudo kill -s 'SIGHUP' $(pgrep 'gitlab-runner') + +# Stop accepting new builds and exit as soon as currently running builds finish +# A.K.A. graceful shutdown +sudo kill -QUIT $(pgrep 'gitlab-runner') +sudo kill -s 'SIGQUIT' $(pidof 'gitlab-runner') + +# Pause active runners +curl -fs 'https://gitlab.com/api/v4/runners/all?per_page=100&paused=false' -H 'PRIVATE-TOKEN: glpat-m-…' \ +| jq '.[].id' - \ +| xargs -I '{}' curl -fsX 'PUT' 'https://gitlab.com/api/v4/runners/{}' -H 'PRIVATE-TOKEN: glpat-m-…' -F 'paused=true' + ### # docker+machine executor diff --git a/snippets/gitlab/package installation.sh b/snippets/gitlab/package installation.sh index 49e1535..b5f6f8c 100644 --- a/snippets/gitlab/package installation.sh +++ b/snippets/gitlab/package installation.sh @@ -121,6 +121,14 @@ sudo gitlab-ctl backup-etc tmux new-session -A -s 'gitlab-upgrade' "sudo yum update 'gitlab-ee'" # 'gitlab-ee-16.11.3' if version-specific sudo gitlab-rake 'gitlab:check' +# DB version upgrade +sudo gitlab-ctl pg-upgrade +sudo gitlab-ctl pg-upgrade -V '16' +# Check there is enough disk space for two copies of the database +test $(( $(sudo du -s '/var/opt/gitlab/postgresql/data' | awk '{print $1}') * 2 )) -lt \ + $(sudo df --output='avail' --direct '/var/opt/gitlab/postgresql/data' | tail -n 1) \ +&& sudo gitlab-ctl pg-upgrade -V '16' + # Password reset sudo gitlab-rake 'gitlab:password:reset[root]' sudo gitlab-rails console diff --git a/snippets/process management.sh b/snippets/process management.sh new file mode 100644 index 0000000..ee2ac34 --- /dev/null +++ b/snippets/process management.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +# https://askubuntu.com/questions/180336/how-to-find-the-process-id-pid-of-a-running-terminal-program +# https://bash.cyberciti.biz/guide/Sending_signal_to_Processes + +# Find process IDs +pidof 'gitlab-runner' +pgrep 'gitlab-runner' +# Limit search to specific owners +pgrep -u 'root,daemon' 'sshd' + + +# List available signals +kill -l + +# Send signals to processes +kill -9 '1234' +kill -KILL '1234' +kill -SIGKILL '1234' +kill -s 'SIGHUP' '3969' +pkill -KILL 'firefox' +pkill --signal 'HUP' 'prometheus' +killall -s 'SIGKILL' 'firefox-bin'