diff options
author | bnewbold <bnewbold@robocracy.org> | 2012-07-12 17:21:54 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2012-07-12 22:25:50 -0400 |
commit | f1e764f2e5728113f191456236d02fdae6e7680a (patch) | |
tree | 46484b2871311fd213c1df2e2b228a0db8635903 /modules | |
parent | 337560b0d197fb3d1b4fd7cb1fdecc687c9f9758 (diff) |
integrate exmachina configuration management layer
- add exmachina code and test code
- modify plinth.py to listen for shared secret on stdin at start
(if appropriate flag is set) and try to connect to exmachina daemon
- use exmachina to read and set /etc/hostname as a demo
- update plinth init.d script to start exmachina and share keys
- update docs with new deps and run instructions
Diffstat (limited to 'modules')
-rw-r--r-- | modules/installed/system/config.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/modules/installed/system/config.py b/modules/installed/system/config.py index c8b5190..b31dc60 100644 --- a/modules/installed/system/config.py +++ b/modules/installed/system/config.py @@ -41,20 +41,18 @@ def valid_hostname(name): def set_hostname(hostname): "Sets machine hostname to hostname" - cfg.log.info("Writing '%s' to /etc/hostname" % hostname) - unslurp("/etc/hostname", hostname+"\n") + cfg.log.info("Writing '%s' to /etc/hostname with exmachina" % hostname) + try: - retcode = subprocess.call("/etc/init.d/hostname.sh start", shell=True) - if retcode < 0: - cfg.log.error("Hostname restart terminated by signal: return code is %s" % retcode) - else: - cfg.log.debug("Hostname restart returned %s" % retcode) + cfg.exmachina.augeas.set("/files/etc/hostname/*", hostname) + cfg.exmachina.augeas.save() + # don't persist/cache change unless it was saved successfuly + sys_store = filedict_con(cfg.store_file, 'sys') + sys_store['hostname'] = hostname + cfg.exmachina.initd.restart("hostname.sh") # is hostname.sh debian-only? except OSError, e: raise cherrypy.HTTPError(500, "Hostname restart failed: %s" % e) - sys_store = filedict_con(cfg.store_file, 'sys') - sys_store['hostname'] = hostname - class general(FormPlugin, PagePlugin): url = ["/sys/config"] order = 30 @@ -72,8 +70,11 @@ class general(FormPlugin, PagePlugin): def main(self, message='', **kwargs): sys_store = filedict_con(cfg.store_file, 'sys') + hostname = cfg.exmachina.augeas.get("/files/etc/hostname/*") + # this layer of persisting configuration in sys_store could/should be + # removed -BLN defaults = {'time_zone': "slurp('/etc/timezone').rstrip()", - 'hostname': "gethostname()", + 'hostname': "hostname", } for k,c in defaults.items(): if not k in kwargs: @@ -81,6 +82,8 @@ class general(FormPlugin, PagePlugin): kwargs[k] = sys_store[k] except KeyError: exec("if not '%(k)s' in kwargs: sys_store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c}) + # over-ride the sys_store cached value + kwargs['hostname'] = hostname ## Get the list of supported timezones and the index in that list of the current one module_file = __file__ @@ -120,7 +123,8 @@ class general(FormPlugin, PagePlugin): old_val = sys_store['hostname'] try: set_hostname(hostname) - except: + except Exception, e: + cfg.log.error(e) cfg.log.info("Trying to restore old hostname value.") set_hostname(old_val) raise |