Automated bash scripts for managing Mastodon instance upgrades, designed for the mementomori.social workflow but adaptable to other instances.
When it's upgrade day - Test and upgrade workflow with the scripts
You don't even have to create announcement and status page update manually, the script will prompt about it.
sudo su mastodon# Long oneliner in local environment
cd ~ && (test -d upgrade-workflow-automation && cd upgrade-workflow-automation && git pull || git clone https://github.com/mementomori-social/upgrade-workflow-automation.git) && cd ~/upgrade-workflow-automation && bash mastodon-upgrade-local.shAfter testing and verification, SSH to your production server and deploy:
ssh your-production-serversudo su mastodon# Long oneliner in production
cd ~ && (test -d upgrade-workflow-automation && cd upgrade-workflow-automation && git pull || git clone https://github.com/mementomori-social/upgrade-workflow-automation.git) && cd ~/upgrade-workflow-automation && bash mastodon-upgrade-production.shOptional: Update Mastodon Bird UI if there are new changes:
bash mastodon-bird-ui-update.sh- Automatic git remote detection - Detects your fork and upstream remotes automatically
- Commit behind tracking - Shows how many commits behind upstream before sync
- Colored output - Modern, visually appealing progress indicators
- Service management - Automatic service startup/restart handling
- Migration management - Handles database migrations with confirmations
- Search index rebuilding - Manages Elasticsearch index updates
- Upgrade logging - Tracks upgrade history for documentation
- Safety confirmations - Production-safe with multiple confirmation prompts
mastodon-upgrade-local.sh handles the development environment upgrade process:
- Checks and starts required services automatically
- Fetches current production version from API
- Manages GitHub fork sync workflow
- Builds and tests changes
- Creates new versioned branches
- Merges modifications from previous branches
mastodon-upgrade-production.sh manages production deployments:
- Requires database backup before proceeding
- Service status validation
- Careful migration handling with live database warnings
- Optional search index rebuilding
- Service restart management
- Post-deployment monitoring
This automation expects specific Mastodon installation setups:
Local development environment:
- Mastodon installed at
/opt/mastodon - Running as
mastodonuser - Services:
mastodon-web,mastodon-sidekiq,mastodon-streaming - PostgreSQL service available
Production environment:
- Mastodon installed at
/home/mastodon/live - Running as
mastodonuser - Database server accessible (can be remote)
- Backup directory configured and writable
- Git - For repository management
- Ruby (via rbenv) - Version management
- Node.js (via nvm) - For asset compilation (v22.18.0 recommended for production parity)
- Yarn - Package manager (managed by corepack)
- PostgreSQL client - For database operations
- GitHub CLI (optional) - For automated fork syncing:
sudo apt install gh
mastodonuser must have sudo privileges for service management- Write access to backup directory (production)
- SSH access to database server (if remote)
- Copy scripts to your Mastodon user's home directory:
sudo cp mastodon-upgrade-*.sh /home/mastodon/
sudo chown mastodon:mastodon /home/mastodon/mastodon-upgrade-*.sh
sudo chmod +x /home/mastodon/mastodon-upgrade-*.sh- Switch to mastodon user and run:
sudo su - mastodon
./mastodon-upgrade-local.shThe scripts support configuration via a .env file. Copy the example and customize:
cp .env.example .env
nano .envIf not using a .env file, you can edit the scripts directly to customize:
MASTODON_DIR="/opt/mastodon"- Your Mastodon installation directoryAPI_URL="https://your-instance.com/api/v1/instance"- Your instance API URLYOUR_FORK_REPO="your-org/mastodon"- Your fork repository
PRODUCTION_MASTODON_DIR="/home/mastodon/live"- Production Mastodon directoryDB_HOST,DB_PORT,DB_USER- Database server settings for backupsBACKUP_DIR="/tmp/mastodon-backups"- Where to store database backups
Template service files for development environment are provided in the systemd/ directory. These are configured for /opt/mastodon with RAILS_ENV=development and NODE_ENV=development.
# Copy service files to systemd
sudo cp systemd/*.service /etc/systemd/system/
sudo systemctl daemon-reload
# Enable services to start on boot
sudo systemctl enable mastodon-web mastodon-sidekiq mastodon-streaming mastodon-streaming@4000# Start services
sudo systemctl start mastodon-web mastodon-sidekiq mastodon-streaming
# Restart services
sudo systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
# View logs
journalctl -u mastodon-web -f
journalctl -u mastodon-streaming@4000 -fMastodon loads environment variables from .env.{environment}.local files, which override tracked defaults. Create .env.development.local in your Mastodon directory with your configuration (database credentials, domain, secrets, etc). This file is ignored by git.
- Service check - Ensures all services are running
- Version detection - Gets current production version
- Commit analysis - Checks how many commits behind upstream
- GitHub sync - Prompts for manual fork sync
- Build and test - Installs dependencies and builds
- Migration - Handles database migrations
- Branch management - Creates new branch and merges mods
- Verification - Manual testing checklist
- Backup reminder - Database backup instructions
- Service validation - Checks current service status
- Code deployment - Fetches and applies changes
- Migration - Runs database migrations with confirmation
- Service restart - Restarts all Mastodon services
- Monitoring - Shows log output for verification
All upgrades are logged to ~/mastodon-upgrades.log with format:
2025-08-30 14:30:00 - Upgrade completed: mementomods-2025-08-29 -> mementomods-2025-08-30 (was 42 commits behind)
To adapt for your instance:
- Update the organization/fork references:
YOUR_FORK_REPO="your-org/mastodon"- Modify the git remote detection pattern:
if [[ "$url" =~ your-org/mastodon ]]; then- Adjust paths for your environment:
MASTODON_DIR="/your/mastodon/path"Created for mementomori.social - A Mastodon instance focused on memory, mortality, and mindful living.
These scripts automate our manual upgrade workflow documented at help.mementomori.social