From 17d96e5da9f58b44866595a2a052f041aa1f98ad Mon Sep 17 00:00:00 2001 From: Kevin Fenzi Date: Fri, 13 Nov 2015 23:49:38 +0000 Subject: [PATCH] Add a conditional-reload script and use it so we can not fail on hosts with no httpd installed. --- handlers/restart_services.yml | 2 +- .../common-scripts/conditional-reload.sh | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 roles/base/files/common-scripts/conditional-reload.sh diff --git a/handlers/restart_services.yml b/handlers/restart_services.yml index 80f2c9e55f..126117901c 100644 --- a/handlers/restart_services.yml +++ b/handlers/restart_services.yml @@ -34,7 +34,7 @@ command: /usr/local/bin/conditional-restart.sh fedmsg-relay fedmsg-relay - name: reload httpd - action: service name=httpd state=reloaded + command: /usr/local/bin/conditional-reload.sh httpd httpd - name: restart iptables action: service name=iptables state=restarted diff --git a/roles/base/files/common-scripts/conditional-reload.sh b/roles/base/files/common-scripts/conditional-reload.sh new file mode 100644 index 0000000000..b9aecdb108 --- /dev/null +++ b/roles/base/files/common-scripts/conditional-reload.sh @@ -0,0 +1,20 @@ +#!/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 [ $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