Skip to content

Commit

Permalink
Correctly handle upgrading from a crashed grain.
Browse files Browse the repository at this point in the history
MySQL can't recover its storage *and* upgrade in the same step, so we
need to include MySQL 5.5 for grains which were shut down uncleanly
before upgrade. A user who hit this reported it on sandstorm-dev. See
also:

    sandstorm-io/vagrant-spk#276
  • Loading branch information
zenhack committed Aug 13, 2020
1 parent 3c5dbb5 commit e0f6196
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 10 deletions.
20 changes: 20 additions & 0 deletions .sandstorm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

set -euo pipefail

# Install mysql 5.5 from nix, for upgrading old grains:
if [ ! -d /nix/store ]; then
sh <(curl -L https://nixos.org/nix/install) --no-daemon
fi
. /home/vagrant/.nix-profile/etc/profile.d/nix.sh
cd /home/vagrant
if [ ! -d nixpkgs ]; then
git clone https://github.com/nixos/nixpkgs
cd nixpkgs
git checkout 880bc93fc0ad44ea5b973e532c338afeb70d2a71
fi
sudo ln -sf \
$(nix-shell \
-p mysql55 \
-I nixpkgs=$HOME/nixpkgs \
--command 'dirname $(dirname $(which mysqlcheck))' \
) \
/usr/local/mysql55


cd /opt/app/.sandstorm/powerbox-http-proxy
go build
npm install
Expand Down
33 changes: 25 additions & 8 deletions .sandstorm/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -euo pipefail

mysql_socket=/var/run/mysqld/mysqld.sock

wait_for() {
local service=$1
local file=$2
Expand Down Expand Up @@ -42,19 +44,34 @@ mkdir -p /var/run/mysqld
# HOME=/etc/mysql /usr/bin/mysql_install_db
HOME=/etc/mysql /usr/sbin/mysqld --initialize || true

if [ -d /var/lib/php5 ]; then
# We're updating from a grain that was using MySQL 5.5 (and php5).
# If that grain was shut down improperly then trying to recover
# with MySQL 5.7 will fail; use the old programs to repair the
# db if needed:
HOME=/etc/mysql /usr/local/mysql55/bin/mysqld --skip-grant-tables &
mysql_pid="$!"
wait_for mysql55 $mysql_socket
HOME=/etc/mysql /usr/local/mysql55/bin/mysqlcheck \
--socket $mysql_socket \
--all-databases \
--auto-repair
kill $mysql_pid
wait $mysql_pid

# This also means we're upgrading from an old version of the app, from before we were
# using the .db-created sentinel file; create it, so the rest of the script correctly
# treats this as a pre-existing grain.
touch /var/.db-created
rm -rf /var/lib/php5
fi

# Spawn mysqld
HOME=/etc/mysql /usr/sbin/mysqld --skip-grant-tables &

# Wait until mysql has bound its socket, indicating readiness
wait_for mysql /var/run/mysqld/mysqld.sock
wait_for mysql $mysql_socket

if [ -d /var/lib/php5 ] ; then
# This means we're upgrading from an old version of the app, before we were using
# the .db-created sentinel file; create it, so the rest of the script correctly
# treats this as a pre-existing grain.
touch /var/.db-created
rm -rf /var/lib/php5
fi
if [ ! -e /var/.db-created ]; then
mysql --user "$MYSQL_USER" -e "CREATE DATABASE $MYSQL_DATABASE"
mysql --user "$MYSQL_USER" --database "$MYSQL_DATABASE" < /opt/app/schema/ttrss_schema_mysql.sql
Expand Down
2 changes: 1 addition & 1 deletion .sandstorm/rootfs/opt/app/version_static.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.13.0
1.13.0-1
32 changes: 32 additions & 0 deletions .sandstorm/sandstorm-files.list
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,37 @@ lib/x86_64-linux-gnu/libtinfo.so.5.9
lib/x86_64-linux-gnu/libz.so.1
lib/x86_64-linux-gnu/libz.so.1.2.8
lib64/ld-linux-x86-64.so.2
nix/store/3kljr53j4w0sszhkjdlswdsginr273vl-mysql-5.5.62/bin/mysqlcheck
nix/store/3kljr53j4w0sszhkjdlswdsginr273vl-mysql-5.5.62/bin/mysqld
nix/store/3kljr53j4w0sszhkjdlswdsginr273vl-mysql-5.5.62/share/mysql/charsets/Index.xml
nix/store/3kljr53j4w0sszhkjdlswdsginr273vl-mysql-5.5.62/share/mysql/english/errmsg.sys
nix/store/c7hj2bk4aqgpb3q0h5xhq7lag0lq3jm7-gcc-7.4.0-lib/lib/libstdc++.so.6
nix/store/c7hj2bk4aqgpb3q0h5xhq7lag0lq3jm7-gcc-7.4.0-lib/lib/libstdc++.so.6.0.24
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/ld-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/ld-linux-x86-64.so.2
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libc-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libc.so.6
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libcrypt-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libcrypt.so.1
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libdl-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libdl.so.2
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libgcc_s.so.1
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libm-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libm.so.6
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnsl-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnsl.so.1
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnss_compat-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnss_compat.so.2
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnss_files-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnss_files.so.2
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnss_nis-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libnss_nis.so.2
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libpthread-2.27.so
nix/store/g2p6fwjc995jrq3d8vph7k45l9zhdf8f-glibc-2.27/lib/libpthread.so.0
nix/store/k41bs9s7azs5gcyp5q20jdplz7cgmjlv-openssl-1.0.2s/lib/libcrypto.so.1.0.0
nix/store/k41bs9s7azs5gcyp5q20jdplz7cgmjlv-openssl-1.0.2s/lib/libssl.so.1.0.0
nix/store/kgh9da41mpy9rlvcn9iglkykcn90cm37-zlib-1.2.11/lib/libz.so.1
nix/store/kgh9da41mpy9rlvcn9iglkykcn90cm37-zlib-1.2.11/lib/libz.so.1.2.11
opt/app/.sandstorm/apphooks/ttrss-apphooks
opt/app/.sandstorm/launcher.sh
opt/app/.sandstorm/powerbox-http-proxy/build/index.js
Expand Down Expand Up @@ -486,6 +517,7 @@ usr/lib/x86_64-linux-gnu/libxml2.so.2
usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4
usr/lib/x86_64-linux-gnu/libxslt.so.1
usr/lib/x86_64-linux-gnu/libxslt.so.1.1.29
usr/local/mysql55
usr/sbin/mysqld
usr/sbin/nginx
usr/sbin/php-fpm7.0
Expand Down
2 changes: 1 addition & 1 deletion .sandstorm/sandstorm-pkgdef.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const pkgdef :Spk.PackageDefinition = (
# about your app.
appTitle = (defaultText = "Tiny Tiny RSS"),

appVersion = 15, # Increment this for every release.
appVersion = 16, # Increment this for every release.

# This is stored in a text file that ttrss itself reads the version
# from; we use `embed` to avoid duplication here.
Expand Down

0 comments on commit e0f6196

Please sign in to comment.