Skip to content

Commit 1a1d333

Browse files
committed
improved sql functions
1 parent cb99788 commit 1a1d333

File tree

2 files changed

+186
-354
lines changed

2 files changed

+186
-354
lines changed

bin/v-add-database-host

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ source $VESTA/conf/vesta.conf
3131
A4='******'
3232
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
3333

34+
is_mysql_host_alive() {
35+
mycnf=$(mktemp)
36+
echo "[client]">$mycnf
37+
echo "host='$HOST'" >> $mycnf
38+
echo "user='$USER'" >> $mycnf
39+
echo "password='$PASSWORD'" >> $mycnf
40+
chmod 600 $mycnf
41+
mysql --defaults-file=$mycnf -e 'SELECT VERSION()' >/dev/null 2>&1
42+
rm $mycnf
43+
if [ '0' -ne "$?" ]; then
44+
echo "Error: MySQL connection to $host failed"
45+
log_event "$E_CONNECT" "$EVENT"
46+
exit $E_CONNECT
47+
fi
48+
}
49+
50+
is_pgsql_host_alive() {
51+
export PGPASSWORD="$dbpass"
52+
psql -h $host -U $dbuser -c "SELECT VERSION()" > /dev/null 2>&1
53+
if [ '0' -ne "$?" ]; then
54+
echo "Error: PostgreSQL connection to $host failed"
55+
log_event "$E_CONNECT" "$EVENT"
56+
exit $E_CONNECT
57+
fi
58+
}
59+
3460

3561
#----------------------------------------------------------#
3662
# Verifications #

0 commit comments

Comments
 (0)