merge to HEAD as of 2006-08-21
[vserver-reference.git] / vserver-reference.init
1 #!/bin/bash
2 #
3 # vserver-reference     Updates VServer reference
4 #
5 # Load before pl_conf, pl_nm, vcached, and vservers
6 # chkconfig: 3 60 80
7 # description: Builds VServer reference image
8 #
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2004 The Trustees of Princeton University
11 #
12 # $Id: vserver-reference.init,v 1.24 2006/08/10 18:49:16 mlhuang Exp $
13 #
14
15 case "$1" in
16     start|restart|reload)
17         ;;
18     stop|status)
19         exit 0
20         ;;
21     *)
22         echo $"Usage: $0 {start|stop|restart|status}"
23         exit 1
24         ;;
25 esac
26
27 # Source function library.
28 . /etc/init.d/functions
29
30 # VServer definitions
31 . /usr/lib/util-vserver/util-vserver-vars
32
33 # Parse PLC configuration
34 if [ -r /etc/planetlab/plc_config ] ; then
35     . /etc/planetlab/plc_config
36 else
37     PLC_NAME="PlanetLab"
38     PLC_SLICE_PREFIX="pl"
39     PLC_BOOT_HOST="boot.planet-lab.org"
40 fi
41
42 # Save stdout and stderr
43 exec 3>&1
44 exec 4>&2
45
46 # Redirect stdout and stderr to a log file
47 exec 2>&1
48 exec &>/var/log/vserver-reference.log
49
50 echo -n $"Updating VServer reference: " >&3 2>&4
51
52 shopt -s nullglob
53
54 VROOTS="$__DEFAULT_VSERVERDIR/vserver-reference $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
55
56 # Make sure the barrier bit is set
57 chmod 0000 /vservers
58 setattr --barrier /vservers
59
60 # Copy configuration files from host to slices
61 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf /etc/planetlab/node_id \
62             /etc/planetlab/plc_config* /etc/planetlab/php/* \
63             /etc/pki/rpm-gpg/* ; do
64     if [ -r $file ] ; then
65         for vroot in $VROOTS ; do
66             install -D -m 644 $file $vroot/$file
67         done
68     fi
69 done
70
71 # Remove stale RPM locks
72 rm -f $vroot/var/lib/rpm/__db*
73
74 # (Re)install GPG signing keys
75 if [ -d /etc/pki/rpm-gpg ] ; then
76     for vroot in $VROOTS ; do
77         chroot $vroot rpm --allmatches -e gpg-pubkey || :
78         chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
79     done
80 fi
81
82 # Old versions of the Boot Manager copied portions of the Boot CD to
83 # /mnt/cdrom/bootme, to support old scripts which assumed that the
84 # Boot CD was mounted even in production mode. Now, it just copies it
85 # to /usr/boot/cacert.pem. In any case, copy the boot server
86 # certificate to the place(s) where BootServerRequest expects to find
87 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
88 # versions).
89 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
90 for cacert in $CACERT ; do
91     if [ -r $cacert ] ; then
92         for vroot in $VROOTS ; do
93             # Install boot server certificate
94             install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
95             echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
96
97             # Also install in /mnt/cdrom/bootme for backward compatibility
98             install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
99             echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
100         done
101         break
102     fi
103 done
104
105 success >&3 2>&4
106 echo >&3 2>&4
107 exit 0