330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
1 |
#!/bin/bash -e
|
2 |
#
|
|
3 |
# summary of how this script can be called:
|
|
4 |
# * <new-preinst> install
|
|
5 |
# * <new-preinst> install <old-version>
|
|
6 |
# * <new-preinst> upgrade <old-version>
|
|
7 |
# * <old-preinst> abort-upgrade <new-version>
|
|
8 |
#
|
|
9 |
||
10 |
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi |
|
11 |
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } |
|
12 |
||
13 |
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin |
|
14 |
||
15 |
# Try to stop the server in a sane way. If it does not success let the admin
|
|
16 |
# do it himself. No database directories should be removed while the server
|
|
17 |
# is running! Another mysqld in e.g. a different chroot is fine for us.
|
|
18 |
stop_server() { |
|
19 |
if [ ! -x /etc/init.d/mysql ]; then return; fi |
|
20 |
||
21 |
set +e
|
|
22 |
if [ -x /usr/sbin/invoke-rc.d ]; then |
|
23 |
cmd="invoke-rc.d mysql stop" |
|
24 |
else
|
|
25 |
cmd="/etc/init.d/mysql stop" |
|
26 |
fi
|
|
27 |
$cmd
|
|
28 |
errno=$? |
|
29 |
set -e
|
|
30 |
||
31 |
# 0=ok, 100=no init script (fresh install)
|
|
32 |
if [ "$errno" != 0 -a "$errno" != 100 ]; then |
|
33 |
echo "${cmd/ */} returned $errno" 1>&2 |
|
34 |
echo "There is a MySQL server running, but we failed in our attempts to stop it." 1>&2 |
|
35 |
echo "Stop it yourself and try again!" 1>&2 |
|
36 |
exit 1 |
|
37 |
fi
|
|
38 |
}
|
|
39 |
||
40 |
##### here's a bunch of helper functions for converting database formats ######
|
|
41 |
||
42 |
cvt_get_param(){
|
|
43 |
/usr/sbin/mysqld --print-defaults \
|
|
44 |
| tr " " "\n" \ |
|
45 |
| grep -- "--$1" \ |
|
46 |
| tail -n 1 \ |
|
47 |
| cut -d= -f2 |
|
48 |
}
|
|
49 |
||
50 |
cvt_setup_stuff(){
|
|
51 |
mytmp=`mktemp -d -t mysql-ISAM-convert.XXXXXX` |
|
333
by seanius
ISAM fix, part 3 |
52 |
cvt_log="$mytmp/conversion.log" |
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
53 |
if [ ! -d "$mytmp" ]; then |
54 |
echo "can't create temporary directory, oh well." >&2 |
|
55 |
exit 1 |
|
56 |
fi
|
|
57 |
||
58 |
chgrp mysql $mytmp
|
|
59 |
chmod g+rwx $mytmp
|
|
60 |
cvt_socket=${mytmp}/mysql.sock |
|
61 |
||
62 |
cvt_mysqld="mysqld --skip-grant-tables --skip-networking --socket $cvt_socket" |
|
63 |
cvt_mysql="mysql --socket $cvt_socket" |
|
64 |
cvt_mysqladmin="mysqladmin --socket $cvt_socket" |
|
65 |
}
|
|
66 |
||
67 |
cvt_get_databases(){
|
|
68 |
echo fetching database list ... >&2 |
|
69 |
$cvt_mysql -e 'show databases' | sed -n -e '2,$p' |
|
70 |
}
|
|
71 |
||
72 |
cvt_get_tables(){
|
|
73 |
echo querying tables in $1 ... >&2 |
|
74 |
$cvt_mysql $1 -e 'show table status' | sed -n -e '2,$p' | \ |
|
75 |
cut -f 1,2 | grep -w 'ISAM$' | cut -f 1 |
|
76 |
}
|
|
77 |
||
78 |
cvt_convert_table(){
|
|
79 |
echo converting $1.$2 ... >&2 |
|
80 |
$cvt_mysql $1 -e "alter table $2 type=MyISAM" |
|
81 |
}
|
|
82 |
||
83 |
cvt_wait_for_server(){
|
|
332
by seanius
ISAM trap fix, part 2 |
84 |
local count
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
85 |
echo -n waiting for server startup.. >&2 |
86 |
while ! $cvt_mysql </dev/null >/dev/null 2>&1; do |
|
87 |
echo -n . >&2 |
|
88 |
sleep 1
|
|
332
by seanius
ISAM trap fix, part 2 |
89 |
count=".$count" |
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
90 |
if [ -f $mytmp/mysql.done ]; then |
91 |
echo "sorry... looks like the server crashed :(" >&2 |
|
333
by seanius
ISAM fix, part 3 |
92 |
return 1 |
332
by seanius
ISAM trap fix, part 2 |
93 |
elif [ "$count" = "...................." ]; then |
94 |
echo "sorry... looks like the server didn't start :(" >&2 |
|
95 |
return 1 |
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
96 |
fi
|
97 |
done
|
|
98 |
echo ok. >&2 |
|
99 |
}
|
|
100 |
||
101 |
cvt_wait_for_exit(){
|
|
332
by seanius
ISAM trap fix, part 2 |
102 |
local count
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
103 |
echo -n waiting for server shutdown.. >&2 |
104 |
while [ ! -f $mytmp/mysql.done ]; do |
|
105 |
echo -n . >&2 |
|
106 |
sleep 1
|
|
332
by seanius
ISAM trap fix, part 2 |
107 |
count=".$count" |
108 |
if [ "$count" = "...................." ]; then |
|
109 |
echo "hrm... guess it never started?" >&2 |
|
110 |
return 0 |
|
111 |
fi
|
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
112 |
done
|
113 |
echo ok. >&2 |
|
114 |
}
|
|
115 |
||
116 |
cvt_cleanup(){
|
|
332
by seanius
ISAM trap fix, part 2 |
117 |
local mysql_kids
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
118 |
rm -rf $mytmp
|
332
by seanius
ISAM trap fix, part 2 |
119 |
# kill any mysqld child processes left over. there *shouldn't* be any,
|
120 |
# but let's not take chances with that
|
|
121 |
mysql_kids=`ps o 'pid command' --ppid $$ | grep -E '^[[:digit:]]+ mysqld ' | cut -d' ' -f1` |
|
122 |
if [ "$mysql_kids" ]; then |
|
123 |
echo "strange, some mysql processes left around. killing them now." >&2 |
|
124 |
kill $mysql_kids |
|
125 |
sleep 10
|
|
126 |
mysql_kids=`ps o 'pid command' --ppid $$ | grep -E '^[[:digit:]]+ mysqld ' | cut -d' ' -f1` |
|
127 |
if [ "$mysql_kids" ]; then |
|
128 |
echo "okay, they're really not getting the hint..." >&2 |
|
129 |
kill -9 $mysql_kids |
|
130 |
fi
|
|
131 |
fi
|
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
132 |
}
|
133 |
||
134 |
################################ main() ##########################
|
|
135 |
||
452
by ch
* As MySQL-5.0 is, at least currently, incompatible with Kernel 2.4 the |
136 |
# Check kernel version
|
137 |
if dpkg --compare-versions `uname -r` lt 2.6; then |
|
138 |
/bin/echo -e "\nPROBLEM: MySQL-5.x is currently incompatible with kernel 2.4. Aborting."; |
|
139 |
/bin/echo -e "See http://bugs.debian.org/416841 for more information.\n"
|
|
140 |
exit 1 |
|
141 |
fi
|
|
142 |
||
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
143 |
# to be sure
|
144 |
stop_server |
|
145 |
||
146 |
# test if upgrading from non conffile state
|
|
147 |
if [ "$1" = "upgrade" ] && [ -x /usr/sbin/mysqld ]; then |
|
148 |
cvt_datadir=`cvt_get_param datadir` |
|
149 |
# test for ISAM tables, which we must convert NOW
|
|
150 |
if [ -n "`find $cvt_datadir -name '*.ISM' 2>/dev/null`" ]; then |
|
332
by seanius
ISAM trap fix, part 2 |
151 |
set +e
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
152 |
cat << EOF >&2
|
153 |
----------------------------------------
|
|
154 |
WARNING WARNING WARNING
|
|
155 |
----------------------------------------
|
|
156 |
||
157 |
It has been detected that are are using ISAM format on some of your
|
|
158 |
mysql database tables. This format has been deprecated and no longer
|
|
159 |
supported. to prevent these databases from essentially disappearing,
|
|
160 |
an attempt at format conversion will now be made. please check after
|
|
161 |
your upgrade that all tables are present and accounted for.
|
|
162 |
||
163 |
apologies for the noise, but we thought you'd appreciate it :)
|
|
164 |
||
165 |
----------------------------------------
|
|
166 |
WARNING WARNING WARNING
|
|
167 |
----------------------------------------
|
|
168 |
EOF
|
|
169 |
cvt_setup_stuff |
|
333
by seanius
ISAM fix, part 3 |
170 |
($cvt_mysqld >$cvt_log 2>&1; touch $mytmp/mysql.done ) & |
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
171 |
|
332
by seanius
ISAM trap fix, part 2 |
172 |
if cvt_wait_for_server; then |
173 |
dbs=`cvt_get_databases` |
|
174 |
for db in $dbs; do |
|
175 |
tables=`cvt_get_tables $db` |
|
176 |
for tbl in $tables; do |
|
177 |
cvt_convert_table $db $tbl |
|
178 |
done
|
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
179 |
done
|
333
by seanius
ISAM fix, part 3 |
180 |
else
|
181 |
cvt_error="yes" |
|
332
by seanius
ISAM trap fix, part 2 |
182 |
fi
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
183 |
|
184 |
echo shutting down server... >&2 |
|
185 |
$cvt_mysqladmin shutdown
|
|
186 |
cvt_wait_for_exit |
|
187 |
echo "all done!" >&2 |
|
333
by seanius
ISAM fix, part 3 |
188 |
if [ ! "$cvt_error" = "yes" ]; then |
189 |
cvt_cleanup |
|
190 |
else
|
|
191 |
echo "you might want to look in $mytmp..." >&2 |
|
192 |
fi
|
|
332
by seanius
ISAM trap fix, part 2 |
193 |
|
194 |
set -e
|
|
330
by seanius
moving the 4.0 -> 5.0 ISAM conversion stuff to a new preinst for mysql-server |
195 |
fi
|
196 |
fi
|
|
197 |
||
198 |
exit 0 |