Skip to content

Instantly share code, notes, and snippets.

@mkody mkody/upgradeMasto.sh
Last active Aug 23, 2018

Embed
What would you like to do?
im-in.space upgrade script
#!/bin/bash
# Notes:
# - The mastodon user is allowed to execute the `sudo systemctl` commands without any password promps
# - Three remotes: origin (im-in-space/mastodon), upstream (tootsuite/mastodon) and glitch-soc (gitch-soc/mastodon)
# - Three branches: im-in.space (our branch), master (based on upstream) and glitch-soc (based on glitch-soc)
# - If there's conflits in the merge, SAY NO to the second prompt and go fix em (+ `git commit`) before continuing
# Go to the mastodon install dir
cd live
read -n 1 -p "Pull and merge? [y/N]: " contG
echo -e ""
if [ "$contG" = "y" ]; then
echo -e "\n#################################################"
echo -e "# Checkout/pull/push master #"
echo -e "#################################################\n"
git checkout master && git pull upstream master && git push origin master && git checkout im-in.space
echo -e "\n#################################################"
echo -e "# Checkout/pull/push/merge glitch-soc #"
echo -e "#################################################\n"
git checkout glitch-soc && git pull glitch-soc master && git push origin glitch-soc && git checkout im-in.space && git merge glitch-soc --ff -m "Instance update ($(date --utc +'%Y-%m-%d %H:%M (UTC)'))"
fi
read -n 1 -p "Continue? [y/N]: " contU
echo -e ""
if [ "$contU" = "y" ]; then
echo -e "\n#################################################"
echo -e "# Push git im-in.space; Push tags #"
echo -e "#################################################\n"
git push origin im-in.space
git fetch --tags upstream && git push --tags origin
echo -e "\n#################################################"
echo -e "# Send warning toot; Stop ElasticSearch #"
echo -e "#################################################\n"
toot post "We're soon updating our instance. Expect some slowdowns for the next couple of minutes! :spacecore:​ 👁️"
sudo systemctl stop elasticsearch.service
echo -e "\n#################################################"
echo -e "# Update deps #"
echo -e "#################################################\n"
bundle install
yarn install --prod --pure-lockfile
echo -e "\n#################################################"
echo -e "# Precompile #"
echo -e "#################################################\n"
read -n 1 -p "Do it? [y/N]: " contC
echo -e ""
if [ "$contC" = "y" ]; then
RAILS_ENV=production bundle exec rails assets:precompile
fi
echo -e "\n#################################################"
echo -e "# Notify maintenance; Stop services; Migrate DB #"
echo -e "#################################################\n"
toot post "Instance update, we'll be back in a minute! :spacecore:​ 👁️" --visibility=public
sleep 8
sudo systemctl stop mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
RAILS_ENV=production bundle exec rails db:migrate
echo -e "\n#################################################"
echo -e "# Start services; Done #"
echo -e "#################################################\n"
sudo systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
sleep 15
sudo systemctl start elasticsearch.service
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.