-#!/bin/bash
-#
-# Copyright (c) 2017 Wind River Systems, Inc.
-#
-# SPDX-License-Identifier: Apache-2.0
-#
-
-#
-# The patching subsystem provides a patch-functions bash source file
-# with useful function and variable definitions.
-#
-. /etc/patching/patch-functions
-
-#
-# We can now check to see what type of node we're on, if it's locked, etc,
-# and act accordingly
-#
-
-#
-# Declare an overall script return code
-#
-declare -i GLOBAL_RC=$PATCH_STATUS_OK
-
-#
-# handle restarting horizon.
-#
-if is_controller
-then
- # Horizon only runs on the controller
-
- if [ ! -f $PATCH_FLAGDIR/horizon.restarted ]
- then
- # Check SM to see if Horizon is running
- sm-query service horizon | grep -q 'enabled-active'
- if [ $? -eq 0 ]
- then
- loginfo "$0: Logging out all horizon sessions"
-
- # Remove sessions
- rm -f /var/tmp/sessionid*
-
- loginfo "$0: Restarting horizon"
-
- # Ask SM to restart Horizon
- sm-restart service horizon
- touch $PATCH_FLAGDIR/horizon.restarted
-
- # Wait up to 30 seconds for service to recover
- let -i UNTIL=$SECONDS+30
- while [ $UNTIL -ge $SECONDS ]
- do
- # Check to see if it's running
- sm-query service horizon | grep -q 'enabled-active'
- if [ $? -eq 0 ]
- then
- break
- fi
-
- # Still not running? Let's wait 5 seconds and check again
- sleep 5
- done
-
- sm-query service horizon | grep -q 'enabled-active'
- if [ $? -ne 0 ]
- then
- # Still not running! Clear the flag and mark the RC as failed
- loginfo "$0: Failed to restart horizon"
- rm -f $PATCH_FLAGDIR/horizon.restarted
- GLOBAL_RC=$PATCH_STATUS_FAILED
- sm-query service horizon
- fi
- fi
- fi
-fi
-
-#
-# Exit the script with the overall return code
-#
-exit $GLOBAL_RC
-