| Server IP : 61.19.30.66 / Your IP : 216.73.216.15 Web Server : Apache/2.2.22 (Ubuntu) System : Linux klw 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 User : www-data ( 33) PHP Version : 5.3.10-1ubuntu3.48 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/share/pyshared/landscape/ |
Upload File : |
"""Programmatically manage the Landscape client SysV-style init script."""
import os
class ProcessError(Exception):
""" Error running a process with os.system. """
class SysVConfig(object):
"""Configure and drive the Landscape client init script.
@param filename: Path to the file holding init scripts env variables.
"""
def __init__(self, filename="/etc/default/landscape-client"):
self._filename = filename
def set_start_on_boot(self, flag):
"""Make the init script decide to start the client when it's run."""
current = self._parse_file()
current["RUN"] = flag and 1 or 0
self._write_file(current)
def restart_landscape(self):
"""Restart the Landscape client service."""
if os.system("/etc/init.d/landscape-client restart"):
raise ProcessError("Could not restart client")
def stop_landscape(self):
"""Stop the Landscape client service."""
if os.system("/etc/init.d/landscape-client stop"):
raise ProcessError("Could not stop client")
def is_configured_to_run(self):
"""
Return a boolean representing whether the init script will decide to
actually start the client when it is run. This method should match
the semantics of the checks in debian/landscape-client.init.
"""
state = self._parse_file()
run_value = state.get("RUN", "0")
return (not run_value[:1].isspace()) and run_value != "0"
def _parse_file(self):
values = {}
# Only attempt to parse the file if it exists.
if os.path.isfile(self._filename):
for line in open(self._filename, "r"):
line = line.strip()
if "=" in line:
key, value = line.split("=")
values[key] = value
return values
def _write_file(self, values):
file = open(self._filename, "w")
for key in sorted(values.keys()):
file.write("%s=%s\n" % (key, str(values[key])))
file.close()