Browse Source

Add janitor job to clean up old files

Leave 10 most recent ttyrecs
Leave 5 most recent SOTW dump files
pull/1/head
Matthew Faltys 5 years ago
parent
commit
66b958d952
  1. 2
      Makefile
  2. 1
      deps/Dockerfile
  3. 28
      deps/clean.sh
  4. 6
      deps/link_sotw.sh
  5. 19
      nethack-launcher/cleanup.go
  6. 4
      nethack-launcher/print_user_screen.go

2
Makefile

@ -11,6 +11,7 @@ all: stat
run:
go run \
nethack-launcher/check_dir.go \
nethack-launcher/cleanup.go \
nethack-launcher/create_initial_files.go \
nethack-launcher/create_user_files.go \
nethack-launcher/janitor.go \
@ -47,6 +48,7 @@ build_docker: fetch_sotw
cp deps/run_nethack.sh stage.tmp/
cp deps/reclist.c stage.tmp/
cp deps/link_sotw.sh stage.tmp/
cp deps/clean.sh stage.tmp/
cp deps/scores.dat stage.tmp/
wget -O stage.tmp/redis-server https://cryo.unixvoid.com/bin/redis/5.0.7/redis-server
chmod +x stage.tmp/redis-server

1
deps/Dockerfile vendored

@ -110,6 +110,7 @@ COPY chowner.sh /bin/
COPY nethackrc /.nethackrc
COPY run_nethack.sh /
COPY link_sotw.sh /bin/
COPY clean.sh /bin/
ADD sotw.tar.gz /
RUN mv /shadow-of-the-wyrm* /sotw/
COPY scores.dat /sotw/

28
deps/clean.sh vendored

@ -0,0 +1,28 @@
#!/bin/bash
HACKDIR=$1
USERDIR=$2
###
# clean old ttyrecs
###
cd /$HACKDIR/user/$USERDIR/ttyrec/
ls -1tr | head -n -10 | xargs -d '\n' rm -f --
###
# clean sotw files
###
cd /$HACKDIR/user/$USERDIR/sotw/
# there are always 4 symlinked files
# leave 5 of the latest dumps
FILES=$(ls -1tr *.txt | head -n -9)
for f in $FILES; do
#test -h $f || echo "removing old file $f"
if [ ! -h $f ]; then
echo "removing old file $f"
rm -rf $f
fi
done

6
deps/link_sotw.sh vendored

@ -16,6 +16,10 @@ done
# remove inital score file
rm -rf $USERDIR/sotw/scores.dat
# link in shared score file from hackdir
ln -s $HACKDIR/scores.dat $USERDIR/sotw/
# remove initial config file
rm -rf $USERDIR/sotw/swyrm.ini
# copy in sotw config file
cp $HACKDIR/swyrm.ini $USERDIR/sotw/

19
nethack-launcher/cleanup.go

@ -0,0 +1,19 @@
package main
import (
"fmt"
"os/exec"
)
func runCleanup(username string) {
// clean up ttyrecs in /<hackdir>/user/<username>/ttyrec/
// clean up sotw dumps, aka:
// non-symlinked .txt files in /<hackdir>/user/<username>/sotw/
// run cleanup file
out, err := exec.Command("/bin/clean.sh", config.NethackLauncher.HackDir, username).Output()
if err != nil {
fmt.Println(err)
}
fmt.Printf("%s\n", out)
}

4
nethack-launcher/print_user_screen.go

@ -94,7 +94,7 @@ func printUserScreen(redisClient *redis.Client, username string) string {
currentTime := time.Now().UTC()
fulltime := currentTime.Format("2006-01-02.03:04:05")
go runGame(username, fulltime)
//go runCleanup(username)
go runCleanup(username)
watcher := startWatcher(username, fulltime, redisClient)
wg.Wait()
close(watcher)
@ -104,7 +104,7 @@ func printUserScreen(redisClient *redis.Client, username string) string {
currentTime := time.Now().UTC()
fulltime := currentTime.Format("2006-01-02.03:04:05")
go runSotwGame(username, fulltime)
//go runCleanup(username)
go runCleanup(username)
watcher := startWatcher(username, fulltime, redisClient)
wg.Wait()
close(watcher)

Loading…
Cancel
Save