Created
June 6, 2019 14:20
-
-
Save bordeo/635429acce5fb6594add4b66cf561fb5 to your computer and use it in GitHub Desktop.
Automatic rancher upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
read -p 'New Version: ' new_version | |
old_container_name="$(docker ps --filter "name=rancher-server*" --format "{{.Names}}")" | |
old_version="$(expr $old_container_name : 'rancher-server-\(.*\)-no-cacerts')" | |
timestamp="$(/bin/date "+%Y-%m-%d--%H-%M-%S")" | |
echo "Upgrading rancher server..." | |
echo "$old_version -> $new_version" | |
docker pull rancher/rancher:v$new_version | |
docker stop $old_container_name | |
docker create --volumes-from $old_container_name --name rancher-data-$old_version rancher/rancher:v$old_version | |
docker run --volumes-from rancher-data-$old_version -v $PWD:/backup alpine tar zcvf /backup/rancher-data-backup-$old_version-$timestamp.tar.gz /var/lib/rancher | |
docker run \ | |
-d \ | |
--volumes-from rancher-data-$old_version \ | |
--privileged \ | |
--ulimit nofile=90000:90000 \ | |
--restart=unless-stopped \ | |
--name=rancher-server-$new_version-no-cacerts \ | |
-p 80:80 \ | |
-p 443:443 \ | |
-e VIRTUAL_HOST=rancher.hevelop.com \ | |
rancher/rancher:v$new_version \ | |
--no-cacerts | |
echo "Rancher server upgraded!!!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment