Last active
April 20, 2018 21:09
-
-
Save freyes/5327cc554bd18d4f9f6059a9a1af153b to your computer and use it in GitHub Desktop.
automated series upgrade based on https://jujucharms.com/docs/2.3/howto-updateseries
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 -ex | |
# | |
# Usage: | |
# ./upgrade-series.sh ceph-osd/1 | |
# | |
# Based on https://jujucharms.com/docs/2.3/howto-updateseries | |
# | |
APPNAME=$(echo $1 | cut -d'/' -f1) | |
UNIT=$(echo $1 | cut -d'/' -f2) | |
tmpfile=$(mktemp) | |
exec_start_tpl=$(mktemp) | |
cat <<EOF > $exec_start_tpl | |
#!/usr/bin/env bash | |
# Set up logging. | |
touch '/var/log/juju/__AGENT__.log' | |
chown syslog:syslog '/var/log/juju/__AGENT__.log' | |
chmod 0600 '/var/log/juju/__AGENT__.log' | |
exec >> '/var/log/juju/__AGENT__.log' | |
exec 2>&1 | |
# Run the script. | |
'/var/lib/juju/tools/__AGENT__/jujud' machine --data-dir '/var/lib/juju' --machine-id __MACHINE_ID__ --debug | |
EOF | |
service_tpl=$(mktemp) | |
cat <<EOF > $service_tpl | |
[Unit] | |
Description=juju agent for __AGENT__ | |
After=syslog.target | |
After=network.target | |
After=systemd-user-sessions.service | |
[Service] | |
Environment= | |
LimitNOFILE=20000 | |
ExecStart=/var/lib/juju/init/jujud-__AGENT__/exec-start.sh | |
Restart=on-failure | |
TimeoutSec=300 | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
juju update-series $APPNAME xenial | |
echo 'DPkg::options { "--force-confold"; }' > $tmpfile | |
juju scp $tmpfile $APPNAME/$UNIT:/tmp/local | |
juju ssh $APPNAME/$UNIT "sudo cp /tmp/local /etc/apt/apt.conf.d/local && rm /tmp/local" | |
juju ssh $APPNAME/$UNIT "sudo apt-get update -qq && sudo apt-get install -yq screen" | |
juju ssh $APPNAME/$UNIT "screen sudo do-release-upgrade -f DistUpgradeViewNonInteractive" | |
AGENT_CONF=$(juju ssh $APPNAME/$UNIT 'cd /etc/init/ ; ls jujud-machine-*.conf' | tr -d '\r') | |
AGENT_NAME=$(echo $AGENT_CONF | cut -d'.' -f1) | |
juju scp $exec_start_tpl $1:/tmp/exec_start_tpl | |
juju scp $service_tpl $1:/tmp/service_tpl | |
AGENT=$(echo $AGENT_NAME | cut -c 7-) | |
MACHINE_ID=$(echo $AGENT_NAME | rev | cut -d'-' -f1 | rev) | |
juju ssh $APPNAME/$UNIT "sudo mkdir -p /var/lib/juju/init/jujud-$AGENT" | |
juju ssh $APPNAME/$UNIT "sed s/__AGENT__/$AGENT/g /tmp/exec_start_tpl | sudo tee /var/lib/juju/init/jujud-$AGENT/exec-start.sh > /dev/null" | |
juju ssh $APPNAME/$UNIT "sudo sed -i s/__MACHINE_ID__/$MACHINE_ID/g /var/lib/juju/init/jujud-$AGENT/exec-start.sh" | |
juju ssh $APPNAME/$UNIT "sudo chmod 755 /var/lib/juju/init/jujud-$AGENT/exec-start.sh" | |
juju ssh $APPNAME/$UNIT "sed s/__AGENT__/$AGENT/g /tmp/service_tpl | sudo tee /var/lib/juju/init/jujud-$AGENT/jujud-$AGENT.service > /dev/null" | |
juju ssh $APPNAME/$UNIT "sudo sed -i s/__MACHINE_ID__/$MACHINE_ID/g /var/lib/juju/init/jujud-$AGENT/jujud-$AGENT.service" | |
juju ssh $APPNAME/$UNIT "sudo ln -s /var/lib/juju/init/jujud-$AGENT/jujud-$AGENT.service /etc/systemd/system/" | |
juju ssh $APPNAME/$UNIT "sudo ln -s /var/lib/juju/init/jujud-$AGENT/jujud-$AGENT.service /etc/systemd/system/multi-user.target.wants/jujud-$AGENT.service" | |
juju ssh $APPNAME/$UNIT "cd /var/lib/juju/tools ; ln -s ln -s 2.3.6-trusty-amd64 2.3.6-xenial-amd64" # workaround for LP: #1749201 | |
juju update-series $MACHINE_ID xenial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment