diff options
author | doc <doc@filenotfound.org> | 2025-06-30 20:11:52 +0000 |
---|---|---|
committer | doc <doc@filenotfound.org> | 2025-06-30 20:11:52 +0000 |
commit | 41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 (patch) | |
tree | db7c3520fd91abc3cf56b1a52095d23f3a80d059 /upgrade.sh |
Diffstat (limited to 'upgrade.sh')
-rwxr-xr-x | upgrade.sh | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/upgrade.sh b/upgrade.sh new file mode 100755 index 0000000..58437b9 --- /dev/null +++ b/upgrade.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# ---- CONFIGURATION ---- +DOMAIN="your.mastodon.domain" # Replace this with your real domain +ACCOUNT_USERNAME="administration" +SCRIPT_PATH="/root/finish_upgrade.sh" +LOGFILE="/root/mastodon_upgrade_$(date +%F_%H-%M-%S).log" +exec > >(tee -a "$LOGFILE") 2>&1 +set -e + +echo "===== Mastodon 20.04 โ 22.04 Upgrade Starter =====" + +read -p "โ Have you backed up your system and database? (yes/no): " confirmed +if [[ "$confirmed" != "yes" ]]; then + echo "โ Aborting. Please take a backup." + exit 1 +fi + +echo "๐ง Updating system..." +apt update && apt upgrade -y +apt install update-manager-core curl -y + +echo "๐ Stopping Mastodon..." +systemctl stop mastodon-web mastodon-sidekiq mastodon-streaming + +echo "๐ Preparing post-reboot upgrade finalization..." + +# ---- Create finish_upgrade.sh ---- +cat << EOF > $SCRIPT_PATH +#!/bin/bash +LOGFILE="/root/mastodon_post_upgrade_\$(date +%F_%H-%M-%S).log" +exec > >(tee -a "\$LOGFILE") 2>&1 +set -e + +echo "===== Post-Reboot Finalization Script =====" + +echo "๐ Restarting Mastodon services..." +systemctl daemon-reexec +systemctl daemon-reload +systemctl start mastodon-web mastodon-sidekiq mastodon-streaming + +echo "โ
Checking service status..." +systemctl status mastodon-web --no-pager +systemctl status mastodon-sidekiq --no-pager +systemctl status mastodon-streaming --no-pager + +echo "๐ Homepage check..." +if curl --silent --fail https://$DOMAIN >/dev/null; then + echo "โ
Homepage is reachable." +else + echo "โ Homepage failed to load." +fi + +echo "๐ฃ Posting announcement toot..." +cd /home/mastodon/live +sudo -u mastodon -H bash -c ' +RAILS_ENV=production bundle exec rails runner " +acct = Account.find_by(username: \\"$ACCOUNT_USERNAME\\") +if acct + PostStatusService.new.call(acct, text: \\"โ
Server upgrade to Ubuntu 22.04 complete. We\\'re back online!\\") +end +"' + +echo "๐งน Cleaning up..." +apt autoremove -y && apt autoclean -y + +echo "๐ซ Removing rc.local to prevent rerun..." +rm -f /etc/rc.local +rm -f $SCRIPT_PATH + +echo "โ
Post-upgrade steps complete." +EOF + +chmod +x $SCRIPT_PATH + +# ---- Set rc.local to run after reboot ---- +cat << EOF > /etc/rc.local +#!/bin/bash +bash $SCRIPT_PATH +exit 0 +EOF + +chmod +x /etc/rc.local + +echo "" +echo "๐ Starting do-release-upgrade..." +sleep 3 +do-release-upgrade |