From b620ae1fa40aeadb4bbe2164fad7cb5c330acb78 Mon Sep 17 00:00:00 2001
From: Chris Friesen <chris.friesen@windriver.com>
Date: Wed, 28 Nov 2018 01:33:39 -0500
Subject: [PATCH] Remove stale Apache2 service pids when a POD starts.

Stale Apache2 pids will prevent Apache2 from starting and will leave
the POD in a crashed state.

Note: the pid file is somewhat confusingly called
/var/run/httpd/httpd.pid and /var/run/apache2 is just a symlink to
/var/run/httpd.

This is loosely based off the in-review upstream commit at
https://review.openstack.org/#/c/619747

Signed-off-by: Robert Church <robert.church@windriver.com>
---
 ceilometer/templates/bin/_ceilometer-api.sh.tpl | 3 +++
 keystone/templates/bin/_keystone-api.sh.tpl     | 6 ++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ceilometer/templates/bin/_ceilometer-api.sh.tpl b/ceilometer/templates/bin/_ceilometer-api.sh.tpl
index 3ba90d9..4b77452 100644
--- a/ceilometer/templates/bin/_ceilometer-api.sh.tpl
+++ b/ceilometer/templates/bin/_ceilometer-api.sh.tpl
@@ -40,6 +40,9 @@ function start () {
     fi
   fi
 
+  # Get rid of stale pid file if present.
+  rm -f /var/run/apache2/*.pid
+
   # Start Apache2
   exec {{ .Values.conf.software.apache2.binary }} {{ .Values.conf.software.apache2.start_parameters }}
 }
diff --git a/keystone/templates/bin/_keystone-api.sh.tpl b/keystone/templates/bin/_keystone-api.sh.tpl
index 5d4286a..85740a0 100644
--- a/keystone/templates/bin/_keystone-api.sh.tpl
+++ b/keystone/templates/bin/_keystone-api.sh.tpl
@@ -41,10 +41,8 @@ function start () {
      source /etc/apache2/envvars
   fi
 
-  if [ -f /var/run/apache2/apache2.pid ]; then
-     # Remove the stale pid for debian/ubuntu images
-     rm -f /var/run/apache2/apache2.pid
-  fi
+  # Get rid of stale pid, shared memory segment and wsgi sock files if present.
+  rm -f /var/run/apache2/*
 
   # Start Apache2
   exec {{ .Values.conf.software.apache2.binary }} {{ .Values.conf.software.apache2.start_parameters }}
-- 
1.8.3.1