diff --git a/handlers/restart_services.yml b/handlers/restart_services.yml index 943763480d..c6a18c391d 100644 --- a/handlers/restart_services.yml +++ b/handlers/restart_services.yml @@ -6,7 +6,7 @@ action: service name=auditd state=restarted - name: restart apache - action: service name=httpd state=restarted + command: /usr/local/bin/conditional-restart.sh httpd httpd - name: reload apache action: service name=httpd state=reloaded @@ -17,8 +17,20 @@ - name: restart crond action: service name=crond state=restarted +- name: restart fedmsg-gateway + command: /usr/local/bin/conditional-restart.sh fedmsg-gateway fedmsg-gateway + +- name: restart fedmsg-hub + command: /usr/local/bin/conditional-restart.sh fedmsg-hub fedmsg-hub + +- name: restart fedmsg-irc + command: /usr/local/bin/conditional-restart.sh fedmsg-irc fedmsg-irc + +- name: restart fedmsg-relay + command: /usr/local/bin/conditional-restart.sh fedmsg-relay fedmsg-relay + - name: restart httpd - action: service name=httpd state=restarted + command: /usr/local/bin/conditional-restart.sh httpd httpd - name: reload httpd action: service name=httpd state=reloaded diff --git a/roles/base/files/common-scripts/conditional-restart.sh b/roles/base/files/common-scripts/conditional-restart.sh new file mode 100644 index 0000000000..6e77eb2983 --- /dev/null +++ b/roles/base/files/common-scripts/conditional-restart.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Restart SERVICE only if PACKAGE is installed. +# We use this throughout handlers/restart_services.yml + +SERVICE=$1 +PACKAGE=$2 + +/usr/bin/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 diff --git a/roles/fedmsg-hub/handlers/main.yml b/roles/fedmsg-hub/handlers/main.yml deleted file mode 100644 index eeb0c8707f..0000000000 --- a/roles/fedmsg-hub/handlers/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -- name: restart fedmsg-hub - action: service name=fedmsg-hub state=restarted diff --git a/roles/fedmsg_base/tasks/main.yml b/roles/fedmsg_base/tasks/main.yml index 5314706552..3b7e35674f 100644 --- a/roles/fedmsg_base/tasks/main.yml +++ b/roles/fedmsg_base/tasks/main.yml @@ -16,8 +16,19 @@ tags: - config +# Any files that change need to restart any services that depend on them. A +# trick here is that some hosts have an httpd that uses fedmsg, while others do +# not. Some hosts have a fedmsg-hub that uses this config, while others do not. +# Our handlers in handlers/restart_services.yml are smart enough to +# *conditionally* restart these services, only if they are installed on the +# system. - name: setup basic /etc/fedmsg.d/ contents - template: src="{{ item }}.j2" dest="/etc/fedmsg.d/{{ item }}" owner=root group=root mode=644 + template: > + src="{{ item }}.j2" + dest="/etc/fedmsg.d/{{ item }}" + owner=root + group=root + mode=644 with_items: - ssl.py - endpoints.py @@ -32,6 +43,12 @@ - base.py tags: - config + notify: + - restart httpd + - restart fedmsg-gateway + - restart fedmsg-hub + - restart fedmsg-irc + - restart fedmsg-relay - name: setup /etc/pki/fedmsg directory file: path=/etc/pki/fedmsg owner=root group=root mode=0755 state=directory