You've already forked mastodon-utils
mirror of
https://github.com/jakejarvis/mastodon-utils.git
synced 2025-06-27 17:25:42 -04:00
drastically improve the reliability of rbenv commands
This commit is contained in:
@ -3,40 +3,25 @@
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
# default paths
|
||||
MASTODON_ROOT=/home/mastodon
|
||||
APP_ROOT="$MASTODON_ROOT/live"
|
||||
UTILS_ROOT="$MASTODON_ROOT/utils"
|
||||
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
||||
|
||||
# clone this repo if it doesn't exist in the proper location
|
||||
if [ ! -d "$UTILS_ROOT" ]
|
||||
then
|
||||
sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-utils.git "$UTILS_ROOT"
|
||||
|
||||
# fix permissions
|
||||
sudo chown -R mastodon:mastodon "$UTILS_ROOT"
|
||||
sudo git config --global --add safe.directory "$UTILS_ROOT"
|
||||
fi
|
||||
# initialize path
|
||||
source "$(dirname "$(realpath "$0")")"/../init.sh
|
||||
|
||||
# apply custom patches
|
||||
cd "$APP_ROOT"
|
||||
sudo -u mastodon git apply --reject --allow-binary-replacement "$UTILS_ROOT"/patches/*.patch
|
||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ];
|
||||
then
|
||||
as_mastodon git apply --reject --allow-binary-replacement "$UTILS_ROOT"/patches/*.patch
|
||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
|
||||
# apply additional glitch-only patches:
|
||||
sudo -u mastodon git apply --reject --allow-binary-replacement "$UTILS_ROOT"/patches/glitch/*.patch
|
||||
as_mastodon git apply --reject --allow-binary-replacement "$UTILS_ROOT"/patches/glitch/*.patch
|
||||
fi
|
||||
|
||||
# update dependencies
|
||||
echo "Updating deps..."
|
||||
sudo -u mastodon "$RBENV_ROOT/shims/bundle" install --jobs "$(getconf _NPROCESSORS_ONLN)"
|
||||
sudo -u mastodon yarn install --pure-lockfile --network-timeout 100000
|
||||
as_mastodon bundle install --jobs "$(getconf _NPROCESSORS_ONLN)"
|
||||
as_mastodon yarn install --pure-lockfile --network-timeout 100000
|
||||
|
||||
# compile new assets
|
||||
echo "Compiling new assets..."
|
||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails assets:precompile
|
||||
sudo chown -R mastodon:mastodon "$APP_ROOT"
|
||||
as_mastodon RAILS_ENV=production bundle exec rails assets:precompile
|
||||
|
||||
# restart frontend
|
||||
echo "Restarting mastodon-web..."
|
||||
|
@ -1,31 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
# cronjob ran once per week at 3 AM on Monday; see https://crontab.guru/#0_3_*_*_1
|
||||
# syntax for crontab -e:
|
||||
# 0 3 * * 1 bash -c "/home/mastodon/utils/scripts/backup.sh >> /home/mastodon/logs/cron.log 2>&1"
|
||||
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
# default paths
|
||||
MASTODON_ROOT=/home/mastodon
|
||||
APP_ROOT="$MASTODON_ROOT/live"
|
||||
BACKUPS_ROOT="$MASTODON_ROOT/backups"
|
||||
# initialize path
|
||||
source "$(dirname "$(realpath "$0")")"/../init.sh
|
||||
|
||||
if [ "$(systemctl is-active mastodon-web.service)" = "active" ]
|
||||
then
|
||||
if [ "$(systemctl is-active mastodon-web.service)" = "active" ]; then
|
||||
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
|
||||
sudo mkdir -p "$BACKUPS_ROOT"
|
||||
sudo chown -R mastodon:mastodon "$BACKUPS_ROOT"
|
||||
if [ ! -d "$BACKUPS_ROOT" ]; then
|
||||
as_mastodon mkdir -p "$BACKUPS_ROOT"
|
||||
fi
|
||||
|
||||
TEMP_DIR=$(sudo -u mastodon mktemp -d)
|
||||
if [ ! -d "$LOGS_ROOT" ]; then
|
||||
as_mastodon mkdir -p "$LOGS_ROOT"
|
||||
fi
|
||||
|
||||
TEMP_DIR=$(as_mastodon mktemp -d)
|
||||
|
||||
echo "Backing up Postgres..."
|
||||
sudo -u mastodon pg_dump -Fc mastodon_production -f "$TEMP_DIR/postgres.dump"
|
||||
as_mastodon pg_dump -Fc mastodon_production -f "$TEMP_DIR/postgres.dump"
|
||||
|
||||
echo "Backing up Redis..."
|
||||
sudo cp /var/lib/redis/dump.rdb "$TEMP_DIR/redis.rdb"
|
||||
|
@ -4,20 +4,8 @@
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
# default paths
|
||||
MASTODON_ROOT=/home/mastodon
|
||||
APP_ROOT="$MASTODON_ROOT/live"
|
||||
UTILS_ROOT="$MASTODON_ROOT/utils"
|
||||
|
||||
# clone this repo if it doesn't exist in the proper location
|
||||
if [ ! -d "$UTILS_ROOT" ]
|
||||
then
|
||||
sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-utils.git "$UTILS_ROOT"
|
||||
|
||||
# fix permissions
|
||||
sudo chown -R mastodon:mastodon "$UTILS_ROOT"
|
||||
sudo git config --global --add safe.directory "$UTILS_ROOT"
|
||||
fi
|
||||
# initialize path
|
||||
source "$(dirname "$(realpath "$0")")"/../init.sh
|
||||
|
||||
# setup nginx config
|
||||
sudo rm -rf /etc/nginx/sites-available
|
||||
|
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
MASTODON_ROOT=/home/mastodon
|
||||
APP_ROOT="$MASTODON_ROOT/live"
|
||||
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
||||
|
||||
tootctl() {
|
||||
( cd "$APP_ROOT" && sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/ruby" "$APP_ROOT/bin/tootctl" "$@" )
|
||||
}
|
@ -3,30 +3,21 @@
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
# default paths
|
||||
MASTODON_ROOT=/home/mastodon
|
||||
APP_ROOT="$MASTODON_ROOT/live"
|
||||
UTILS_ROOT="$MASTODON_ROOT/utils"
|
||||
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
||||
|
||||
# check for existing installation
|
||||
if [ ! -d "$APP_ROOT" ]; then
|
||||
echo "$APP_ROOT doesn't exist, are you sure Mastodon is installed?"
|
||||
exit 255
|
||||
fi
|
||||
# initialize path
|
||||
source "$(dirname "$(realpath "$0")")"/../init.sh
|
||||
|
||||
# pull latest mastodon source
|
||||
cd "$APP_ROOT"
|
||||
sudo -u mastodon git fetch --all
|
||||
sudo -u mastodon git stash push --message "pre-upgrade changes"
|
||||
as_mastodon git fetch --all
|
||||
as_mastodon git stash push --message "pre-upgrade changes"
|
||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
|
||||
# glitch-soc (uses latest commits)
|
||||
echo "Pulling latest glitch-soc commits..."
|
||||
sudo -u mastodon git checkout glitch-soc/main
|
||||
as_mastodon git checkout glitch-soc/main
|
||||
else
|
||||
# vanilla (uses latest release)
|
||||
echo "Pulling latest Mastodon release..."
|
||||
sudo -u mastodon git checkout "$(sudo -u mastodon git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
|
||||
as_mastodon git checkout "$(as_mastodon git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
|
||||
fi
|
||||
|
||||
# pull & apply latest patches
|
||||
@ -34,17 +25,17 @@ fi
|
||||
|
||||
# create blank custom.css (this overrides any CSS set in the admin panel, but if that's not being used, then
|
||||
# this quickly saves a request to the backend)
|
||||
sudo -u mastodon touch "$APP_ROOT/public/custom.css"
|
||||
as_mastodon touch "$APP_ROOT/public/custom.css"
|
||||
|
||||
# set new ruby version
|
||||
RUBY_VERSION="$(sudo -u mastodon cat $APP_ROOT/.ruby-version)"
|
||||
sudo -u mastodon RUBY_CONFIGURE_OPTS=--with-jemalloc "$RBENV_ROOT/bin/rbenv" install "$RUBY_VERSION" || true
|
||||
sudo -u mastodon "$RBENV_ROOT/bin/rbenv" global "$RUBY_VERSION"
|
||||
RUBY_VERSION="$(as_mastodon cat "$APP_ROOT"/.ruby-version)"
|
||||
as_mastodon RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install "$RUBY_VERSION"
|
||||
as_mastodon rbenv global "$RUBY_VERSION"
|
||||
|
||||
# run migrations:
|
||||
# https://docs.joinmastodon.org/admin/upgrading/
|
||||
echo "Running pre-deploy database migrations..."
|
||||
sudo -u mastodon SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production DB_PORT=5432 "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||
as_mastodon SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production DB_PORT=5432 bundle exec rails db:migrate
|
||||
|
||||
# restart mastodon
|
||||
echo "Restarting services (round 1/2)..."
|
||||
@ -52,9 +43,9 @@ sudo systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
|
||||
|
||||
# clear caches & run post-deployment db migration
|
||||
echo "Clearing cache..."
|
||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/ruby" "$APP_ROOT/bin/tootctl" cache clear
|
||||
as_mastodon RAILS_ENV=production ruby "$APP_ROOT/bin/tootctl" cache clear
|
||||
echo "Running post-deploy database migrations..."
|
||||
sudo -u mastodon RAILS_ENV=production DB_PORT=5432 "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||
as_mastodon RAILS_ENV=production DB_PORT=5432 bundle exec rails db:migrate
|
||||
|
||||
# restart mastodon again
|
||||
echo "Restarting services (round 2/2)..."
|
||||
|
@ -1,7 +1,11 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
. "$(dirname "$0")/tootctl_shim.sh"
|
||||
# initialize path
|
||||
source "$(dirname "$(realpath "$0")")"/../init.sh
|
||||
|
||||
tootctl version
|
||||
echo "* rbenv version: $(rbenv --version)"
|
||||
echo "* Ruby version: $(ruby --version)"
|
||||
echo "* Mastodon version: $(tootctl version)"
|
||||
|
@ -1,12 +1,18 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# cronjob ran once per week at 3 AM on Sunday; see https://crontab.guru/#0_3_*_*_0
|
||||
# syntax for crontab -e:
|
||||
# 0 3 * * 0 root /home/mastodon/utils/weekly_cleanup.sh >> /home/mastodon/logs/cron.log 2>&1
|
||||
# 0 3 * * 0 bash -c "/home/mastodon/utils/scripts/weekly_cleanup.sh >> /home/mastodon/logs/cron.log 2>&1"
|
||||
|
||||
set -e
|
||||
# exit when any step fails
|
||||
set -euo pipefail
|
||||
|
||||
. "$(dirname "$0")/tootctl_shim.sh"
|
||||
# initialize path
|
||||
source "$(dirname "$(realpath "$0")")"/../init.sh
|
||||
|
||||
if [ ! -d "$LOGS_ROOT" ]; then
|
||||
as_mastodon mkdir -p "$LOGS_ROOT"
|
||||
fi
|
||||
|
||||
tootctl media remove --days 7
|
||||
tootctl preview_cards remove --days 90
|
||||
|
Reference in New Issue
Block a user