commit c9645599b7df24604ff3bfc2557f2d4d30c030aa
Author: Nicolas Chauvet <kwizart(a)gmail.com>
Date: Wed Jul 31 10:51:26 2019 +0200
Update common-scripts
.../files/common-scripts/conditional-reload.sh | 12 +++++++--
.../files/common-scripts/conditional-restart.sh | 24 +++++-------------
.../common-scripts/proxy-conditional-reload.sh | 25 ++++++++++++++++++++
3 files changed, 41 insertions(+), 20 deletions(-)
---
diff --git a/roles/base/files/common-scripts/conditional-reload.sh
b/roles/base/files/common-scripts/conditional-reload.sh
index b9aecdb..988a08b 100644
--- a/roles/base/files/common-scripts/conditional-reload.sh
+++ b/roles/base/files/common-scripts/conditional-reload.sh
@@ -10,9 +10,15 @@ rpm -q $PACKAGE
INSTALLED=$?
if [ $INSTALLED -eq 0 ]; then
- echo "Package $PACKAGE installed. Attempting reload of $SERVICE."
- /sbin/service $SERVICE reload
- exit $? # Exit with the /sbin/service status code
+ echo "Checking if $SERVICE is running"
+ /sbin/service $SERVICE status >& /dev/null
+ if [ $? == 0 ]; then
+ echo "Package $PACKAGE installed and running. Attempting reload of
$SERVICE."
+ /sbin/service $SERVICE reload
+ exit $? # Exit with the /sbin/service status code
+ fi
+ echo "Package $PACKAGE is install, but $SERVICE is not running,
skipping..."
+ exit 0
fi
# If the package wasn't installed, then pretend everything is fine.
diff --git a/roles/base/files/common-scripts/conditional-restart.sh
b/roles/base/files/common-scripts/conditional-restart.sh
index f95ef74..8da52dc 100644
--- a/roles/base/files/common-scripts/conditional-restart.sh
+++ b/roles/base/files/common-scripts/conditional-restart.sh
@@ -1,20 +1,10 @@
#!/bin/bash
-# Restart SERVICE only if PACKAGE is installed.
-# We use this throughout handlers/restart_services.yml
+#
+# We use this to try and restart a service.
+# If it's not running, do nothing.
+# If it is running, restart it.
+#
SERVICE=$1
-PACKAGE=$2
-
-rpm -q $PACKAGE
-
-INSTALLED=$?
-
-if [ $INSTALLED -eq 0 ]; then
- echo "Package $PACKAGE installed. Attempting restart of $SERVICE."
- /sbin/service $SERVICE restart
- exit $? # Exit with the /sbin/service status code
-fi
-
-# If the package wasn't installed, then pretend everything is fine.
-echo "Package $PACKAGE not installed. Skipping restart of $SERVICE."
-exit 0
+# Check if service unit is present before trying to restart it
+/usr/bin/systemctl cat $1.service &>/dev/null && /usr/bin/systemctl
try-restart $1 || true
diff --git a/roles/base/files/common-scripts/proxy-conditional-reload.sh
b/roles/base/files/common-scripts/proxy-conditional-reload.sh
new file mode 100644
index 0000000..ef60087
--- /dev/null
+++ b/roles/base/files/common-scripts/proxy-conditional-reload.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+# reload SERVICE only if PACKAGE is installed.
+# We use this throughout handlers/restart_services.yml
+
+SERVICE=$1
+PACKAGE=$2
+
+rpm -q $PACKAGE
+
+INSTALLED=$?
+
+if [ ! -f /etc/httpd/ticketkey_*.tkey ]; then
+ # This host is not configured yet, do not try and restart httpd
+ exit 0
+fi
+
+if [ $INSTALLED -eq 0 ]; then
+ echo "Package $PACKAGE installed. Attempting reload of $SERVICE."
+ /sbin/service $SERVICE reload
+ exit $? # Exit with the /sbin/service status code
+fi
+
+# If the package wasn't installed, then pretend everything is fine.
+echo "Package $PACKAGE not installed. Skipping reload of $SERVICE."
+exit 0