76 lines
2.2 KiB
Plaintext
76 lines
2.2 KiB
Plaintext
|
#!/bin/sh
|
||
|
|
||
|
#----------------------------------------------------------------------
|
||
|
# copyright (C) 2006 Mitel Networks Corporation
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation; either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
#
|
||
|
#----------------------------------------------------------------------
|
||
|
|
||
|
# Source function library.
|
||
|
SYSTEMCTL_SKIP_REDIRECT=1
|
||
|
. /etc/rc.d/init.d/functions
|
||
|
|
||
|
if [ $# -lt 1 ]; then
|
||
|
echo "Usage: $0 <start|restart>" 1>&2
|
||
|
exit 1
|
||
|
fi
|
||
|
# We should only do something if $1 is 'start'.
|
||
|
if [ $1 != "start" ] && [ $1 != "restart" ]; then
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
psql='/usr/pgsql-13/bin/psql'
|
||
|
createdb='/usr/pgsql-13/bin/createdb'
|
||
|
|
||
|
M="Waiting for postgresql to startup: ."
|
||
|
for i in $(seq 1 30)
|
||
|
do
|
||
|
if chpst -u postgres $psql -f - template1 < /dev/null 2>/dev/null
|
||
|
then
|
||
|
if [ "$M" = "." ]
|
||
|
then
|
||
|
echo
|
||
|
fi
|
||
|
exit_value=0
|
||
|
HOME=/root
|
||
|
export HOME
|
||
|
for link in $(find /etc/e-smith/pgsql/init -type f -o -type l | sort)
|
||
|
do
|
||
|
F=$(basename $link | sed s/S[0-9][0-9]//)
|
||
|
case $F in
|
||
|
*.sql)
|
||
|
D=$(echo $F | sed 's/\.sql$//')
|
||
|
action "Creating database $D in postgresql" chpst -u postgres $createdb -T template0 $D
|
||
|
action "Loading $F into postgresql" chpst -u postgres $psql $D < $link && /bin/rm $link
|
||
|
;;
|
||
|
*)
|
||
|
action "Loading $F into postgresql" chpst -u postgres $link && /bin/rm $link
|
||
|
;;
|
||
|
esac
|
||
|
# Record any failure for the final return value.
|
||
|
if [ $? -ne 0 ]; then
|
||
|
exit_value=1
|
||
|
fi
|
||
|
done
|
||
|
exit $exit_value
|
||
|
fi
|
||
|
echo -n $M
|
||
|
M=.
|
||
|
sleep 2
|
||
|
done
|
||
|
echo "Timed out waiting for postgresql to startup" >&2
|
||
|
exit 1
|