Created
March 1, 2017 18:12
-
-
Save lazypower/627fda486371dfb7dcab510aba034fab to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -eux | |
# Backup existing configuration into configured temp path. | |
BACKUP=$(action-get backup) | |
BACKUP_PACKAGE=$(action-get backup-package) | |
BACKUP_TIMESTAMP=$(date +"%Y_%m_%d_%I_%M_%p") | |
if [ "${BACKUP}" == "True" ]; then | |
# auth credentials | |
if [ -d '/etc/ssl/etcd' ]; then | |
mkdir /tmp/$BACKUP_TIMESTAMP | |
cp -r /etc/ssl/etcd /tmp/$BACKUP_TIMESTAMP | |
fi | |
# Service Configuration | |
if [ -e '/etc/default/etcd' ]; then | |
cp /etc/default/etcd /tmp/$BACKUP_TIMESTAMP/etcd.defaults | |
fi | |
tar cfz $BACKUP_PACKAGE /tmp/$BACKUP_TIMESTAMP | |
fi | |
# Install the ingest snap ('assume this is coming from resources for offline') | |
USE_RESOURCE=$(action-get use-resource) | |
# Handle the snap ingestion routine | |
function ingest_snap { | |
# This determines if we have a resource provided etcd ingest snap. | |
if [ "${USE_RESOURCE}" == "False" ]; then | |
# If no manual snap specified, assume snapstore connectivity | |
snap install etcd --channel=ingest/stable --classic | |
else | |
# Install from the resource location, and check for correct snap. | |
MANUAL_SNAP=$(resource-get etcd) | |
snap install ${ETCD_MANUAL_SNAP} --classic --dangerous | |
if [ ! -f /snap/bin/etcd.ingest ]; then | |
action-fail "Missing etcd.ingest command. Did you attach the correct snap?" | |
exit 0 | |
fi | |
/snap/bin/etcd.ingest | |
charms.reactive set_state etcd.snap.ingest | |
action-set outcome="Ingest succeeded. Proceed with attaching the etcd release snap, and re-run snap-upgrade" | |
exit 0 | |
fi | |
/snap/bin/etcd.ingest | |
# I would prefer to leave this state for debugging purposes to know if we | |
# find issues later on with ingested units. Please do not remove. | |
charms.reactive set_state etcd.snap.ingest | |
} | |
# this may be falsy. Allow failure when checking ingestion state | |
set +e | |
INGESTED=$() | |
set -e | |
if [ ! $(charms.reactive is_state etcd.snap.ingest) ]; then | |
ingest_snap | |
fi | |
if [ "${USE_RESOURCE}" == "False" ]; then | |
CONFIGURED_CHANNEL=$(config-get channel) | |
snap refresh etcd --channel=${CONFIGURED_CHANNEL} --classic | |
else | |
MANUAL_SNAP=$(resource-get etcd) | |
snap install --dangerous ${MANUAL_SNAP} --classic | |
fi | |
sudo apt purge -y etcd | |
charms.reactive remove_state etcd.installed | |
# Self test | |
set +e | |
/snap/bin/etcd.etcdctl member list | |
if [ $? == 0 ]; then | |
status-set "active" "Migration complete." | |
else | |
status-set "waiting" "Failed self check... waiting on cluster." | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment