3 # vcached: VServer cache daemon
5 # Description: A daemon that periodically preallocates vservers and stores
6 # them in a cache. Preallocated vservers from the cache may be then used to
7 # instantiate real vservers. Requires that /var/run/vcached.pid does not
8 # exist on startup. Should start/stop/restart from /etc/init.d.
12 # Brent Chun - bnc@intel-research.net
13 # Tristan Koo - tristan.koo@intel-research.net
14 # William Wung - wungism@uclink.berkeley.edu
16 # Mark Huang <mlhuang@cs.princeton.edu>
17 # Copyright (c) 2004 The Trustees of Princeton University (Trustees).
19 # $Id: vcached,v 1.3 2004/08/25 14:58:45 mlh-pl_kernel Exp $
26 while getopts 'fd' OPT ; do
33 # check if we are already running
34 [ -f $pidfile ] && exit 1
37 if [ $foreground -eq 0 ] ; then
38 nohup nice -n $nice -- $0 $* -f >>$logfile 2>&1 &
43 trap "rm -f $pidfile ; exit 255" EXIT
46 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
47 test -e "$UTIL_VSERVER_VARS" || {
48 echo "Can not find util-vserver installation; aborting..."
51 . "$UTIL_VSERVER_VARS"
54 chattr -R -i "$VROOTDIR/.vtmp"
55 rm -rf "$VROOTDIR/.vtmp"
57 mkdir -p "$VROOTDIR/.vcache"
58 mkdir -p "$VROOTDIR/.vtmp"
62 [ $debug -ne 0 ] && echo "$(date) Checking the cache"
63 for i in $(seq 0 $(($slots - 1))) ; do
64 if [ ! -d "$VROOTDIR/.vcache/v$i" ] ; then
65 echo "$(date) Caching v$i"
66 # build image in .vtmp
67 TMP=$(mktemp -d "$VROOTDIR/.vtmp/v$i.XXXXXX")
68 "$PKGLIBDIR/vbuild" "$VROOTDIR/vserver-reference" "$TMP"
70 # move it to .vcache when complete
71 if [ $RETVAL -eq 0 ] ; then
72 mv "$TMP" "$VROOTDIR/.vcache/v$i"
73 echo "$(date) v$i ready"
75 echo "$(date) Error $RETVAL building v$i"
80 [ $debug -ne 0 ] && echo "$(date) Sleeping for $period seconds"