File: util-vserver-newvserver-cleanup.diff

package info (click to toggle)
vserver-debiantools 0.3.4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 184 kB
  • ctags: 24
  • sloc: sh: 1,440; makefile: 90
file content (204 lines) | stat: -rw-r--r-- 6,600 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
From: Daniel Hermann <hermann@tkm.physik.uni-karlsruhe.de>

--- newvserver.orig	2005-04-17 17:46:11.000000000 +0200
+++ newvserver	2005-04-17 18:54:08.000000000 +0200
@@ -62,9 +62,6 @@
 # Default network interface for vservers:
 INTERFACE="eth0"
 
-# Copy vreboot/vhalt/vshutdown utility into /usr/local/sbin/
-COPY_VREBOOT="true"
-
 if [ -r /etc/vservers/util-vserver-vars ] ; then
     . /etc/vservers/util-vserver-vars
 fi
@@ -96,15 +93,13 @@
 {
 	cat << EOF
 Usage:	${0##*/} [OPTIONS] --hostname x --domain y.z --ip 1.2.3.4
-Creates a new Debian vserver by downloading packages via HTTP/FTP
+Creates a new Debian vserver by calling "vserver ... build"
 
 Options:
         -h, --help		this help
         -V, --version		copyright and version information
 	--arch			set target architecture (eg. --arch "i386")
 				(autodetected on Debian host if dpkg available)
-	--copy-vreboot		install "vreboot/vshutdown/vhalt"
-	--no-copy-vreboot	don't install "vreboot/vshutdown/vhalt"
 	--dist			defaults to "sarge", passed to debootstrap.
 	--fakeinit		use "/sbin/init" to boot vserver
 	--conffile		extra configuration file to load.
@@ -184,14 +179,6 @@
                        fi
                        shift 2
                        ;;
-		    --copy-vreboot)
-			COPY_VREBOOT="true"
-			shift
-			;;
-		    --no-copy-vreboot)
-			COPY_VREBOOT=""
-			shift
-			;;
 		    --dist)
 			case "$2" in
 			    [a-z]*)
@@ -341,16 +328,6 @@
 ##############################################################################
 
 
