summaryrefslogtreecommitdiff
path: root/upgrade.sh
blob: 58437b9c406a6dc0b564b05ef161b3c0fdee53d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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