diff --git a/handlers/restart_services.yml b/handlers/restart_services.yml index 53a3495aa5..2ceaa44db3 100644 --- a/handlers/restart_services.yml +++ b/handlers/restart_services.yml @@ -15,20 +15,20 @@ action: service name=crond state=restarted - name: restart fedmsg-gateway - command: /usr/local/bin/conditional-restart.sh fedmsg-gateway fedmsg-gateway + command: /usr/local/bin/conditional-restart.sh fedmsg-gateway - name: restart fedmsg-hub - command: /usr/local/bin/conditional-restart.sh fedmsg-hub fedmsg-hub + command: /usr/local/bin/conditional-restart.sh fedmsg-hub # Note that, we're cool with arbitrary restarts on bodhi-backend02, just # not bodhi-backend01 or bodhi-backend03. 01 and 03 is where the releng/mash # stuff happens and we # don't want to interrupt that. when: inventory_hostname not in ['bodhi-backend01.phx2.fedoraproject.org', 'bodhi-backend03.phx2.fedoraproject.org'] - name: restart fedmsg-irc - command: /usr/local/bin/conditional-restart.sh fedmsg-irc fedmsg-irc + command: /usr/local/bin/conditional-restart.sh fedmsg-irc - name: restart fedmsg-relay - command: /usr/local/bin/conditional-restart.sh fedmsg-relay fedmsg-relay + command: /usr/local/bin/conditional-restart.sh fedmsg-relay - name: restart koji-sync-listener action: service name=koji-sync-listener state=restarted diff --git a/roles/base/files/common-scripts/conditional-restart.sh b/roles/base/files/common-scripts/conditional-restart.sh index f95ef741d7..931bf42360 100644 --- a/roles/base/files/common-scripts/conditional-restart.sh +++ b/roles/base/files/common-scripts/conditional-restart.sh @@ -1,20 +1,9 @@ #!/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 +/usr/bin/systemctl try-restart $1