Skip to content

Instantly share code, notes, and snippets.

@JanDeDobbeleer
Created November 24, 2022 13:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanDeDobbeleer/e0c8e29295251fb0773b2c2cbad8ff8d to your computer and use it in GitHub Desktop.
Save JanDeDobbeleer/e0c8e29295251fb0773b2c2cbad8ff8d to your computer and use it in GitHub Desktop.
Matodon cleanup scripts
#!/bin/bash
cd /home/mastodon/live
bin/tootctl media remove --days=7
bin/tootctl preview-cards remove --days=7
bin/tootctl statuses remove --days=3
bin/tootctl media remove-orphans
SHELL=/bin/bash
PATH=/home/mastodon/.rbenv/shims:/home/mastodon/.rbenv/bin:/usr/local/bin:/usr/bin:/bin
###
### Mastodon cronjobs for media cache purging
###
RAILS_ENV=production
0 0 * * * /home/mastodon/scripts/cleanup.sh >> /home/mastodon/logs/cleanup-`date +\%F`.log 2>&1
0 0 * * * /home/mastodon/scripts/logs.sh >> /home/mastodon/logs/logs-`date +\%F`.log 2>&1
#!/bin/bash
find /home/mastodon/logs -type f -mtime +7 -delete
@mhemeryck
Copy link

equivalent cron job for my k8s setup:

---                                                                                                                                                                                          
apiVersion: batch/v1                                                                                                                                                                         
kind: CronJob                                                                                                                                                                                
metadata:                                                                                                                                                                                    
  name: mastodon-cleanup                                                                                                                                                                     
spec:                                                                                                                                                                                        
  schedule: "0 0 * * *"                                                                                                                                                                      
  jobTemplate:                                                                                                                                                                               
    spec:                                                                                                                                                                                    
      template:                                                                                                                                                                              
        spec:                                                                                                                                                                                
          restartPolicy: Never                                                                                                                                                               
          volumes:                                                                                                                                                                           
            - name: mastodon-public-system                                                                                                                                                   
              persistentVolumeClaim:                                                                                                                                                         
                claimName: mastodon-public-system                                                                                                                                            
          containers:                                                                                                                                                                        
            - name: mastodon-cleanup                                                                                                                                                         
              image: tootsuite/mastodon:v3.5.4                                                                                                                                               
              volumeMounts:                                                                                                                                                                  
                - name: mastodon-public-system                                                                                                                                               
                  mountPath: /mastodon/public/system                                                                                                                                         
              envFrom:                                                                                                                                                                       
                - configMapRef:                                                                                                                                                              
                    name: mastodon                                                                                                                                                           
                - secretRef:                                                                                                                                                                 
                    name: mastodon                                                                                                                                                           
              command: ["/bin/sh"]                                                                                                                                                           
              args:                                                                                                                                                                          
                - -c                                                                                                                                                                         
                - |                                                                                                                                                                          
                  tootctl media remove --days=7                                                                                                                                              
                  tootctl preview-cards remove --days=7                                                                                                                                      
                  tootctl statuses remove --days=3                                                                                                                                           
                  tootctl media remove-orphans

Notea:

  1. the volume names are for a volume that's shared with the main web container.
  2. I couldn't find anything really logged to file inside the container, so that's not covered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment