3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 # based on vunify by Jacques Gelinas
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # This scripts is used to unify the disk space used by vservers
21 # It takes various RPM packages and hard link them together so all
22 # vservers are sharing the same exact copy of the files.
23 # After doing so, it set them immutable, so the vserver can't change them
25 # This has the following advantages:
26 # -You save disk space. If you have 100 vservers, each using 500 megs
27 # (common linux server installation), you can unify 90% of that
28 # -Memory usage. Since the exact same binary are loaded, including
29 # the same shared object, you save some memory and this can increase
30 # performance, especially the memory cache usage.
32 # On the down side, you are loosing some flexibility. The vserver
33 # administrators can't upgrade package as they see fit, since the
34 # files are immutable. On the other end, just unifying glibc is probably
36 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
37 test -e "$UTIL_VSERVER_VARS" || {
38 echo "Can not find util-vserver installation; aborting..."
41 . "$UTIL_VSERVER_VARS"
44 echo vunify [ --undo ] ref-vserver vservers -- packages
47 if [ "$1" == "--undo" ] ; then
54 while [ "$1" != "" -a "$1" != "--" ]
59 if [ "$servers" = "" ] ; then
60 echo No vserver specified >&2
62 elif [ "$1" != "--" ] ; then
63 echo Missing -- marker >&2
68 echo No package specified >&2
71 if [ ! -d $VROOTDIR/$ref/. ] ; then
72 echo No vserver $ref >&2
76 #echo servers=$servers
78 tmpfile=/var/run/vunifi.$$
80 echo Extracting list of file to unify in $tmpfile
83 $VROOTDIR/$ref/bin/rpm --root $VROOTDIR/$ref -ql --dump $pkg | \
84 while read path size mtime md5 \
85 mode owner group isconfig isdoc rdev symlink
87 if [ "$isconfig" = 0 ] ; then
94 if [ "$undo" = 0 ] ; then
95 echo Unifying server $serv
96 cat $tmpfile | while read file
98 if [ ! -d $VROOTDIR/$ref/$file -a ! -L $VROOTDIR/$ref/$file ] ; then
99 ln -f $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file
102 cat $tmpfile | while read file
104 chattr +i $VROOTDIR/$ref/$file
107 echo Differencing server $serv
108 cat $tmpfile | while read file
110 chattr -i $VROOTDIR/$ref/$file
111 if [ ! -d $VROOTDIR/$ref/$file ] ; then
112 rm -f $VROOTDIR/$serv/$file
113 cp -a $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file