~gnuoy/charms/trusty/keystone/restart-horror

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/host.py

  • Committer: Corey Bryant
  • Date: 2015-08-18 17:34:34 UTC
  • Revision ID: corey.bryant@canonical.com-20150818173434-hp6flkiy622hjrsy
[corey.bryant,r=trivial] Sync charm-helpers to pick up Liberty support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
    stopped = service_stop(service_name)
73
73
    # XXX: Support systemd too
74
74
    override_path = os.path.join(
75
 
        init_dir, '{}.conf.override'.format(service_name))
 
75
        init_dir, '{}.override'.format(service_name))
76
76
    with open(override_path, 'w') as fh:
77
77
        fh.write("manual\n")
78
78
    return stopped
86
86
    if init_dir is None:
87
87
        init_dir = "/etc/init"
88
88
    override_path = os.path.join(
89
 
        init_dir, '{}.conf.override'.format(service_name))
 
89
        init_dir, '{}.override'.format(service_name))
90
90
    if os.path.exists(override_path):
91
91
        os.unlink(override_path)
92
92
    started = service_start(service_name)
148
148
    return user_info
149
149
 
150
150
 
 
151
def user_exists(username):
 
152
    """Check if a user exists"""
 
153
    try:
 
154
        pwd.getpwnam(username)
 
155
        user_exists = True
 
156
    except KeyError:
 
157
        user_exists = False
 
158
    return user_exists
 
159
 
 
160
 
151
161
def add_group(group_name, system_group=False):
152
162
    """Add a group to the system"""
153
163
    try:
280
290
    return system_mounts
281
291
 
282
292
 
 
293
def fstab_mount(mountpoint):
 
294
    """Mount filesystem using fstab"""
 
295
    cmd_args = ['mount', mountpoint]
 
296
    try:
 
297
        subprocess.check_output(cmd_args)
 
298
    except subprocess.CalledProcessError as e:
 
299
        log('Error unmounting {}\n{}'.format(mountpoint, e.output))
 
300
        return False
 
301
    return True
 
302
 
 
303
 
283
304
def file_hash(path, hash_type='md5'):
284
305
    """
285
306
    Generate a hash checksum of the contents of 'path' or None if not found.