Skip to content

Commit

Permalink
[misc] Fixes owtf#668, owtf#669
Browse files Browse the repository at this point in the history
- Now postgres service will restart only if user inputs "y"
- The fix uses `SHOW config_file;` to get the path for the
  postgres config file
  • Loading branch information
viyatb authored and DePierre committed Apr 21, 2016
1 parent 72da8a3 commit 5b9c333
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions scripts/db_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,37 @@ fi
postgresql_fix() {
# remove SSL=true from the postgresql main config
postgres_version="$(psql --version 2>&1 | tail -1 | awk '{print $3}' | sed 's/\./ /g' | awk '{print $1 "." $2}')"

postgres_conf="/etc/postgresql/$postgres_version/main/postgresql.conf"
postgres_conf="$(echo 'SHOW config_file;' | sudo -u postgres psql | grep 'postgres')"
echo "Having SSL=true in postgres config causes many errors (psycopg2 problem)"
read -r -p "Remove SSL=true from the PostgreSQL config?[Y/n]" response
remove_ssl=${response:-"y"} # tolower
case $remove_ssl in
[yY][eE][sS]|[yY])
sed -i -e '/ssl =/ s/= .*/= false/' $postgres_conf

echo "Restarting the postgresql service"
# get the return values of which commands to determine the service controller
which service >> /dev/null 2>&1
service_bin=$?
which systemctl >> /dev/null 2>&1
systemctl_bin=$?
if [ "$service_bin" != "1" ]; then
service postgresql restart
service postgresql status | grep -q '^Running clusters: ..*$'
status_exitcode="$?"
elif [ "$systemctl_bin" != "1" ]; then
systemctl restart postgresql
systemctl status postgresql | grep -q "active"
status_exitcode="$?"
else
echo "[+] It seems postgres server is not running or responding, please start/restart it manually!"
exit 1
fi
;;
*)
# do nothing
;;
esac

echo "Restarting the postgresql service"

#get the return values of which commands to determine the service controller
which service >> /dev/null 2>&1
service_bin=$?
which systemctl >> /dev/null 2>&1
systemctl_bin=$?
if [ "$service_bin" != "1" ]; then
service postgresql restart
service postgresql status | grep -q '^Running clusters: ..*$'
status_exitcode="$?"
elif [ "$systemctl_bin" != "1" ]; then
systemctl restart postgresql
systemctl status postgresql | grep -q "active"
status_exitcode="$?"
else
echo "[+] It seems postgres server is not running or responding, please start/restart it manually!"
exit 1
fi
}


Expand Down

0 comments on commit 5b9c333

Please sign in to comment.