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

Last change on this file since 68 was 68, checked in by zerodeux, 12 years ago

(vcaron) we explicitly remove the vserver data, no need to ask userdel to do it again

  • 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
61if [ -z "$name" ]; then
62  help; exit 1
63fi
64#if [ ! -d /etc/vservers/"$name" ]; then
65#  error "vserver '$name' does not exist"
66#fi
67
68echo -n "About to wipe clean '$name' vserver. Are you sure (type 'yes') ? "
69read sure
70if [ "$sure" != "yes" ]; then
71  echo "Coward."
72  exit 1
73fi
74
75vserver $name stop
76
77umount /var/lib/vservers/$name/home
78umount /var/lib/vservers/$name
79lvremove -f /dev/vg-vservers/$name
80
81cd /etc
82cp -a fstab fstab-
83sed -ne '/\/'$name' /!p' <fstab >fstab.new
84mv -f fstab.new fstab
85
86rm -rf /etc/vservers/$name
87rm -rf /var/lib/vservers/$name
88
89userdel -f $name
90
91# Tear down MySQL accounts and databases
92#
93if mysql --version >/dev/null; then
94  cat <<EOF | mysql -f
95DROP DATABASE \`${name}_dev\`;
96DROP DATABASE \`${name}_prod\`;
97REVOKE ALL PRIVILEGES, GRANT OPTION FROM '$name'@'%';
98DROP USER '$name'@'%';
99EOF
100fi
Note: See TracBrowser for help on using the repository browser.