~corey.bryant/charms/trusty/ceph-radosgw/ch-sync

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2015-08-03 14:53:01 UTC
  • Revision ID: liam.young@canonical.com-20150803145301-t9bo9mhf4hk37ydu
Tags: 15.07
[gnuoy,trivial] Pre-release charmhelper sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    return service_result
64
64
 
65
65
 
 
66
def service_pause(service_name, init_dir=None):
 
67
    """Pause a system service.
 
68
 
 
69
    Stop it, and prevent it from starting again at boot."""
 
70
    if init_dir is None:
 
71
        init_dir = "/etc/init"
 
72
    stopped = service_stop(service_name)
 
73
    # XXX: Support systemd too
 
74
    override_path = os.path.join(
 
75
        init_dir, '{}.conf.override'.format(service_name))
 
76
    with open(override_path, 'w') as fh:
 
77
        fh.write("manual\n")
 
78
    return stopped
 
79
 
 
80
 
 
81
def service_resume(service_name, init_dir=None):
 
82
    """Resume a system service.
 
83
 
 
84
    Reenable starting again at boot. Start the service"""
 
85
    # XXX: Support systemd too
 
86
    if init_dir is None:
 
87
        init_dir = "/etc/init"
 
88
    override_path = os.path.join(
 
89
        init_dir, '{}.conf.override'.format(service_name))
 
90
    if os.path.exists(override_path):
 
91
        os.unlink(override_path)
 
92
    started = service_start(service_name)
 
93
    return started
 
94
 
 
95
 
66
96
def service(action, service_name):
67
97
    """Control a system service"""
68
98
    cmd = ['service', service_name, action]
140
170
 
141
171
def add_user_to_group(username, group):
142
172
    """Add a user to a group"""
143
 
    cmd = [
144
 
        'gpasswd', '-a',
145
 
        username,
146
 
        group
147
 
    ]
 
173
    cmd = ['gpasswd', '-a', username, group]
148
174
    log("Adding user {} to group {}".format(username, group))
149
175
    subprocess.check_call(cmd)
150
176