Commit 5bbac948 authored by Boxiang Sun's avatar Boxiang Sun

peertube: restore script improvement

parent 0f241a41
...@@ -54,4 +54,4 @@ md5sum = 58d1a4fe246169dea94d7d243b4bac9e ...@@ -54,4 +54,4 @@ md5sum = 58d1a4fe246169dea94d7d243b4bac9e
[template-peertube-restore-script] [template-peertube-restore-script]
filename = template-peertube-restore.sh.in filename = template-peertube-restore.sh.in
md5sum = da2564f97a74674e700880c005106720 md5sum = 4cc9853025c2bf45b35ca14d5182b15b
...@@ -26,13 +26,20 @@ while ! [ -e "$pg_version" ]; do ...@@ -26,13 +26,20 @@ while ! [ -e "$pg_version" ]; do
sleep 1 sleep 1
done done
# # 2. # 2. Make sure the postgresql process is not running.
echo "Starting postgresql..." # Quote from the postgresql doc:
# > While the server is running, its PID is stored in the file postmaster.pid in the data directory.
$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory} & # https://www.postgresql.org/docs/current/server-start.html
# which means if the postmaster.pid exist, then the postgresql is running.
postgres_pid=$! pid_file=$${postgresql:pgdata-directory}/postmaster.pid
echo $postgres_pid if [ -e "$pid_file" ]; then
echo "postgresql is running, continue."
else
echo "Starting postgresql..."
$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory} &
postgres_pid=$!
echo $postgres_pid
fi
# run psql # run psql
psql() { psql() {
...@@ -57,17 +64,14 @@ echo "I: PostgreSQL ready." 1>&2 ...@@ -57,17 +64,14 @@ echo "I: PostgreSQL ready." 1>&2
sleep 5 sleep 5
# Check the postgresql is running, if postgresql has stopped, abort # Check the postgresql is running, if postgresql has stopped, abort
# > While the server is running, its PID is stored in the file postmaster.pid in the data directory.
# https://www.postgresql.org/docs/current/server-start.html
# which means if the postmaster.pid exist, then the postgresql is running.
pid_file=$${postgresql:pgdata-directory}/postmaster.pid pid_file=$${postgresql:pgdata-directory}/postmaster.pid
if ! [ -e "$pid_file" ]; then if ! [ -e "$pid_file" ]; then
echo "postgresql exited, aborting." echo "postgresql exited, aborting."
exit 1 exit 1
fi fi
# Restore the database
$${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} -U peertube -e -c -C -d postgres $${directory:srv}/backup/peertube_prod-dump.db $${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} -U peertube -e -c -C -d postgres $${directory:srv}/backup/peertube_prod-dump.db
pg_restore_pid=$! pg_restore_pid=$!
...@@ -76,10 +80,9 @@ wait $PID ...@@ -76,10 +80,9 @@ wait $PID
echo 'Backup restoration successfully completed.' echo 'Backup restoration successfully completed.'
# Allow slapos node instance to start the postgresql service # The database process should be stopped to allow
kill $postgres_pid #"slapos node instance" to starts the real postgresql service
if [ -e "$pid_file" ]; then if [ -e "$pid_file" ]; then
echo "postgresql exited, aborting." echo "Stoping postgresql..."
rm $pid_file pkill -9 -f "$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory}"
fi fi
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment