63
63
return service_result
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.
69
69
Stop it, and prevent it from starting again at boot."""
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:
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:
78
elif os.path.exists(sysv_file):
79
subprocess.check_call(["update-rc.d", service_name, "disable"])
81
# XXX: Support SystemD too
83
"Unable to detect {0} as either Upstart {1} or SysV {2}".format(
84
service_name, upstart_file, sysv_file))
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.
84
92
Reenable starting again at boot. Start the service"""
85
# XXX: Support systemd too
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"])
103
# XXX: Support SystemD too
105
"Unable to detect {0} as either Upstart {1} or SysV {2}".format(
106
service_name, upstart_file, sysv_file))
92
108
started = service_start(service_name)