Skip to content

Commit fa56b3f

Browse files
committed
Merge pull request #678 from remibergsma/sec-stor-script-mysql-default-port
Improve cloud-install-sys-tmplt to work in dev environment againThe script that you run to initially setup secondary storage, had some errors. As it now depends on /etc/cloudstack/management/db.properties, it did not work any more on my development environment. I defined some defaults that work in development environments (those are sane defaults anyway), then check if the /etc/cloudstack/management/db.properties file exists. If so, it reads from there and gets the vars just like before. If not, it keeps the defaults unless of course someone overrides them on the command line. While working on the script, I also fixed the indentation and found a query that was not yet using the -P mysql port variable. I tested it both on my development environment as well as in an environment installed from RPM (where you'd have /etc/cloudstack/management/db.properties and that both worked. PS @snuf please check if it also works again for you. * pr/678: clean-ups in the file this query had no -P port specified so did not work make sane defaults for MySQL settings Signed-off-by: Remi Bergsma <github@remi.nl>
2 parents f65dec4 + 2f858a7 commit fa56b3f

File tree

1 file changed

+65
-58
lines changed

1 file changed

+65
-58
lines changed

scripts/storage/secondary/cloud-install-sys-tmplt

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
# to you under the Apache License, Version 2.0 (the
99
# "License"); you may not use this file except in compliance
1010
# with the License. You may obtain a copy of the License at
11-
#
11+
#
1212
# http://www.apache.org/licenses/LICENSE-2.0
13-
#
13+
#
1414
# Unless required by applicable law or agreed to in writing,
1515
# software distributed under the License is distributed on an
1616
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -37,48 +37,49 @@ templateId=
3737
hyper=
3838
msKey=password
3939
DISKSPACE=2120000 #free disk space required in kilobytes
40-
dbHost=
41-
dbUser=
40+
dbHost="localhost"
41+
dbUser="root"
4242
dbPassword=
43-
dbPort=
43+
dbPort=3306
4444
jasypt='/usr/share/cloudstack-common/lib/jasypt-1.9.2.jar'
4545
while getopts 'm:h:f:u:Ft:e:s:o:r:d:p:'# OPTION
4646
do
4747
case $OPTION in
48-
m) mflag=1
49-
mntpoint="$OPTARG"
50-
;;
51-
f) fflag=1
52-
tmpltimg="$OPTARG"
53-
;;
54-
u) uflag=1
55-
url="$OPTARG"
56-
;;
57-
F) Fflag=1 ;;
48+
m) mflag=1
49+
mntpoint="$OPTARG"
50+
;;
51+
f) fflag=1
52+
tmpltimg="$OPTARG"
53+
;;
54+
u) uflag=1
55+
url="$OPTARG"
56+
;;
57+
F) Fflag=1
58+
;;
5859
t) templateId="$OPTARG"
59-
;;
60+
;;
6061
e) ext="$OPTARG"
61-
;;
62+
;;
6263
h) hyper="$OPTARG"
63-
;;
64+
;;
6465
s) sflag=1
65-
msKey="$OPTARG"
66-
;;
66+
msKey="$OPTARG"
67+
;;
6768
o) oflag=1
6869
dbHost="$OPTARG"
69-
;;
70+
;;
7071
r) rflag=1
7172
dbUser="$OPTARG"
72-
;;
73+
;;
7374
d) dflag=1
7475
dbPassword="$OPTARG"
75-
;;
76+
;;
7677
p) pflag=1
7778
dbPort="$OPTARG"
78-
;;
79-
?) usage
80-
failed 2
81-
;;
79+
;;
80+
?) usage
81+
failed 2
82+
;;
8283
esac
8384
done
8485

@@ -94,30 +95,35 @@ then
9495
failed 2
9596
fi
9697

97-
if [ ! -d $mntpoint ]
98+
if [ ! -d $mntpoint ]
9899
then
99100
echo "mount point $mntpoint doesn't exist\n"
100101
failed 4
101102
fi
102103

103-
if [[ "$fflag" == "1" && ! -f $tmpltimg ]]
104+
if [[ "$fflag" == "1" && ! -f $tmpltimg ]]
104105
then
105106
echo "template image file $tmpltimg doesn't exist"
106107
failed 3
107108
fi
108109

109-
if [ "$pflag" != 1 ]; then
110-
dbPort=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.port' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
111-
fi
110+
if [ -f /etc/cloudstack/management/db.properties ]
111+
then
112+
if [ "$pflag" != 1 ]
113+
then
114+
dbPort=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.port' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
115+
fi
112116

113-
if [ "$oflag" != 1 ]; then
114-
dbHost=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.host' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
115-
fi
116-
if [ "$rflag" != 1 ]; then
117-
dbUser=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.username' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
118-
fi
117+
if [ "$oflag" != 1 ]
118+
then
119+
dbHost=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.host' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
120+
fi
121+
122+
if [ "$rflag" != 1 ]
123+
then
124+
dbUser=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.username' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
125+
fi
119126

120-
if [ -f /etc/cloudstack/management/db.properties ]; then
121127
encType=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.encryption.type' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
122128
if [ "$encType" == "file" ]
123129
then
@@ -130,23 +136,24 @@ if [ -f /etc/cloudstack/management/db.properties ]; then
130136
failed 9
131137
fi
132138
fi
133-
fi
134139

135-
if [[ "$encType" == "file" || "$encType" == "web" ]]
136-
then
137-
encPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i | sed 's/^ENC(\(.*\))/\1/')
138-
if [ ! $encPassword == "" ]
139-
then
140-
dbPassword=(`java -classpath $jasypt org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI decrypt.sh input=$encPassword password=$msKey verbose=false`)
141-
if [ ! $dbPassword ]
142-
then
143-
echo "Failed to decrypt DB password from db.properties"
144-
failed 9
145-
fi
146-
fi
147-
else
148-
if [ "$dflag" != 1 ]; then
149-
dbPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i )
140+
if [[ "$encType" == "file" || "$encType" == "web" ]]
141+
then
142+
encPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i | sed 's/^ENC(\(.*\))/\1/')
143+
if [ ! $encPassword == "" ]
144+
then
145+
dbPassword=(`java -classpath $jasypt org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI decrypt.sh input=$encPassword password=$msKey verbose=false`)
146+
if [ ! $dbPassword ]
147+
then
148+
echo "Failed to decrypt DB password from db.properties"
149+
failed 9
150+
fi
151+
fi
152+
else
153+
if [ "$dflag" != 1 ]
154+
then
155+
dbPassword=$(sed '/^\#/d' /etc/cloudstack/management/db.properties | grep 'db.cloud.password' | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'i )
156+
fi
150157
fi
151158
fi
152159

@@ -184,14 +191,14 @@ fi
184191

185192
if [ ! $templateId ]
186193
then
187-
echo "Unable to get template Id from database"
188-
failed 8
194+
echo "Unable to get template Id from database"
195+
failed 8
189196
fi
190197

191198
_uuid=$(uuidgen)
192199
localfile=$_uuid.$ext
193200

194-
_res=(`mysql -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "update cloud.vm_template set uuid=\"$_uuid\", url=\"$url\" where id=\"$templateId\""`)
201+
_res=(`mysql -P $dbPort -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e "update cloud.vm_template set uuid=\"$_uuid\", url=\"$url\" where id=\"$templateId\""`)
195202

196203
mntpoint=`echo "$mntpoint" | sed 's|/*$||'`
197204

0 commit comments

Comments
 (0)