3 # Reinitialize contents of the database to pass new tests (using the backup made in from /root/dump)
5 # define some convenience functions
8 echo "select count(*) from users;" | su - postgres -c "psql $database" > /dev/null 2>&1
13 echo "Starting the database"
14 if type invoke-rc.d 2>/dev/null
16 invoke-rc.d postgresql start
18 service postgresql start
21 echo "Waiting for database to be up..."
23 while [ $i -lt 10 ] && ! is_db_up ; do
24 echo "...not yet ($(date))..."
31 echo "... FAIL: database still down?"
37 echo "Stopping the database"
38 if type invoke-rc.d 2>/dev/null
40 invoke-rc.d postgresql stop
42 service postgresql stop
45 echo "Waiting for database to be down..."
47 while [ $i -lt 10 ] && is_db_up ; do
48 echo "...not yet ($(date))..."
55 echo "... FAIL: database still up?"
61 echo "Starting apache"
62 if type invoke-rc.d 2>/dev/null
64 invoke-rc.d apache2 start
72 echo "Stopping apache"
73 if type invoke-rc.d 2>/dev/null
75 invoke-rc.d apache2 stop
81 # Now the main program
87 scriptdir=$(dirname $0)
88 if [ -d "$scriptdir/../../src" ]
90 UTILS_PATH=$(cd $scriptdir/../../src ; pwd)
92 UTILS_PATH=$(cd $scriptdir/../.. ; pwd)
94 export PATH=$PATH:$UTILS_PATH/utils:$UTILS_PATH/bin
95 if type forge_get_config
97 database=`FUSIONFORGE_NO_PLUGINS=true forge_get_config database_name`
99 echo "$0: FATAL ERROR : COULD NOT FIND forge_get_config"
103 if [ "x$database" = "x" ]
105 echo "Forge database name not found"
108 echo "Forge database is $database"
115 if [ -d /var/lib/postgresql ] ; then
116 dbdir=/var/lib/postgresql
117 elif [ -d /var/lib/pgsql ] ; then
120 echo "Database dir not found"
124 for i in arch bzr cvs darcs git hg svn ; do
125 repopath=`FUSIONFORGE_NO_PLUGINS=true forge_get_config repos_path scm$i`
126 if [ -d "$repopath" ] && ls $repopath | grep -q .. ; then
127 echo "Removing $i repositories"
132 # If the backup is there, restore it (it should now have been created by install.sh)
133 if [ -d $dbdir.backup ]; then
135 echo "Restore database from files backup ($dbdir.backup/)"
137 cp -a --reflink=auto $dbdir.backup $dbdir
140 # We will restore from the dump, then perform a backup so that it's there next time
144 # install.sh should have created it, if not, then nothing much we can do
147 echo "Dropping database $database"
148 su - postgres -c "dropdb -e $database"
150 echo "Restore database from dump file: psql -f- < /root/dump"
151 su - postgres -c "psql -f-" < /root/dump > /var/log/pg_restore.log 2>/var/log/pg_restore.err
153 # Perform a file backup which will now be faster to restore, next time (align with new install.sh behaviour)
155 echo "Perform files backup to $dbdir.backup/"
156 cp -a --reflink=auto $dbdir $dbdir.backup
159 # TODO: reinit the db from scratch and create the dump
160 echo "Couldn't restore the database: No /root/dump found"
169 echo "Flushing/restarting nscd"
170 nscd -i passwd && nscd -i group || true