mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-03-01 00:59:23 +01:00
* fix missing dependencies * LNBits SQLite to PostgreSQL migration (#3411) * LNBits SQLite to PostgreSQL migration New installations with PostgreSQL configuration, existent data with SQLite. convert script needs a full start of LNBits prior migrating the old sqlite db's. User can migrate from raspiblitz menu. * only fix postgres if it needs to check for symbolik link of postgres default directory or desired postgres folder btcpayserver and lnbits could use postgresql new script to install or uninstall postgresql * fix typos * silent apt remove * fix removed function postgresConfig call bonus.postgresql.sh to setup PostgreSQL * Support outdated installation old installations should upgrade to new tag first create new data directory /mnt/hdd/app-data/LNBits/data * Improve migration Make it a bit more user friendly and prepare for a worst case to revert the migration if something fails unexpectedly make use of sync method for preparation * Rework migration workflow Cant wait for lnbits to start when ExecStartPre is used. We need a full start of lnbits prior migration, so make use of lsof to check for ports and wait. dont forget to start postgres service after installation. dont forget to stop postgres after uninstall * Dont overwrite the backup file if we start migrate again, the sqlite backup should not be overwritten with postgres data. Keep the backup file. * add migrate message to menu add the hint to revert migration manually after migrate script executed * fix install and data directory lnbits always needs a data directory * clean up lnbits settings for migration even if postgresql is already running, we can extract sqlite backup and start migrate remove migrateMsg duplicate * preserve database for reflash drop database only for migrate, not for regular installations * set blitz config for LNBits fix drop database only for migrate, not for regular installations * Add confirmation dialog and automatic revert User needs to confirm the process, this will eliminate missclicks add a migrate revert function to automatically revert if something unexpected happens let the user call the function manually * check conv.py on success or revert if the conversion script fails, revert automatically * Improve revert message Do not print the revert hint message if current database is SQLite * fix read config LNBitsDB * fix unpack backup Folder LNBits should never block the restore of backup. Happened after multiple migrations and revert. * Wait for lnbits v0.9.5 Set commit version with fix for postgresql database and BIGINT for amounts for migrate Can be set to v0.9.5 tag or above later * improve migrate backup handling revert to the current backup and not to the previous backup. No need for the failed folder state user message with backup file path * check psql version once * supress expected errors if database exists Co-authored-by: /rootzoll <christian@geektank.de> * fix error output on status Co-authored-by: ChuckNorrison <2964146+ChuckNorrison@users.noreply.github.com>
93 lines
2.6 KiB
Bash
Executable file
93 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# command info
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
|
echo "config script to install PostgreSQL"
|
|
echo "bonus.postgresql.sh [on|off]"
|
|
exit 1
|
|
fi
|
|
|
|
# switch on
|
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|
# https://github.com/rootzoll/raspiblitz/issues/3218
|
|
echo "# Install PostgreSQL"
|
|
|
|
sudo apt install -y postgresql
|
|
postgres_datadir="/var/lib/postgresql" # default data dir
|
|
|
|
# sudo -u postgres psql -c "show data_directory"
|
|
# /var/lib/postgresql/13/main
|
|
if [ ! -d $postgres_datadir ]; then
|
|
echo "# Create PostgreSQL data"
|
|
sudo mkdir -p $postgres_datadir/13/main
|
|
sudo chown -R postgres:postgres $postgres_datadir
|
|
# sudo pg_dropcluster 13 main
|
|
sudo pg_createcluster 13 main --start
|
|
fi
|
|
|
|
fix_postgres=0
|
|
if [ -L $postgres_datadir ] ; then
|
|
if [ -e $postgres_datadir ] ; then
|
|
echo "# Good link in $postgres_datadir"
|
|
else
|
|
echo "# Broken link in $postgres_datadir"
|
|
fix_postgres=1
|
|
fi
|
|
elif [ -e $postgres_datadir ] ; then
|
|
echo "# Not a link in $postgres_datadir"
|
|
fix_postgres=1
|
|
else
|
|
echo "# Missing Link in $postgres_datadir"
|
|
fix_postgres=1
|
|
fi
|
|
|
|
if [ fix_postgres = 1 ] || [ ! -d /mnt/hdd/app-data/postgresql ]; then
|
|
echo "# Move the PostgreSQL data to /mnt/hdd/app-data/postgresql"
|
|
sudo systemctl stop postgresql 2>/dev/null
|
|
sudo rsync -av $postgres_datadir /mnt/hdd/app-data
|
|
sudo mv $postgres_datadir /var/lib/postgresql.bak
|
|
sudo rm -rf $postgres_datadir # not a symlink.. delete it silently
|
|
sudo ln -s /mnt/hdd/app-data/postgresql /var/lib/
|
|
fi
|
|
sudo systemctl enable postgresql
|
|
sudo systemctl start postgresql
|
|
|
|
# check if PostgreSQL was installed
|
|
if psql --version; then
|
|
# wait for the postgres server to start
|
|
count=0
|
|
count_max=30
|
|
while ! nc -zv 127.0.0.1 5432 2>/dev/null;
|
|
do
|
|
count=`expr $count + 1`
|
|
echo "sleep $count/$count_max"
|
|
sleep 1
|
|
if [ $count = $count_max ]; then
|
|
sudo systemctl status postgresql
|
|
echo "FAIL - Was not able to start PostgreSQL service"
|
|
exit 1
|
|
fi
|
|
done
|
|
echo "OK PostgreSQL installed"
|
|
else
|
|
echo "FAIL - Was not able to install PostgreSQL"
|
|
echo "ABORT - PostgreSQL install"
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|
|
fi
|
|
|
|
# switch off
|
|
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
|
# setting value in raspiblitz config
|
|
echo "*** REMOVING POSTGRESQL ***"
|
|
sudo apt remove -y postgresql
|
|
sudo systemctl stop postgresql 2>/dev/null
|
|
sudo systemctl disable postgresql
|
|
echo "OK PostgreSQL removed."
|
|
exit 0
|
|
fi
|
|
|
|
echo "FAIL - Unknown Parameter $1"
|
|
exit 1
|