shithub: scripts

ref: 3519f1d58ff78407227adb5a3a202d7a4e626a93
dir: /bin/rc/librarysrv/

View raw version
#!/bin/rc

librarysrv=/n/santiago/srv/library
libraryrmtpt=/n/libraryroot
librarymtpt=/n/library
cachemtpt=/n/ramfs.library

cmd=$1
switch($cmd) {
case start
	echo 'starting cached library'
case halt
	echo 'halting cached library'
	for(mtpt in $librarymtpt $libraryrmtpt $cachemtpt) {
		echo 'unmounting' $mtpt
		unmount $mtpt
	}

	for(srvf in /srv/library.cached /srv/ramfs.library) {
		echo 'removing' $srvf
		rm $srvf
	}

	echo 'done halting; you may kill ramfs and cfs now'
	exit
case *
	echo 'usage: librarysrv start|halt'
	exit
}

#cachesize=8192		# 32
cachesize=16384		# 64M

if(! test -f $librarysrv) {
	echo 'library server' $librarysrv 'not found'
	exit
}

if(! test -f /srv/ramfs.library) {
	echo 'running ramfs'
	ramfs -S ramfs.library -m $cachemtpt
}
if not {
	mount /srv/ramfs.library $cachemtpt
}

if(! test -f $cachemtpt^'/cache') {
	echo 'creating cache:' $cachesize 'blocks'
	dd -if /dev/zero -of $cachemtpt^'/cache' -bs 4096 -count $cachesize
}

echo 'running cfs'
cfs -S -n -r -f $cachemtpt^'/cache' -F $librarysrv $libraryrmtpt

mkdir /tmp/library

libraryc=`{ls `{ls $libraryrmtpt | tail -n 1} | tail -n 1}

unionfs -m $librarymtpt -s library.cached /tmp/library $libraryc $librarymtpt