components/openstack/horizon/files/horizon-upgrade
changeset 6856 356aeea98c39
equal deleted inserted replaced
6855:ea44e7e0ca98 6856:356aeea98c39
       
     1 #!/usr/bin/python2.7
       
     2 
       
     3 # Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
       
     4 #
       
     5 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
       
     6 #    not use this file except in compliance with the License. You may obtain
       
     7 #    a copy of the License at
       
     8 #
       
     9 #         http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 #    Unless required by applicable law or agreed to in writing, software
       
    12 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
       
    13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
       
    14 #    License for the specific language governing permissions and limitations
       
    15 #    under the License.
       
    16 
       
    17 import os
       
    18 from subprocess import check_call, Popen, PIPE
       
    19 import sys
       
    20 import traceback
       
    21 
       
    22 import smf_include
       
    23 
       
    24 
       
    25 def start():
       
    26     # pull out the current version of config/upgrade-id
       
    27     p = Popen(['/usr/bin/svcprop', '-p', 'config/upgrade-id',
       
    28                os.environ['SMF_FMRI']], stdout=PIPE, stderr=PIPE)
       
    29     curr_ver, _err = p.communicate()
       
    30     curr_ver = curr_ver.strip()
       
    31 
       
    32     # extract the openstack-upgrade-id from the pkg
       
    33     p = Popen(['/usr/bin/pkg', 'contents', '-H', '-t', 'set', '-o', 'value',
       
    34                '-a', 'name=openstack.upgrade-id',
       
    35                'pkg:/cloud/openstack/horizon'], stdout=PIPE, stderr=PIPE)
       
    36     pkg_ver, _err = p.communicate()
       
    37     pkg_ver = pkg_ver.strip()
       
    38 
       
    39     if curr_ver == pkg_ver:
       
    40         # No need to upgrade
       
    41         sys.exit(smf_include.SMF_EXIT_OK)
       
    42 
       
    43     # In versions of OpenStack prior to Mitaka, 'openstack-dashboard-http.conf'
       
    44     # and 'openstack-dashboard-tls.conf' were delivered by the
       
    45     # cloud/openstack/horizon package.  Look for the existence of either file
       
    46     # in Apache's conf.d directory.  If either are found, exit the service
       
    47     # degraded so the administrator can investigate why.
       
    48     for filename in ['openstack-dashboard-http.conf',
       
    49                      'openstack-dashboard-tls.conf']:
       
    50         path = os.path.join('/etc/apache2/2.4/conf.d', filename)
       
    51         if os.path.exists(path) or os.path.islink(path):
       
    52             reason = '/etc/apache2/2.4/conf.d/%s found.  ' % filename + \
       
    53                      'Starting with the Mitaka release, Horizon is now a ' + \
       
    54                      'stand-alone service and should be configured ' + \
       
    55                      'independently from the ' + \
       
    56                      'svc:/network/http:apache24 service.  ' + \
       
    57                      '/etc/apache2/2.4/conf.d/%s should be ' % filename + \
       
    58                      'removed before restarting the ' + \
       
    59                      'svc:/network/http:apache24 service'
       
    60             smf_include.smf_method_exit(smf_include.SMF_EXIT_DEGRADED,
       
    61                                         'Apache_Configured', reason)
       
    62 
       
    63     # update the current version
       
    64     check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
       
    65                 'config/upgrade-id', '=', pkg_ver])
       
    66     check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'refresh'])
       
    67 
       
    68     sys.exit(smf_include.SMF_EXIT_OK)
       
    69 
       
    70 
       
    71 if __name__ == '__main__':
       
    72     os.putenv('LC_ALL', 'C')
       
    73     try:
       
    74         smf_include.smf_main()
       
    75     except RuntimeError:
       
    76         sys.exit(smf_include.SMF_EXIT_ERR_FATAL)
       
    77     except Exception as err:
       
    78         print 'Unknown error:  %s' % err
       
    79         print
       
    80         traceback.print_exc(file=sys.stdout)
       
    81         sys.exit(smf_include.SMF_EXIT_ERR_FATAL)