Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos
Commits
bfc1cf0d
Commit
bfc1cf0d
authored
Dec 02, 2022
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
peertube: fixup
parent
bd07933a
Pipeline
#25147
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
1 deletion
+92
-1
software/peertube/buildout.hash.cfg
software/peertube/buildout.hash.cfg
+1
-1
software/peertube/template-peertube-restore.sh.in
software/peertube/template-peertube-restore.sh.in
+91
-0
No files found.
software/peertube/buildout.hash.cfg
View file @
bfc1cf0d
...
...
@@ -54,4 +54,4 @@ md5sum = 58d1a4fe246169dea94d7d243b4bac9e
[template-peertube-restore-script]
filename = template-peertube-restore.sh.in
md5sum =
bb2ae3ff8d94b38c793b50dc27d33049
md5sum =
0e8e0380887083b0dbb81ffa4016b431
software/peertube/template-peertube-restore.sh.in
View file @
bfc1cf0d
...
...
@@ -9,3 +9,94 @@
# Depending on the output, it will create a file containing
# the status of the restoration (success or failure)
die() {
echo "$*" 1>&2
exit 1
}
pg_version=$${postgresql:pgdata-directory}/PG_VERSION
echo "Check postgresql data directory is ready"
tpgwait=60
while ! [ -e "$pg_version" ]; do
tpgwait=$(( $tpgwait - 1 ))
test $tpgwait = 0 && die "PGdata directory not ready"
echo "I: PGdata directory is not ready (yet ?); will retry $tpgwait times..." 1>&2
sleep 1
done
echo "Postgresql data directory is ready"
# 2. Make sure the postgresql process is not running.
# Quote from the postgresql doc:
# > 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
if [ -e "$pid_file" ]; then
echo "Postgresql is running, this should not happened, aborting."
exit 1
fi
echo "Starting postgresql..."
$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory} &
postgresql_pid=$!
trap "kill $postgresql_pid" EXIT TERM INT
sleep 30
# If postgres has stopped, abort
if ! [ -d /proc/$postgresql_pid ]; then
echo "postgresql exited, aborting."
exit 1
fi
tpgwait=60
while ! [ -e "$pid_file" ]; do
tpgwait=$(( $tpgwait - 1 ))
test $tpgwait = 0 && die "Can not create pid_file"
echo "pid_file not exist; will retry $tpgwait times..." 1>&2
sleep 1
done
# run psql
psql() {
$${postgresql:bin}/psql \
-h $${postgresql:pgdata-directory} \
-U $${postgresql:superuser} \
-d $${postgresql:dbname} \
"$@"
}
echo "Ready to check postgresql is running..."
# initial db setup
# ( first quering PG several times waiting a bit till postgresql is started and ready )
tpgwait=10
while true; do
pgtables="$(psql -c '\d' 2>&1)" && break
tpgwait=$(( $tpgwait - 1 ))
test $tpgwait = 0 && die "pg query problem"
echo "I: PostgreSQL is not ready (yet ?); will retry $tpgwait times..." 1>&2
sleep 1
done
echo "I: PostgreSQL ready." 1>&2
# sleep 5
echo "Check postgresql is running again"
# Check the postgresql is running, if postgresql has stopped, abort
if ! [ -e "$pid_file" ]; then
echo "postgresql exited, aborting."
exit 1
fi
echo "Postgresql is running, ready to restore"
# 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 || {
RESTORE_EXIT_CODE=$?
echo 'Backup restoration failed.'
exit $RESTORE_EXIT_CODE
}
echo "Postgresql restore finished"
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment