-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredeploy.sh
executable file
·108 lines (94 loc) · 2.53 KB
/
redeploy.sh
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
#!/bin/bash
#set -x
usage() {
printf "Usage: %s:\n
[-s nfs path to secondary storage <nfs-server:/export/path> ] [-u url to system template] [-h hypervisor type (kvm|xenserver|vmware) ]\n" $(basename $0) >&2
printf "\nThe -s flag will clean the secondary path and install the specified
hypervisor's system template as per -h, if -h is not given then xenserver is
assumed\n"
}
failed() {
exit $1
}
#flags
sflag=
hflag=
uflag=
VERSION="1.0.1"
echo "Redeploy Version: $VERSION"
#some defaults
spath='nfs2.lab.vmops.com:/export/home/bvt/secondary'
hypervisor='xenserver'
sysvmurl='http://download.cloud.com/templates/acton/acton-systemvm-02062012.vhd.bz2'
systemvm_seeder='/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt'
while getopts 'u:s:h:' OPTION
do
case $OPTION in
s) sflag=1
spath="$OPTARG"
;;
h) hflag=1
hypervisor="$OPTARG"
;;
u) uflag=1
sysvmurl="$OPTARG"
;;
?) usage
failed 2
;;
esac
done
if [[ -e /etc/redhat-release ]]
then
cat /etc/redhat-release
else
echo "script works on rpm environments only"
exit 5
fi
#check if process is running
proc=$(ps aux | grep cloud | wc -l)
if [[ $proc -lt 2 ]]
then
echo "Cloud process not running"
if [[ -e /var/run/cloud-management.pid ]]
then
rm -f /var/run/cloud-management.pid
fi
else
#stop service
service cloud-management stop
fi
#TODO: archive old logs
#refresh log state
cat /dev/null > /var/log/cloud/management/management-server.log
cat /dev/null > /var/log/cloud/management/api-server.log
cat /dev/null > /var/log/cloud/management/catalina.out
#replace disk size reqd to 1GB max
sed -i 's/DISKSPACE=5120000/DISKSPACE=20000/g' $systemvm_seeder
if [[ "$uflag" != "1" && "$hypervisor" != "xenserver" ]]
then
echo "URL of systemvm template is reqd."
usage
fi
if [[ "$sflag" == "1" ]]
then
mkdir -p /tmp/secondary
mount -t nfs $spath /tmp/secondary
rm -rf /tmp/secondary/*
if [[ "$hflag" == "1" && "$hypervisor" == "xenserver" ]]
then
bash -x $systemvm_seeder -m /tmp/secondary/ -u $sysvmurl -h xenserver
elif [[ "$hflag" == "1" && "$hypervisor" == "kvm" ]]
then
bash -x $systemvm_seeder -m /tmp/secondary/ -u $sysvmurl -h kvm
elif [[ "$hflag" == "1" && "$hypervisor" == "vmware" ]]
then
bash -x $systemvm_seeder -m /tmp/secondary/ -u $sysvmurl -h vmware
else
bash -x $systemvm_seeder -m /tmp/secondary/ -u $sysvmurl -h xenserver
fi
umount /tmp/secondary
else
echo "please provide the nfs secondary storage path where templates are stored"
usage
fi