diff options
author | Alexander Bokovoy <abokovoy@redhat.com> | 2011-10-10 15:25:15 +0300 |
---|---|---|
committer | Simo Sorce <ssorce@redhat.com> | 2011-10-13 15:04:13 -0400 |
commit | 04ba21aaca9c376abab36cf75d764507a3b14802 (patch) | |
tree | 505d2b61d1731fe62a019e679df93ff6bf070893 /ipapython/platform/redhat.py | |
parent | 789b560a5786b02bd210f90c5b75b18b3ca609b3 (diff) | |
download | freeipa-04ba21aaca9c376abab36cf75d764507a3b14802.tar.gz freeipa-04ba21aaca9c376abab36cf75d764507a3b14802.tar.xz freeipa-04ba21aaca9c376abab36cf75d764507a3b14802.zip |
Add support for systemd environments and use it to support Fedora 16
https://fedorahosted.org/freeipa/ticket/1192
Diffstat (limited to 'ipapython/platform/redhat.py')
-rw-r--r-- | ipapython/platform/redhat.py | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/ipapython/platform/redhat.py b/ipapython/platform/redhat.py index 6bf8bf348..d9de3abca 100644 --- a/ipapython/platform/redhat.py +++ b/ipapython/platform/redhat.py @@ -65,20 +65,20 @@ class RedHatService(base.PlatformService): installed = False return installed - def is_enabled(self): + def is_enabled(self, instance_name=""): (stdout, stderr, returncode) = ipautil.run(["/sbin/chkconfig", self.service_name],raiseonerr=False) return (returncode == 0) - def enable(self): + def enable(self, instance_name=""): ipautil.run(["/sbin/chkconfig", self.service_name, "on"]) - def disable(self): + def disable(self, instance_name=""): ipautil.run(["/sbin/chkconfig", self.service_name, "off"]) - def install(self): + def install(self, instance_name=""): ipautil.run(["/sbin/chkconfig", "--add", self.service_name]) - def remove(self): + def remove(self, instance_name=""): ipautil.run(["/sbin/chkconfig", "--del", self.service_name]) class RedHatAuthConfig(base.AuthConfig): @@ -133,48 +133,11 @@ def restore_context(filepath): ipautil.run(["/sbin/restorecon", filepath], raiseonerr=False) def backup_and_replace_hostname(fstore, statestore, hostname): - network_filename = "/etc/sysconfig/network" - # Backup original /etc/sysconfig/network - fstore.backup_file(network_filename) - hostname_pattern = re.compile(''' -(^ - \s* - (?P<option> [^\#;]+?) - (\s*=\s*) - (?P<value> .+?)? - (\s*((\#|;).*)?)? -$)''', re.VERBOSE) - temp_filename = None - with tempfile.NamedTemporaryFile(delete=False) as new_config: - temp_filename = new_config.name - with open(network_filename, 'r') as f: - for line in f: - new_line = line - m = hostname_pattern.match(line) - if m: - option, value = m.group('option', 'value') - if option is not None and option == 'HOSTNAME': - if value is not None and hostname != value: - new_line = u"HOSTNAME=%s\n" % (hostname) - statestore.backup_state('network', 'hostname', value) - new_config.write(new_line) - new_config.flush() - # Make sure the resulting file is readable by others before installing it - os.fchmod(new_config.fileno(), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) - os.fchown(new_config.fileno(), 0, 0) - - # At this point new_config is closed but not removed due to 'delete=False' above - # Now, install the temporary file as configuration and ensure old version is available as .orig - # While .orig file is not used during uninstall, it is left there for administrator. - ipautil.install_file(temp_filename, network_filename) - try: - ipautil.run(['/bin/hostname', hostname]) - except ipautil.CalledProcessError, e: - print >>sys.stderr, "Failed to set this machine hostname to %s (%s)." % (hostname, str(e)) - - # For SE Linux environments it is important to reset SE labels to the expected ones - try: - restore_context(network_filename) - except ipautil.CalledProcessError, e: - print >>sys.stderr, "Failed to set permissions for %s (%s)." % (network_filename, str(e)) + replacevars = {'HOSTNAME':hostname} + old_values = ipautil.backup_config_and_replace_variables(fstore, + "/etc/sysconfig/network", + replacevars=replacevars) + restore_context("/etc/sysconfig/network") + if old_values['HOSTNAME']: + statestore.backup_state('network', 'hostname', old_values['HOSTNAME']) |