do not rely on /etc/myplc-release to start or stop postgresql
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 16 Apr 2015 11:03:11 +0000 (13:03 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 16 Apr 2015 11:03:11 +0000 (13:03 +0200)
instead: start it when not yet running, and record that in /etc/sfa/postgresql-started so we can stop it properly

init.d/sfa

index ae4aa9c..e3b80f9 100755 (executable)
@@ -36,6 +36,7 @@ function debian_get_postgresql_versions () {
 }
 
 ####################
+POSTGRESQL_STARTED=/etc/sfa/postgresql-started
 if [ -f /etc/redhat-release ] ; then
     # source function library
     . /etc/init.d/functions
@@ -233,9 +234,13 @@ function db_start () {
 
     ######## Start up the server
     # not too nice, but.. when co-located with myplc we'll let it start/stop postgresql
-    if [ ! -f /etc/myplc-release ] ; then
-       echo STARTING...
+    if [ ! postgresql_check ] ; then
        service postgresql start >& /dev/null
+       MESSAGE=$"Starting PostgreSQL server"
+       echo -n "$MESSAGE"
+       [ "$ERRORS" == 0 ] && success "$MESSAGE" || failure "$MESSAGE" ; echo
+       # best-effort to make sure we turn it back off when running stop
+       touch $POSTGRESQL_STARTED
     fi
     postgresql_check
     check
@@ -270,12 +275,13 @@ function db_stop () {
     [ "$SFA_DB_ENABLED" == 1 -o "$SFA_DB_ENABLED" == True ] || return
 
     # not too nice, but.. when co-located with myplc we'll let it start/stop postgresql
-    if [ ! -f /etc/myplc-release ] ; then
+    if [ -f $POSTGRESQL_STARTED ] ; then
        service postgresql stop >& /dev/null
        check
        MESSAGE=$"Stopping PostgreSQL server"
        echo -n "$MESSAGE"
        [ "$ERRORS" == 0 ] && success "$MESSAGE" || failure "$MESSAGE" ; echo
+       rm -f $POSTGRESQL_STARTED
     fi
 }