You've already forked mastodon-utils
mirror of
https://github.com/jakejarvis/mastodon-utils.git
synced 2025-06-27 17:25:42 -04:00
make it a whole lot easier to set custom env variables
This commit is contained in:
@ -14,46 +14,51 @@ echo -e "\n===== backup.sh: started at $(date '+%Y-%m-%d %H:%M:%S') =====\n"
|
||||
. "$(dirname "${BASH_SOURCE[0]}")"/../init.sh
|
||||
|
||||
if [ "$(systemctl is-active mastodon-web.service)" = "active" ]; then
|
||||
echo "⚠️ Mastodon is currently running."
|
||||
echo "⚠ Mastodon is currently running."
|
||||
echo "We'll start the backup anyways, but if it's a critical one, stop all Mastodon"
|
||||
echo "services first with 'systemctl stop mastodon-*' and run this again."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ ! -d "$BACKUPS_ROOT" ]; then
|
||||
as_mastodon mkdir -p "$BACKUPS_ROOT"
|
||||
sudo mkdir -p "$BACKUPS_ROOT"
|
||||
fi
|
||||
|
||||
TEMP_DIR=$(as_mastodon mktemp -d)
|
||||
# TODO: ugly, do better
|
||||
TEMP_DIR=$(sudo mktemp -d)
|
||||
sudo chmod 777 "$TEMP_DIR"
|
||||
|
||||
echo "Backing up Postgres..."
|
||||
as_mastodon pg_dump -Fc mastodon_production -f "$TEMP_DIR/postgres.dump"
|
||||
echo "* Backing up Postgres..."
|
||||
sudo -u postgres pg_dump -Fc mastodon_production -f "$TEMP_DIR/postgres.dump"
|
||||
|
||||
echo "Backing up Redis..."
|
||||
echo "* Backing up Redis..."
|
||||
sudo cp /var/lib/redis/dump.rdb "$TEMP_DIR/redis.rdb"
|
||||
|
||||
echo "Backing up secrets..."
|
||||
echo "* Backing up secrets..."
|
||||
sudo cp "$APP_ROOT/.env.production" "$TEMP_DIR/env.production"
|
||||
|
||||
echo "Backing up certs..."
|
||||
echo "* Backing up certs..."
|
||||
sudo mkdir -p "$TEMP_DIR/certs"
|
||||
sudo cp -r /etc/letsencrypt/{archive,live,renewal} "$TEMP_DIR/certs/"
|
||||
|
||||
echo "Compressing..."
|
||||
echo "* Compressing..."
|
||||
ARCHIVE_DEST="$BACKUPS_ROOT/mastodon-$(date "+%Y.%m.%d-%H.%M.%S").tar.gz"
|
||||
sudo tar --owner=0 --group=0 -czvf "$ARCHIVE_DEST" -C "$TEMP_DIR" .
|
||||
sudo chown "$MASTODON_USER":"$MASTODON_USER" "$ARCHIVE_DEST"
|
||||
|
||||
echo "Removing temp files..."
|
||||
echo "* Fixing permissions..."
|
||||
sudo chown -R "$MASTODON_USER":"$MASTODON_USER" "$BACKUPS_ROOT"
|
||||
|
||||
echo "* Removing temp files..."
|
||||
sudo rm -rf --preserve-root "$TEMP_DIR"
|
||||
|
||||
echo "Saved to $ARCHIVE_DEST"
|
||||
echo "* Saved archive to '$ARCHIVE_DEST'"
|
||||
|
||||
if [ -s /usr/local/bin/linode-cli ]; then
|
||||
echo "Uploading to S3..."
|
||||
echo "* Uploading to S3..."
|
||||
sudo /usr/local/bin/linode-cli obj put "$ARCHIVE_DEST" jarvis-backup
|
||||
fi
|
||||
|
||||
echo "🎉 done! (keep this archive safe!)"
|
||||
echo "* 🎉 done! (keep this archive safe!)"
|
||||
|
||||
echo -e "\n===== backup.sh: finished at $(date '+%Y-%m-%d %H:%M:%S') =====\n"
|
||||
|
@ -7,7 +7,7 @@ set -euo pipefail
|
||||
# shellcheck disable=SC1091
|
||||
. "$(dirname "${BASH_SOURCE[0]}")"/../init.sh
|
||||
|
||||
# re-detect glitch-soc
|
||||
# re-detect glitch-soc (answer might have changed since first sourcing init.sh)
|
||||
MASTODON_IS_GLITCH="$(test -d "$APP_ROOT/app/javascript/flavours/glitch" && echo true || echo false)"
|
||||
|
||||
# ---
|
||||
@ -41,8 +41,8 @@ if [ "$MASTODON_IS_GLITCH" = true ]; then
|
||||
"public/riot-glitch.png"
|
||||
)
|
||||
|
||||
for f in "${removePaths[@]}"; do
|
||||
as_mastodon rm -rf --preserve-root "$APP_ROOT/$f"
|
||||
for r in "${removePaths[@]}"; do
|
||||
as_mastodon rm -rf --preserve-root "$APP_ROOT/$r"
|
||||
done
|
||||
fi
|
||||
|
||||
|
@ -3,10 +3,7 @@
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
# :)
|
||||
MY_NAME_IS_JAKE_JARVIS="false"
|
||||
|
||||
# can't say you weren't warned
|
||||
# can't say you weren't warned :)
|
||||
if [ "$MY_NAME_IS_JAKE_JARVIS" != "pinky promise" ]; then
|
||||
echo "🚨 LISTEN UP!!!! YOU PROBABLY WANT THIS SCRIPT INSTEAD:"
|
||||
echo "https://github.com/jakejarvis/mastodon-installer/blob/main/install.sh"
|
||||
@ -19,7 +16,7 @@ fi
|
||||
|
||||
# check for existing installation
|
||||
if [ -d "$APP_ROOT" ]; then
|
||||
echo "⚠️ $APP_ROOT already exists. Are you sure Mastodon isn't already installed?"
|
||||
echo "⚠ $APP_ROOT already exists. Are you sure Mastodon isn't already installed?"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
@ -128,6 +125,7 @@ as_mastodon git checkout "$(as_mastodon git tag -l | grep -v 'rc[0-9]*$' | sort
|
||||
# as_mastodon git checkout glitch-soc/main
|
||||
|
||||
# apply customizations
|
||||
# shellcheck disable=SC1091
|
||||
. "$UTILS_ROOT"/scripts/customize.sh
|
||||
|
||||
# install ruby
|
||||
|
@ -3,10 +3,7 @@
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
# :)
|
||||
MY_NAME_IS_JAKE_JARVIS="false"
|
||||
|
||||
# can't say you weren't warned
|
||||
# can't say you weren't warned :)
|
||||
if [ "$MY_NAME_IS_JAKE_JARVIS" != "pinky promise" ]; then
|
||||
echo "🚨 LISTEN UP!!!! YOU PROBABLY WANT THIS SCRIPT INSTEAD:"
|
||||
echo "https://github.com/jakejarvis/mastodon-installer/blob/main/upgrade.sh"
|
||||
@ -23,53 +20,55 @@ as_mastodon git fetch --all
|
||||
as_mastodon git stash push --include-untracked --message "pre-upgrade changes"
|
||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
|
||||
# glitch-soc (uses latest commits)
|
||||
echo "Pulling latest glitch-soc commits..."
|
||||
echo "* Pulling latest glitch-soc commits..."
|
||||
as_mastodon git checkout glitch-soc/main
|
||||
else
|
||||
# vanilla (uses latest release)
|
||||
echo "Pulling latest Mastodon release..."
|
||||
echo "* Pulling latest Mastodon release..."
|
||||
as_mastodon git checkout "$(as_mastodon git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
|
||||
fi
|
||||
|
||||
# re-apply customizations
|
||||
echo "* Applying patches..."
|
||||
# shellcheck disable=SC1091
|
||||
. "$UTILS_ROOT"/scripts/customize.sh
|
||||
|
||||
# refresh dependencies
|
||||
echo "* Updating dependencies..."
|
||||
# set new ruby version
|
||||
as_mastodon RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install --skip-existing
|
||||
as_mastodon rbenv global "$(as_mastodon cat "$APP_ROOT"/.ruby-version)"
|
||||
|
||||
# set new node version
|
||||
as_mastodon nvm install
|
||||
as_mastodon nvm use
|
||||
as_mastodon npm install --global yarn
|
||||
|
||||
# update dependencies
|
||||
# install deps
|
||||
as_mastodon bundle install --jobs "$(getconf _NPROCESSORS_ONLN)"
|
||||
as_mastodon yarn install --pure-lockfile
|
||||
|
||||
# compile new assets
|
||||
echo "Compiling new assets..."
|
||||
echo "* Compiling new assets..."
|
||||
as_mastodon RAILS_ENV=production bundle exec rails assets:precompile
|
||||
|
||||
# run migrations:
|
||||
# https://docs.joinmastodon.org/admin/upgrading/
|
||||
echo "Running pre-deploy database migrations..."
|
||||
echo "* Running pre-deploy database migrations..."
|
||||
# note: DB_PORT is hard-coded because we need the raw DB, and .env.production might be pointing at pgbouncer
|
||||
as_mastodon DB_PORT=5432 SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate
|
||||
|
||||
# restart mastodon
|
||||
echo "Restarting services (round 1/2)..."
|
||||
echo "* Restarting services (round 1/2)..."
|
||||
sudo systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
|
||||
|
||||
# clear caches & run post-deployment db migration
|
||||
echo "Clearing cache..."
|
||||
echo "* Clearing cache..."
|
||||
as_mastodon RAILS_ENV=production ruby "$APP_ROOT/bin/tootctl" cache clear
|
||||
echo "Running post-deploy database migrations..."
|
||||
echo "* Running post-deploy database migrations..."
|
||||
# note: DB_PORT is hard-coded because we need the raw DB, and .env.production might be pointing at pgbouncer
|
||||
as_mastodon DB_PORT=5432 RAILS_ENV=production bundle exec rails db:migrate
|
||||
|
||||
# restart mastodon again
|
||||
echo "Restarting services (round 2/2)..."
|
||||
echo "* Restarting services (round 2/2)..."
|
||||
sudo systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
|
||||
|
||||
echo "🎉 done!"
|
||||
echo "* 🎉 done!"
|
||||
|
@ -13,3 +13,4 @@ echo "* Ruby: $(ruby --version)"
|
||||
echo "* Node.js: $(node --version)"
|
||||
echo "* Yarn: $(yarn --version)"
|
||||
echo "* Mastodon: $(tootctl version)"
|
||||
echo "* whoami: $(as_mastodon whoami)"
|
||||
|
Reference in New Issue
Block a user