~ionutbalutoiu/charms/trusty/neutron-api/next

« back to all changes in this revision

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

  • Committer: David Ames
  • Date: 2015-09-28 17:45:40 UTC
  • mfrom: (145 trunk)
  • mto: This revision was merged to the branch mainline in revision 146.
  • Revision ID: david.ames@canonical.com-20150928174540-wx0t0d3uwgmlsotb
PullĀ inĀ upstream

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):
 
66
def service_pause(service_name, init_dir="/etc/init", initd_dir="/etc/init.d"):
67
67
    """Pause a system service.
68
68
 
69
69
    Stop it, and prevent it from starting again at boot."""
70
 
    if init_dir is None:
71
 
        init_dir = "/etc/init"
72
70
    stopped = service_stop(service_name)
73
 
    # XXX: Support systemd too
74
 
    override_path = os.path.join(
75
 
        init_dir, '{}.override'.format(service_name))
76
 
    with open(override_path, 'w') as fh:
77
 
        fh.write("manual\n")
 
71
    upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))
 
72
    sysv_file = os.path.join(initd_dir, service_name)
 
73
    if os.path.exists(upstart_file):
 
74
        override_path = os.path.join(
 
75
            init_dir, '{}.override'.format(service_name))
 
76
        with open(override_path, 'w') as fh:
 
77
            fh.write("manual\n")
 
78
    elif os.path.exists(sysv_file):
 
79
        subprocess.check_call(["update-rc.d", service_name, "disable"])
 
80
    else:
 
81
        # XXX: Support SystemD too
 
82
        raise ValueError(
 
83
            "Unable to detect {0} as either Upstart {1} or SysV {2}".format(
 
84
                service_name, upstart_file, sysv_file))
78
85
    return stopped
79
86
 
80
87
 
81
 
def service_resume(service_name, init_dir=None):
 
88
def service_resume(service_name, init_dir="/etc/init",
 
89
                   initd_dir="/etc/init.d"):
82
90
    """Resume a system service.
83
91
 
84
92
    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, '{}.override'.format(service_name))
90
 
    if os.path.exists(override_path):
91
 
        os.unlink(override_path)
 
93
    upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))
 
94
    sysv_file = os.path.join(initd_dir, service_name)
 
95
    if os.path.exists(upstart_file):
 
96
        override_path = os.path.join(
 
97
            init_dir, '{}.override'.format(service_name))
 
98
        if os.path.exists(override_path):
 
99
            os.unlink(override_path)
 
100
    elif os.path.exists(sysv_file):
 
101
        subprocess.check_call(["update-rc.d", service_name, "enable"])
 
102
    else:
 
103
        # XXX: Support SystemD too
 
104
        raise ValueError(
 
105
            "Unable to detect {0} as either Upstart {1} or SysV {2}".format(
 
106
                service_name, upstart_file, sysv_file))
 
107
 
92
108
    started = service_start(service_name)
93
109
    return started
94
110