diff options
-rwxr-xr-x | bin/__dispatch.sh | 3 | ||||
l--------- | bin/gerrit-update | 1 | ||||
-rw-r--r-- | tools/gerrit-update.nix | 34 |
3 files changed, 38 insertions, 0 deletions
diff --git a/bin/__dispatch.sh b/bin/__dispatch.sh index b265e2fd197a..2f1c882b99c2 100755 --- a/bin/__dispatch.sh +++ b/bin/__dispatch.sh @@ -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" ;; diff --git a/bin/gerrit-update b/bin/gerrit-update new file mode 120000 index 000000000000..8390ec9c9652 --- /dev/null +++ b/bin/gerrit-update @@ -0,0 +1 @@ +__dispatch.sh \ No newline at end of file diff --git a/tools/gerrit-update.nix b/tools/gerrit-update.nix new file mode 100644 index 000000000000..e4efd89ea597 --- /dev/null +++ b/tools/gerrit-update.nix @@ -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" +'' |