Author: tmckay
Date: 2012-01-31 19:29:52 +0000 (Tue, 31 Jan 2012)
New Revision: 5198
Modified:
trunk/cumin/bin/cumin-database
Log:
Use systemctl when available. Maintains compatibility between F15, F16+, RHEL 5, and RHEL
6 which are all slightly different when considering the whole operation set.
BZ785863
Modified: trunk/cumin/bin/cumin-database
===================================================================
--- trunk/cumin/bin/cumin-database 2012-01-30 19:05:05 UTC (rev 5197)
+++ trunk/cumin/bin/cumin-database 2012-01-31 19:29:52 UTC (rev 5198)
@@ -18,7 +18,9 @@
function format-output {
while read line; do
- echo " | $line"
+ if [ -n "$line" ]; then
+ echo " | $line"
+ fi
done
}
@@ -38,15 +40,36 @@
completed=1
for ((c=0; c<=$2; c++))
do
+ echo $1
$1 && completed=0
if [ $completed -eq 0 ]; then
break
fi
sleep 1
+ echo "retrying..."
done
return $completed
}
+# check for existence of systemctl function...
+if [[ -f "/bin/systemctl" ]]; then
+ have_systemd=1
+else
+ have_systemd=0
+fi
+
+function postgresql_str {
+ # There is no supported OS version that has a valid
+ # initdb option for the postgresql.service systemd script.
+
+ # el6 and Fedora F15 support sevice postresql initdb, however
+ if [ $have_systemd -eq 1 ] && [ "$1" != "initdb" ]; then
+ echo systemctl $1 postgresql.service
+ else
+ echo /sbin/service postgresql $1
+ fi
+}
+
function check-environment {
which rpm > /dev/null
@@ -60,7 +83,7 @@
}
function check-started {
- /sbin/service postgresql status &> /dev/null || {
+ $(postgresql_str status) &> /dev/null || {
echo "Error: The database is not running"
if [ "$1" != noadvice ]; then
echo "Hint: Run 'cumin-database start'"
@@ -188,14 +211,14 @@
check-environment || exit 1
check-initialized || exit 1
- /sbin/service postgresql start
+ $(postgresql_str start)
}
function stop {
check-environment || exit 1
check-initialized || exit 1
- /sbin/service postgresql stop
+ $(postgresql_str stop)
}
function restart {
@@ -207,7 +230,7 @@
# Use condrestart to skip restart of stopped service.
# Apparently condstop sometimes fails. Try up to 5 times.
- retry "/sbin/service postgresql condrestart" 5 || {
+ retry "$(postgresql_str condrestart)" 5 || {
echo "postgres restart failed"
exit 1
}
@@ -227,20 +250,18 @@
exit 1
fi
- # On older versions of Postgres (before 8.4), initdb does not exist but
- # using the start option will initialize the database, then start it.
- # Try initdb first, and if it fails try start. The "start" method
- # will leave the service running, which is different than initdb,
- # but that is fine at this point because it is restarted after
- # the call to configure anyway.
+ # Newer systems have a /usr/bin/postgresql-setup script, try to use it first.
if [[ -f "/usr/bin/postgresql-setup" ]]; then
echo -e "using postgresql-setup..."
run "/usr/bin/postgresql-setup initdb"
else
+ # On older versions of Postgres (before 8.4), initdb does not exist but
+ # using the start option will initialize the database, then start it.
+ # Try initdb first, and if it fails try start.
echo -e "\nAttempting to use initdb option..."
- run "/sbin/service postgresql initdb" || {
+ run "$(postgresql_str initdb)" || {
echo -e "\ninitdb option not supported, using start..."
- run "/sbin/service postgresql start"
+ run "$(postgresql_str start)"
}
fi
@@ -328,7 +349,7 @@
echo "Not good enough"
done
- run "/sbin/service postgresql stop" || :
+ run "$(postgresql_str stop)" || :
run "rm -rf /var/lib/pgsql/data"
}
@@ -395,7 +416,7 @@
configure)
configure && {
echo "The database server is configured"
- /sbin/service postgresql status &> /dev/null && {
+ $(postgresql_str status) &> /dev/null && {
echo -e "\nAfter configuration the server must be restarted."
echo -e "Would you like to restart the server now?\n"
get-explicit-confirmation
Show replies by date