-# Check we've got debootstrap available
-if [ ! -x /usr/sbin/debootstrap ]; then
-  cat << EOF 1>&2
-${0##*/}: Requires the debootstrap package to bootstrap Debian
-  Debian Host:	apt-get install debootstrap
-  RPM Host:	rpm -i http://people.debian.org/~blade/install/debootstrap/debootstrap-0.1.17.3-2.i386.rpm
-EOF
-  exit 1
-fi
-
 if ! cat /proc/self/status | grep '^s_context:[^0-9]0$'; then
     echo "${0##*/} error:"
     echo "	Must be run from the host server (security context 0)" 1>&2
@@ -364,33 +341,19 @@
   exit 1
 fi
 
-# check for /vserver/$VHOST/etc/ incase we are on pre-mounted LVM partition
-# (used to just check for "/vserver/$VHOST/" existing
-if [ -d "$VROOTDIR/$VHOST/etc/" -o -f "/etc/vservers/$VHOST.conf" ] ; then
-  cat << EOF 1>&2
-${0##*/} error: Virtual Server "$VHOST" appears to already exist
-  check "/etc/vservers/$VHOST.conf" or "/vservers/$VHOST/etc/";
-EOF
-  exit 1
-fi
-
-# This is used to keep a cache of the downloaded .deb packges for next install
-if [ -d "$VROOTDIR/ARCHIVES/$DIST" ]; then
-    mkdir -p "$VROOTDIR/$VHOST/var/cache/apt/archives"
-    cp -a "$VROOTDIR/ARCHIVES/$DIST/"*.deb "$VROOTDIR/$VHOST/var/cache/apt/archives" > /dev/null 2>&1
-fi
-
 # We only want to pass the Architecture if we need to (autodectected otherwise)
 if [ -n "$ARCH" ]; then
     ARCH_ARGUMENT="--arch $ARCH"
 fi
 
-# Fire off `debootstrap' to do all the hard work
-# like downloading and installing
-if ! /usr/sbin/debootstrap $ARCH_ARGUMENT \
-	"--include=$INSTALL_PACKAGES" "--exclude=$REMOVE_PACKAGES" \
-	"$DIST" "$VROOTDIR/$VHOST" "$MIRROR" ; then
-    echo "${0##*/}: error: debootstrap failure. Cannot continue."
+## use "vserver ... build" to build the new vserver
+if ! /usr/sbin/vserver "$VHOST" build -m debootstrap \
+       --rootdir "$VROOTDIR" --hostname "$VHOST" --interface "$INTERFACE:$IP" \
+       -- -d "$DIST" -m "$MIRROR" \
+       -- $ARCH_ARGUMENT \
+        --include="$INSTALL_PACKAGES" --exclude="$REMOVE_PACKAGES"
+  then
+    echo "${0##*/}: error: vserver-build failure. Cannot continue."
     exit 1
 fi
 
@@ -406,15 +369,8 @@
 
 EOF
 
-# Fix up the available device nodes, for security
+# Fix up the available device nodes (mostly done by vserver-build above)
 if cd "$VROOTDIR/$VHOST/dev"; then
-    mkdir -p /var/lib/vserver-debiantools
-    tar cfp /var/lib/vserver-debiantools/dev.tar.$$ full null ptmx random tty urandom zero
-    rm -rf *
-    tar xfp /var/lib/vserver-debiantools/dev.tar.$$
-    rm -f /var/lib/vserver-debiantools/dev.tar.$$
-    mkdir pts
-    mkdir shm
     ln -s /proc/self/fd fd
     ln -s fd/2 stderr
     ln -s fd/0 stdin
@@ -467,14 +423,6 @@
 proc		/proc		proc	defaults			0	0
 EOF
 
-# The new vserver patch now automatically mounts /proc
-# Debian needs /dev/pts mounting "gid=5,mode=620" by vserver
-cat << EOF > "$VROOTDIR/$VHOST/etc/mtab"
-/dev/hdv1 / vfs none 0 0
-proc /proc proc rw 0 0
-devpts /dev/pts devpts rw,gid=5,mode=620 0 0
-EOF
-
 # Create a reduced inittab that doesn't start getty on the consoles
 cat << EOF > "$VROOTDIR/$VHOST/etc/inittab"
 # /etc/inittab: init(8) configuration.
@@ -549,22 +497,6 @@
 
 EOF
 
-# Create default /etc/vservers entry
-cat << EOF > /etc/vservers/$VHOST.conf
-S_HOSTNAME="$VHOST"
-IPROOT="$IP"
-IPROOTDEV="$INTERFACE"
-ONBOOT="yes"
-S_NICE=""
-S_FLAGS="lock nproc$FAKEINIT"
-ULIMIT="-H -n 1024"
-S_CAPS="CAP_NET_RAW"
-
-# *NOT* DNS domain name, for NIS only
-S_DOMAINNAME=""
-
-EOF
-
 if [ -n "$EXTRA_PACKAGES" ]; then
     EXTRA_PACKAGES_INSTALL="apt-get --assume-yes install ${EXTRA_PACKAGES//,/ }"
 fi
@@ -601,6 +533,9 @@
 
 EOF
 
+## start vserver before we can exec anything inside it
+vserver $VHOST start
+
 # Run the above commands from within the server
 chmod 755 $VROOTDIR/$VHOST/vserver-config.sh
 vserver $VHOST exec /vserver-config.sh
@@ -622,30 +557,12 @@
     chmod 600 "$VROOTDIR/$VHOST/root/.ssh/authorized_keys"
 fi
 
-# Install the vreboot/rebootmgr utility--hopefully this will disappear soon
-VREBOOT_LOCATION="/usr/lib/util-vserver/vreboot"
-if [ "$COPY_VREBOOT" == "true" -a -x "$VREBOOT_LOCATION" ]; then
-    cp -a "$VREBOOT_LOCATION" "$VROOTDIR/$VHOST/usr/local/sbin/"
-    chmod 750 "$VROOTDIR/$VHOST/usr/local/sbin/vreboot"
-    # ln -s "$VROOTDIR/$VHOST/usr/local/sbin/"{vshutdown,vreboot}
-    # ln -s "$VROOTDIR/$VHOST/usr/local/sbin/"{vhalt,vreboot}
-fi
-
-# Stop all the processes that were started inside the server
-export PREVLEVEL=2
-vserver $VHOST exec /etc/init.d/rc 0
+## stop the vserver
 vserver $VHOST stop
 
-# Populate the archive for future virtual servers
-if [ ! -d $VROOTDIR/ARCHIVES/$DIST ]; then
-    mkdir -p $VROOTDIR/ARCHIVES/$DIST
-fi
-cp $VROOTDIR/$VHOST/var/cache/apt/archives/*.deb $VROOTDIR/ARCHIVES/$DIST
-
-echo "Restarting rebootmgr."
-invoke-rc.d rebootmgr restart
 echo
-echo "You should now adjust /etc/vservers/$VHOST.conf to suit your needs,"
+echo "You should now adjust the configuration in /etc/vservers/$VHOST/"
+echo "to suit your needs,"
 echo "or else just go ahead and type \`vserver $VHOST start' to start"
 echo "your new virtual server.  debian/rules!"
 echo