Skip to content

Commit

Permalink
Add Makefile for deploy, maintainance.sh for misc maintananace
Browse files Browse the repository at this point in the history
  • Loading branch information
fono09 committed Mar 7, 2024
1 parent 66aff99 commit 560b642
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Makefile
@@ -0,0 +1,11 @@
stack = mastodon
envfile = ./.env.production

include $(envfile)
export

up:
docker stack deploy -c docker-compose.yml $(stack)

config:
docker compose -f docker-compose.yml config
19 changes: 16 additions & 3 deletions docker-compose.yml
Expand Up @@ -104,7 +104,7 @@ services:
- LETSENCRYPT_EMAIL=fono@fono.jp
deploy:
mode: replicated
replicas: 3
replicas: 4
endpoint_mode: vip

before_migration:
Expand All @@ -122,6 +122,19 @@ services:
restart_policy:
condition: none

maintainance:
<<: *web
command: bash -c "bin/tootctl accounts prune && bin/tootctl media remove && bin/tootctl media remove-orphans && bin/tootctl preview_cards remove --days=21 && bin/tootctl media usage"
healthcheck:
test: ""
ports: []
deploy:
placement:
constraints: [node.hostname == okaya]
replicas: 0
restart_policy:
condition: none

after_migration:
<<: *web
command: bash -c "bundle exec rails db:migrate"
Expand Down Expand Up @@ -169,7 +182,7 @@ services:
- redis
deploy:
mode: replicated
replicas: 3
replicas: 4
endpoint_mode: vip

sidekiq:
Expand All @@ -190,7 +203,7 @@ services:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
deploy:
mode: replicated
replicas: 3
replicas: 4
endpoint_mode: vip

## Uncomment to enable federation with tor instances along with adding the following ENV variables
Expand Down
25 changes: 25 additions & 0 deletions maintainance.sh
@@ -0,0 +1,25 @@
#!/bin/bash
set -euxo pipefail

cd `dirname $0`
pwd

SERVICE_NAME=mastodon_maintainance


get_service_state(){
echo `docker service ps --format '{{ .DesiredState }}' $1`
}

date +"%F %T"
if [[ `get_service_state $SERVICE_NAME` != "Running" ]]; then
docker service scale $SERVICE_NAME=1
fi

while [[ `get_service_state $SERVICE_NAME` == "Running" ]]; do
date +"%F %T"
sleep 10
done

date +"%F %T"
docker service scale $SERVICE_NAME=0

0 comments on commit 560b642

Please sign in to comment.