This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
publik-bi/3m/cron.sh

28 lines
706 B
Bash
Executable File

#!/bin/bash
set -x -e
cd ~/publik-bi/3m/
export PLATFORM=${PLATFORM:-prod}
DB=auquotidien-bi
TEMPDB=$DB-temp
TEMP_DUMP=`tempfile`
trap "rm -f $TEMP_DUMP" INT TERM EXIT
dropdb $TEMPDB || true
createdb $TEMPDB
pg_dump -Oc auquotidien >$TEMP_DUMP
psql $TEMPDB -f $TEMP_DUMP
psql $TEMPDB -f 3m_$PLATFORM.sql
# minimize downtime
/sbin/start-stop-daemon --stop --pidfile slicer-$PLATFORM.pid --oknodo --retry 5
psql -c "ALTER DATABASE \"$DB\" RENAME TO \"$DB-old\"" auquotidien
psql -c "ALTER DATABASE \"$TEMPDB\" RENAME TO \"$DB\"" auquotidien
/sbin/start-stop-daemon --start --background --make-pidfile \
--pidfile slicer-$PLATFORM.pid --oknodo --startas ./run-slicer.sh \
--chdir .
dropdb $DB-old