~openstack-charmers/charms/trusty/swift-storage/trunk

« back to all changes in this revision

Viewing changes to charmhelpers/core/host.py

  • Committer: James Page
  • Date: 2016-05-18 13:13:51 UTC
  • Revision ID: james.page@ubuntu.com-20160518131351-ezr0yivk08e18py4
Resync charm-helpers

Avoid use of 'service --status-all' which is currently
broken on trusty for upstart managed daemons; the change
moves to detecting how the daemon is managed, and then
using upstart status XXX or the return code of service XXX
status to determine whether a process is running.

Fixes for IPv6 network address detection under Ubuntu
16.04 which changes the output format of the ip commands
slightly.

Update the version map to include 8.1.x as a Neutron
version for Mitaka.

Change-Id: I0b68a2c4c03cb9d9113f23df8af50e09b0628348
Closes-Bug: 1581171
Closes-Bug: 1581598
Closes-Bug: 1580674

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
    return subprocess.call(cmd) == 0
129
129
 
130
130
 
131
 
def systemv_services_running():
132
 
    output = subprocess.check_output(
133
 
        ['service', '--status-all'],
134
 
        stderr=subprocess.STDOUT).decode('UTF-8')
135
 
    return [row.split()[-1] for row in output.split('\n') if '[ + ]' in row]
 
131
_UPSTART_CONF = "/etc/init/{}.conf"
 
132
_INIT_D_CONF = "/etc/init.d/{}"
136
133
 
137
134
 
138
135
def service_running(service_name):
140
137
    if init_is_systemd():
141
138
        return service('is-active', service_name)
142
139
    else:
143
 
        try:
144
 
            output = subprocess.check_output(
145
 
                ['service', service_name, 'status'],
146
 
                stderr=subprocess.STDOUT).decode('UTF-8')
147
 
        except subprocess.CalledProcessError:
148
 
            return False
149
 
        else:
150
 
            # This works for upstart scripts where the 'service' command
151
 
            # returns a consistent string to represent running 'start/running'
152
 
            if ("start/running" in output or "is running" in output or
153
 
                    "up and running" in output):
154
 
                return True
 
140
        if os.path.exists(_UPSTART_CONF.format(service_name)):
 
141
            try:
 
142
                output = subprocess.check_output(
 
143
                    ['status', service_name],
 
144
                    stderr=subprocess.STDOUT).decode('UTF-8')
 
145
            except subprocess.CalledProcessError:
 
146
                return False
 
147
            else:
 
148
                # This works for upstart scripts where the 'service' command
 
149
                # returns a consistent string to represent running 'start/running'
 
150
                if "start/running" in output:
 
151
                    return True
 
152
        elif os.path.exists(_INIT_D_CONF.format(service_name)):
155
153
            # Check System V scripts init script return codes
156
 
            if service_name in systemv_services_running():
157
 
                return True
158
 
            return False
 
154
            return service('status', service_name)
 
155
        return False
159
156
 
160
157
 
161
158
def service_available(service_name):