Okay, so I wrote it after all.

This was tested on RHEL4 (yum-2.4.3) and FC6 (yum-3.0.3). It was found working.

Please let me know what you think.

Cheers,
--
Konstantin Ryabitsev
Montréal, Québec
# Yum plugin that restarts services when packages are installed or upgraded.
# See service-restart.conf for more information on configuration parameters.
#
# Copyright (c) 2007 McGill University
# Konstantin Ryabitsev <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

import os
from glob import fnmatch
from yum.plugins import TYPE_CORE

requires_api_version = '2.1'
plugin_type = (TYPE_CORE,)

def posttrans_hook(conduit):
    # read the configuration
    servicecmd = conduit.confString('main', 'servicecmd', '/sbin/service')
    packages = []
    for service in conduit.confString('main', 'services', '').split(','):
        service = service.strip()
        action = conduit.confString(service, 'action', 'condrestart')
        for package in conduit.confString(service, 'packages', '').split(','):
            if package:
                packages.append({'package': package, 'service': service, 
                                 'action': action})
    
    ts = conduit.getTsInfo()
    actions = {}
    for member in ts.getMembers():
        if member.ts_state == 'u':
            # this package was installed or updated
            for package in packages:
                if fnmatch.fnmatch(member.name, package['package']):
                    # package match! Add it to the services to restart
                    actions[package['service']] = package['action']
    
    for service in actions.keys():
        command = '%s %s %s' % (servicecmd, service, actions[service])
        conduit.info(2, '  service-restart: running %s' % command)
        os.system(command)

Attachment: service-restart.conf
Description: Binary data

_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to