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
37 echo vunify [ --undo ] ref-vserver vservers -- packages
40 if [ "$1" == "--undo" ] ; then
47 while [ "$1" != "" -a "$1" != "--" ]
52 if [ "$servers" = "" ] ; then
53 echo No vserver specified >&2
55 elif [ "$1" != "--" ] ; then
56 echo Missing -- marker >&2
61 echo No package specified >&2
64 if [ ! -d /vservers/$ref/. ] ; then
65 echo No vserver $ref >&2
69 #echo servers=$servers
71 tmpfile=/var/run/vunifi.$$
73 echo Extracting list of file to unify in $tmpfile
76 /vservers/$ref/bin/rpm --root /vservers/$ref -ql --dump $pkg | \
77 while read path size mtime md5 \
78 mode owner group isconfig isdoc rdev symlink
80 if [ "$isconfig" = 0 ] ; then
87 if [ "$undo" = 0 ] ; then
88 echo Unifying server $serv
89 cat $tmpfile | while read file
91 if [ ! -d /vservers/$ref/$file -a ! -L /vservers/$ref/$file ] ; then
92 ln -f /vservers/$ref/$file /vservers/$serv/$file
95 cat $tmpfile | while read file
97 chattr +i /vservers/$ref/$file
100 echo Differencing server $serv
101 cat $tmpfile | while read file
103 chattr -i /vservers/$ref/$file
104 if [ ! -d /vservers/$ref/$file ] ; then
105 rm -f /vservers/$serv/$file
106 cp -a /vservers/$ref/$file /vservers/$serv/$file