~pjdc/charms/trusty/postgresql/nagios-additional-servicegroups

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Stuart Bishop
  • Date: 2014-05-07 04:49:06 UTC
  • mfrom: (90.1.4 postgresql)
  • Revision ID: stuart@stuartbishop.net-20140507044906-8z43ktiwg20j1bct
[thedac] Package holding & nagios fixes, per https://code.launchpad.net/~thedac/charms/precise/postgresql/package-holding/+merge/216411

Show diffs side-by-side

added added

removed removed

Lines of Context:
866
866
        local_state[name] = config_data.get(name, None)
867
867
    local_state.save()
868
868
 
 
869
    package_status = config_data['package_status']
 
870
    if package_status not in ['install', 'hold']:
 
871
        valid = False
 
872
        log("package_status must be 'install' or 'hold' not '{}'"
 
873
            "".format(package_status), CRITICAL)
 
874
 
869
875
    if not valid:
870
876
        sys.exit(99)
871
877
 
872
878
 
 
879
def ensure_package_status(package, status):
 
880
    selections = ''.join(['{} {}\n'.format(package, status)])
 
881
    dpkg = subprocess.Popen(['dpkg', '--set-selections'],
 
882
                                stdin=subprocess.PIPE)
 
883
    dpkg.communicate(input=selections)
 
884
 
 
885
 
873
886
#------------------------------------------------------------------------------
874
887
# Core logic for permanent storage changes:
875
888
# NOTE the only 2 "True" return points:
1584
1597
        packages.append('pgtune')
1585
1598
    packages.extend((hookenv.config('extra-packages') or '').split())
1586
1599
    packages = fetch.filter_installed_packages(packages)
 
1600
    # Set package state for main postgresql package if installed
 
1601
    if 'postgresql-{}'.format(version) not in packages:
 
1602
        ensure_package_status('postgresql-{}'.format(version), 
 
1603
                              hookenv.config('package_status'))
1587
1604
    fetch.apt_install(packages, fatal=True)
1588
1605
 
1589
1606