source: ror-farm/ror-farm-del @ 345

Last change on this file since 345 was 345, checked in by zecrazytux, 11 years ago

Fixed a shell warning at first 'rorette' creation
Take the first available LVM volume group instead of harcoding one

  • Property svn:executable set to *
File size: 2.3 KB
Line 
1#!/bin/sh
2
3# ror-farm-del (c) 2008 Bearstech - http://bearstech.com
4#
5# Depends: util-vserver vserver-debiantools lvm2 pwgen
6# Recommends: mysql-client
7
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21THIS_NAME=ror-farm-del
22THIS_VERSION=3
23
24# FIXME: lacks a lot of sanity checks, lots of command errors (but really wipes clean...)
25# FIXME: clearly prints what's wiped (files, db, ...)
26
27
28help() {
29  cat << EOF
30Usage: $THIS_NAME vserver
31
32Stops and wipes a vserver instance. DANGEROUS.
33EOF
34}
35
36version() {
37  echo "$THIS_NAME $THIS_VERSION"
38}
39
40error() {
41  echo "$THIS_NAME: error: $*"
42  exit 1
43}
44
45
46# Parse args
47#
48parse_opt=run
49while [ $parse_opt != "done"  ] ; do
50  case "$1" in
51    --help|-h)     shift; help; exit 0;;
52    --version|-v)  shift; version; exit 0;;
53
54    --)            shift; parse_opt=done;;
55    -*)            echo "$THIS_NAME: unknown option '$1'"; exit 1;;
56    *)             parse_opt=done;;
57  esac
58done
59name="$1"; shift
60
61vgname=$(vgs --noheadings | awk '{ print $1 }' | head -1)
62
63if [ -z "$name" ]; then
64  help; exit 1
65fi
66#if [ ! -d /etc/vservers/"$name" ]; then
67#  error "vserver '$name' does not exist"
68#fi
69
70echo -n "About to wipe clean '$name' vserver. Are you sure (type 'yes') ? "
71read sure
72if [ "$sure" != "yes" ]; then
73  echo "Coward."
74  exit 1
75fi
76
77vserver $name stop
78
79umount /var/lib/vservers/$name/home
80umount /var/lib/vservers/$name
81lvremove -f /dev/$vgname/$name
82
83cd /etc
84cp -a fstab fstab-
85sed -ne '/\/'$name' /!p' <fstab >fstab.new
86mv -f fstab.new fstab
87
88rm -rf /etc/vservers/$name
89rm -rf /var/lib/vservers/$name
90
91userdel -f $name
92
93# Tear down MySQL accounts and databases
94#
95if mysql --version >/dev/null; then
96  cat <<EOF | mysql -f
97DROP DATABASE \`${name}_dev\`;
98DROP DATABASE \`${name}_prod\`;
99REVOKE ALL PRIVILEGES, GRANT OPTION FROM '$name'@'%';
100DROP USER '$name'@'%';
101EOF
102fi
Note: See TracBrowser for help on using the repository browser.