Add initial meta-stx to support StarlingX build
[pti/rtp.git] / meta-stx / recipes-devtools / python / files / python-django-horizon / horizon-patching-restart
1 #!/bin/bash
2 #
3 # Copyright (c) 2017 Wind River Systems, Inc.
4 #
5 # SPDX-License-Identifier: Apache-2.0
6 #
7
8 #
9 # The patching subsystem provides a patch-functions bash source file
10 # with useful function and variable definitions.
11 #
12 . /etc/patching/patch-functions
13
14 #
15 # We can now check to see what type of node we're on, if it's locked, etc,
16 # and act accordingly
17 #
18
19 #
20 # Declare an overall script return code
21 #
22 declare -i GLOBAL_RC=$PATCH_STATUS_OK
23
24 #
25 # handle restarting horizon.
26 #
27 if is_controller
28 then
29     # Horizon only runs on the controller
30
31     if [ ! -f $PATCH_FLAGDIR/horizon.restarted ]
32     then
33         # Check SM to see if Horizon is running
34         sm-query service horizon | grep -q 'enabled-active'
35         if [ $? -eq 0 ]
36         then
37             loginfo "$0: Logging out all horizon sessions"
38
39             # Remove sessions
40             rm -f /var/tmp/sessionid*
41
42             loginfo "$0: Restarting horizon"
43
44             # Ask SM to restart Horizon
45             sm-restart service horizon
46             touch $PATCH_FLAGDIR/horizon.restarted
47
48             # Wait up to 30 seconds for service to recover
49             let -i UNTIL=$SECONDS+30
50             while [ $UNTIL -ge $SECONDS ]
51             do
52                 # Check to see if it's running
53                 sm-query service horizon | grep -q 'enabled-active'
54                 if [ $? -eq 0 ]
55                 then
56                     break
57                 fi
58
59                 # Still not running? Let's wait 5 seconds and check again
60                 sleep 5
61             done
62
63             sm-query service horizon | grep -q 'enabled-active'
64             if [ $? -ne 0 ]
65             then
66                 # Still not running! Clear the flag and mark the RC as failed
67                 loginfo "$0: Failed to restart horizon"
68                 rm -f $PATCH_FLAGDIR/horizon.restarted
69                 GLOBAL_RC=$PATCH_STATUS_FAILED
70                 sm-query service horizon
71             fi
72         fi
73     fi
74 fi
75
76 #
77 # Exit the script with the overall return code
78 #
79 exit $GLOBAL_RC
80