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.1 2004/07/30 16:46:24 mlh-pl_kernel Exp $
22 # number of images to keep cached
25 # fill the cache periodically
32 pidfile=/var/run/vcached.pid
35 logfile=/var/log/vcached.log
44 while getopts 'fd' OPT ; do
51 # check if we are already running
52 [ -f $pidfile ] && exit 1
55 if [ $foreground -eq 0 ] ; then
56 nohup nice -n $nice -- $0 $* -f >>$logfile 2>&1 &
61 trap "killall -q -w vbuild ; rm -f $pidfile ; exit 255" EXIT
64 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
65 test -e "$UTIL_VSERVER_VARS" || {
66 echo "Can not find util-vserver installation; aborting..."
69 . "$UTIL_VSERVER_VARS"
72 chattr -R -i "$VROOTDIR/.vtmp"
73 rm -rf "$VROOTDIR/.vtmp"
75 mkdir -p "$VROOTDIR/.vcache"
76 mkdir -p "$VROOTDIR/.vtmp"
80 [ $debug -ne 0 ] && echo "$(date) Checking the cache"
81 for i in $(seq 0 $(($slots - 1))) ; do
82 if [ ! -d "$VROOTDIR/.vcache/v$i" ] ; then
83 echo "$(date) Caching v$i"
84 # build image in .vtmp
85 "$PKGLIBDIR/vbuild" "$VROOTDIR/vserver-reference" "$VROOTDIR/.vtmp/v$i"
86 # move it to .vcache when complete
87 mv "$VROOTDIR/.vtmp/v$i" "$VROOTDIR/.vcache/v$i"
88 echo "$(date) v$i ready"
91 [ $debug -ne 0 ] && echo "$(date) Sleeping for $period seconds"