feat(gerrit-update): Add helper script for updating Gerrit schema

I've been running a script similar to this after doing Gerrit version
bumps to make sure the schema is up to date, but in the spirit of making
sure someone other that myself can do this task I'm formalising it into
the depot, where I should've put it in the first place.

Change-Id: I50a198e798e2ff26989b01e4bdd0571d85ab62aa
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2203
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
Luke Granger-Brown 2020-11-29 03:34:26 +00:00 committed by lukegb
parent b344ae8783
commit 1409b9c37b
3 changed files with 38 additions and 0 deletions

View file

@ -28,6 +28,9 @@ case "${TARGET_TOOL}" in
gerrit)
attr="tools.gerrit-cli"
;;
gerrit-update)
attr="tools.gerrit-update"
;;
hash-password)
attr="tools.hash-password"
;;

1
bin/gerrit-update Symbolic link
View file

@ -0,0 +1 @@
__dispatch.sh

34
tools/gerrit-update.nix Normal file
View file

@ -0,0 +1,34 @@
# Utility script to perform a Gerrit update.
{ pkgs, ... }:
pkgs.writeShellScriptBin "gerrit-update" ''
set -euo pipefail
if [[ $EUID -ne 0 ]]; then
echo "Oh no! Only root is allowed to update Gerrit!" >&2
exit 1
fi
gerrit_war="$(find "${pkgs.gerrit}/webapps" -name 'gerrit*.war')"
java="${pkgs.jdk}/bin/java"
backup_path="/root/gerrit_preupgrade-$(date +"%Y-%m-%d").tar.bz2"
# Take a safety backup of Gerrit into /root's homedir. Just in case.
echo "Backing up Gerrit to $backup_path"
tar -cjf "$backup_path" /var/lib/gerrit
# Stop Gerrit (and its activation socket).
echo "Stopping Gerrit"
systemctl stop gerrit.service gerrit.socket
# Ask Gerrit to do a schema upgrade...
echo "Performing schema upgrade"
"$java" -jar "$gerrit_war" \
init --no-auto-start --batch --skip-plugins --site-path "/var/lib/gerrit"
# Restart Gerrit.
echo "Restarting Gerrit"
systemctl start gerrit.socket gerrit.service
echo "...done"
''