forked from rposudnevskiy/RBDSR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_cn.sh
executable file
·191 lines (165 loc) · 5.5 KB
/
install_cn.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
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
#!/bin/bash
DEFAULT_CEPH_VERSION="jewel"
CEPH_REPO="mirrors.163.com\/ceph"
# Usage: installRepo <ceph-version>
function installRepo {
echo "Install the release.asc key"
rpm --import 'https://download.ceph.com/keys/release.asc'
echo "Install new Repos"
cp -n repos/ceph-$1.repo /etc/yum.repos.d/
sed -i "s/download.ceph.com/$CEPH_REPO/g" /etc/yum.repos.d/ceph-$1.repo
}
function deinstallRepo {
echo "deinstallRepo $1"
rm -f /etc/yum.repos.d/ceph-$1.repo
}
# Usage: removeRepo <ceph-version>
function removeRepo {
rm -f /etc/yum.repos.d/
}
# Usage: setReposEnabled <repo filename> <section name> <0|1>
function setReposEnabled {
echo "Set $1 $2 enabled = $3"
sed -ie "/\[$2\]/,/^\[/s/enabled=[01]/enabled=$3/" /etc/yum.repos.d/$1
}
# Usage: backupFile <path>
function backupFile {
echo "Backing Up file $1"
if [ -e $1-orig ]; then
echo "$1-orig already in place, not backing up!"
else
mv $1 $1-orig
fi
}
# Usage: restoreFile <path>
function restoreFile {
echo "Backing Up file $1"
if [ -e $1-orig ]; then
mv $1 $1-orig
else
echo "No $1-orig in place, not restoring!"
fi
}
# Usage: copyFile <source path> <destination path>
function copyFile {
cp $1 $2
chmod +x $2
}
function enableRBDSR {
echo "Add RBDSR plugin to whitelist of SM plugins in /etc/xapi.conf"
grep "sm-plugins" /etc/xapi.conf
grep "sm-plugins" /etc/xapi.conf | grep -q "rbd" || sed -ie 's/sm-plugins\(.*\)/& rbd/g' /etc/xapi.conf
grep "sm-plugins" /etc/xapi.conf | grep "rbd"
}
function disableRBDSR {
echo "Remove RBDSR plugin to whitelist of SM plugins in /etc/xapi.conf"
grep "sm-plugins" /etc/xapi.conf
grep "sm-plugins" /etc/xapi.conf | grep -q "rbd" || sed -ie 's/\(sm-plugins\)\(.*\)rbd\(.*\)/\1\2\3/g' /etc/xapi.conf
grep "sm-plugins" /etc/xapi.conf | grep "rbd"
}
function installEpel {
echo "Install Required Packages"
yum install -y epel-release yum-plugin-priorities.noarch --enablerepo=base,extras --releasever=7
}
function installCeph {
echo "Install RBDSR depenencies"
yum install -y snappy leveldb gdisk python-argparse gperftools-libs fuse fuse-libs ceph-common rbd-fuse rbd-nbd --enablerepo=base,extras --releasever=7
}
function installFiles {
echo "Install RBDSR Files"
copyFile "bins/waitdmmerging.sh" "/usr/bin/waitdmmerging.sh"
copyFile "bins/ceph_plugin.py" "/etc/xapi.d/plugins/ceph_plugin"
copyFile "bins/RBDSR.py" "/opt/xensource/sm/RBDSR.py"
copyFile "bins/rbdsr_vhd.py" "/opt/xensource/sm/rbdsr_vhd.py"
copyFile "bins/rbdsr_dmp.py" "/opt/xensource/sm/rbdsr_dmp.py"
copyFile "bins/rbdsr_rbd.py" "/opt/xensource/sm/rbdsr_rbd.py"
copyFile "bins/rbdsr_common.py" "/opt/xensource/sm/rbdsr_common.py"
copyFile "bins/rbdsr_lock.py" "/opt/xensource/sm/rbdsr_lock.py"
copyFile "bins/cleanup.py" "/opt/xensource/sm/cleanup.py"
copyFile "bins/tap-ctl" "/sbin/tap-ctl"
copyFile "bins/vhd-tool" "/bin/vhd-tool"
copyFile "bins/sparse_dd" "/usr/libexec/xapi/sparse_dd"
copyFile "bins/rbd2vhd.py" "/bin/rbd2vhd"
ln "/bin/rbd2vhd" "/bin/vhd2rbd"
ln "/bin/rbd2vhd" "/bin/rbd2raw"
ln "/bin/rbd2vhd" "/bin/rbd2nbd"
ln -s "/opt/xensource/sm/RBDSR.py" "/opt/xensource/sm/RBDSR"
}
function removeFiles {
echo "Removing RBDSR Files"
rm -f "/usr/bin/waitdmmerging.sh"
rm -f "/etc/xapi.d/plugins/ceph_plugin"
rm -f "/opt/xensource/sm/RBDSR"
rm -f "/opt/xensource/sm/rbdsr_vhd.py"
rm -f "/opt/xensource/sm/rbdsr_dmp.py"
rm -f "/opt/xensource/sm/rbdsr_rbd.py"
rm -f "/opt/xensource/sm/rbdsr_common.py"
rm -f "/opt/xensource/sm/rbdsr_lock.py"
rm -f "/opt/xensource/sm/cleanup.py"
rm -f "/sbin/tap-ctl"
rm -f "/bin/vhd-tool"
rm -f "/usr/libexec/xapi/sparse_dd"
rm -f "/bin/rbd2vhd"
rm -f "/bin/vhd2rbd"
rm -f "/bin/rbd2raw"
rm -f "/bin/rbd2nbd"
}
function install {
installRepo $1
installEpel
installCeph
backupFile "/sbin/tap-ctl"
backupFile "/bin/vhd-tool"
backupFile "/usr/libexec/xapi/sparse_dd"
backupFile "/opt/xensource/sm/cleanup.py"
installFiles
enableRBDSR
}
function deinstall {
disableRBDSR
removeFiles
restoreFile "/sbin/tap-ctl"
restoreFile "/bin/vhd-tool"
restoreFile "/usr/libexec/xapi/sparse_dd"
restoreFile "/opt/xensource/sm/cleanup.py"
deinstallRepo $1
}
case $1 in
update)
yum update -y ceph-common rbd-fuse rbd-nbd --enablerepo=base,extras --releasever=7
;;
install)
if [ -z "$2" ]; then
install $DEFAULT_CEPH_VERSION
else
if [ -z `echo $2|egrep "^jewel$|^kraken$|^luminous$"` ]; then
echo "[ERROR]: Unsupported Ceph version specified '$2'"
exit 1
else
install $2
fi
fi
;;
deinstall)
CEPH_INSTALLED_VERSION = `ls -1 | grep ceph | awk 'match($0, /ceph-(.*).repo/, a) {print a[1]}'`
if [ -z "$CEPH_INSTALLED_VERSION" ]; then
echo "[ERROR]: Can't determine installed version of Ceph."
echo " RBDSR plugin is not installed or corrupted."
exit 2
fi
if [ -z "$2" ]; then
deinstall $CEPH_INSTALLED_VERSION
else
if [ "$2" != "$CEPH_INSTALLED_VERSION" ]; then
echo "[ERROR]: Installed version of Ceph is '$CEPH_INSTALLED_VERSION'"
exit 3
else
deinstall $2
fi
fi
;;
*)
echo "Usage: $0 install|deinstall|update [jewel|kraken|luminous]"
exit 1
;;
esac