diff -Nur smeserver-yum-2.6.0.old/root/usr/lib/yum-plugins/smeserver.py smeserver-yum-2.6.0/root/usr/lib/yum-plugins/smeserver.py --- smeserver-yum-2.6.0.old/root/usr/lib/yum-plugins/smeserver.py 2021-02-15 17:05:10.702000000 -0500 +++ smeserver-yum-2.6.0/root/usr/lib/yum-plugins/smeserver.py 2021-02-15 17:07:34.080000000 -0500 @@ -1,6 +1,9 @@ # vim: noexpandtab tabstop=4 import os +import shutil +import subprocess +import syslog from yum.constants import * from yum.plugins import PluginYumExit from yum.plugins import TYPE_CORE @@ -21,8 +24,6 @@ eventlist = dict() actionlist = dict() -actionlistpre = dict() -actionlistpost = dict() templateslist = dict() serviceslist = dict() @@ -62,13 +63,35 @@ servicenames['qpsmtpd']='qpsmtpd' smechange = False +smechangelist = dict() ourfile = False erasing = False DEBUG = False def log(s): - if DEBUG: + if DEBUG : print s +def createevent(): + if os.path.isdir('/etc/e-smith/events/temp'): + shutil.rmtree('/etc/e-smith/events/temp') + os.makedirs('/etc/e-smith/events/temp/services2adjust', 0o777) + os.makedirs('/etc/e-smith/events/temp/templates2expand', 0o777) + +def addtemplate2expand(template): + #check filename + head_tail = os.path.split(template) + head = head_tail[0]; + filename = head_tail[1]; + # create dir + if not os.path.isdir('/etc/e-smith/events/temp/templates2expand' + head): + os.makedirs('/etc/e-smith/events/temp/templates2expand' + head, 0o777) + #touch file + fname= '/etc/e-smith/events/temp/templates2expand'+ template + fhandle = open(fname, 'a') + try: + os.utime(fname, None) + finally: + fhandle.close() def report_yum_status(status): fileHandle = open(status_file, 'w') @@ -100,6 +123,7 @@ report_yum_status('postresolve') def pretrans_hook(conduit): +# we might need to change the strategy here to make a difference between update and removal. #transaction set states #TS_UPDATE = 10 #TS_INSTALL = 20 @@ -122,20 +146,23 @@ global smechange global eventlist global actionlist - global actionlistpre - global actionlistpost global templateslist global serviceslist global erasing + # reinstall are not listed there so already skipped + # downgrade are going there + # update are going there, we filter them out + # real removal are the real deal there ; downgrade are played like if they were removal for tsmem in removes: erasing = True (n, a, e, v, r) = tsmem.po.pkgtup - #only for debug - log('**Package: ' + tsmem.name + ' remove') + if tsmem.output_state == TS_UPDATED : + # if we are actually updating then we are not removing, and new package will do better... skipping + log('skiping as updating ==> state ' + str(tsmem.po.state) + " RPM current state" + str(tsmem.current_state) + " RPM output state" + str(tsmem.output_state)) + continue + log('**Package: ' + tsmem.name + ' to be removed') smeevent = tsmem.name + '-update' - #only for debug - #log(smeevent) if os.path.isdir(events_path + os.sep + smeevent): tmppath = events_path + os.sep + smeevent + os.sep eventlist[tsmem.name] = smeevent @@ -147,8 +174,7 @@ mytmptemplate = os.path.join(subdir, file).replace(tmppathtmpl,os.sep) if not templateslist.has_key(mytmptemplate): templateslist[mytmptemplate]=mytmptemplate - #tmptmplpath = subdir + os.sep + file - log(" template " + file) + log(" template " + mytmptemplate) # nothing for actions ??? @@ -173,12 +199,29 @@ else: if (n.startswith('smeserver') or n.startswith('e-smith')) and not n.startswith('smeserver-locale'): smechange = True + smechangelist[n]=str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) + log("smechange set to True because of " + n + " with " + str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) ) #only for debug log('## smechange: '+str(smechange)) log('## eventlist: '+ str(eventlist.keys())) log('## templateslist: '+str(templateslist.keys())) - log('## serviceslist: '+str(serviceslist.keys())) + log('## serviceslist: '+str(serviceslist.items())) + log('## smechangelist: ' + str(smechangelist.keys())) + + # would it be a good idea to do some action/event there to stop service being removed ? + # create an empty temp event + print "Creating temporary event 'temp' and populating it..." + createevent() + if len(serviceslist)>0: + print " Adding services to adjust" + for kservices in serviceslist: + log(" " + kservices + ": " + serviceslist[kservices]) + os.symlink(serviceslist[kservices], '/etc/e-smith/events/temp/services2adjust/' + kservices) + + # execute the event ; should we really wait ?? + print "Executing signal-event temp before uninstalling ..........." + os.spawnl(os.P_WAIT,signal_event,signal_event, 'temp') def posttrans_hook(conduit): report_yum_status('posttrans') @@ -188,8 +231,6 @@ global smechange global eventlist global actionlist - global actionlistpre - global actionlistpost global templateslist global serviceslist global erasing @@ -197,42 +238,34 @@ for tsmem in ts.getMembers(): (n, a, e, v, r) = tsmem.po.pkgtup - #print 'smechange: '+str(smechange) # we're upgrading/installing/removing a rebootpkgs package.. a reboot is required for pkg in rebootpkgs: if n.startswith(pkg): log('**Package: ' + tsmem.name + ' triggers reboot') - #smechange = True # we do some exclusions -devel -doc ... if pkg in rebootpkgsexclude: - #print 'lista' cont=False for name in rebootpkgsexclude[pkg]: - #print name if n.startswith(pkg + name): - #print pkg + name + ' => smechange' cont=True - #smechange = True if cont: # this is an exception we do not need reboot : -devel, -doc ... continue # either no exception or does not fit exceptions: we need reboot smechange = True + smechangelist[n]=str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) + log("smechange set to True because of " + n + " with " + str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state)) + #log("smechange set to True because of " + pkg) # check if we're upgrading a restartpkgs rpm for pkg in restartpkgs: - #print pkg if n.startswith(pkg): if pkg in servicenames: - #print 'lista' for name in servicenames[pkg]: - #print name if not serviceslist.has_key(name): serviceslist[name] = 'restart' else: - #only for debug - #print pkg if not serviceslist.has_key(pkg): serviceslist[pkg] = 'restart' @@ -244,7 +277,6 @@ # if not smechange and not erasing: if True: - #smeevent = 'yum-reconfigure-' + tsmem.name smeevent = tsmem.name + '-update' if os.path.isdir(events_path + os.sep + smeevent): tmppath = events_path + os.sep + smeevent + os.sep @@ -256,19 +288,8 @@ mytmpaction = os.path.realpath(os.readlink(tmppath + f).replace("..",events_path)) #log(" link " + f + ": " + mytmpaction) + actionlist[f]=mytmpaction - if f < "S05generic_template_expand": - if not actionlistpre.has_key(mytmpaction): - actionlistpre[mytmpaction] = mytmpaction - log(" action Pre : " + f + " -> " + mytmpaction) - elif f > "S90adjust-services": - if not actionlistpost.has_key(mytmpaction): - actionlistpost[mytmpaction] = mytmpaction - log(" action Post : " + f + " -> " + mytmpaction) - else: - if not actionlist.has_key(mytmpaction): - actionlist[mytmpaction] = mytmpaction - log(" action : " + f + " -> " + mytmpaction) if os.path.isdir(tmppath + "templates2expand" + os.sep): tmppathtmpl = tmppath + "templates2expand" + os.sep @@ -277,7 +298,6 @@ mytmptemplate = os.path.join(subdir, file).replace(tmppathtmpl,os.sep) if not templateslist.has_key(mytmptemplate): templateslist[mytmptemplate]=mytmptemplate - #tmptmplpath = subdir + os.sep + file log(" template " + mytmptemplate) if os.path.isdir(tmppath + "services2adjust" + os.sep): @@ -298,18 +318,16 @@ else: if (n.startswith('smeserver') or n.startswith('e-smith')) and not n.startswith('smeserver-locale'): smechange = True - + smechangelist[n]=str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) + log("smechange set to True because of " + n + " with " + str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) ) #only for debug log('## smechange: '+str(smechange)) - #print 'post-trans' log('## eventlist: '+ str(eventlist)) - log('## actions early: ' + str(actionlistpre.keys())) log('## templateslist: '+str(templateslist.keys())) - log('## actions: ' + str(actionlist.keys())) - log('## serviceslist: '+str(serviceslist.keys())) - log('## actions late: ' + str(actionlistpost.keys())) - + log('## serviceslist: '+str(serviceslist.items())) + log('## actions ALL: ' + str(actionlist.keys())) + log('## smechangelist: ' + str(smechangelist.keys())) # check if smechange is true or if eventlist has items.. in both cases we must initialize databases if smechange == True or len(eventlist)>0: @@ -317,62 +335,58 @@ os.spawnl(os.P_WAIT, initialize_database, initialize_database) # just in case we add systemd-default and systemd-reload - if not actionlist.has_key('/etc/e-smith/events/actions/systemd-default'): - actionlist['/etc/e-smith/events/actions/systemd-default'] = '/etc/e-smith/events/actions/systemd-default' - if not actionlist.has_key('/etc/e-smith/events/actions/systemd-reload'): - actionlist['/etc/e-smith/events/actions/systemd-reload'] = '/etc/e-smith/events/actions/systemd-reload' - - # now, if smechange is false (no reboot needed), we can execute actions, expan templates and adjust services - #if not smechange: - - if len(actionlistpre)>0: - print "Executing early actions" - for kactions in actionlistpre: - log(" " + kactions) - if os.path.isfile(kactions): - os.spawnl(os.P_WAIT, kactions, kactions) + if not actionlist.has_key('S88systemd-default'): + actionlist['S88systemd-default'] = '/etc/e-smith/events/actions/systemd-default' + if not actionlist.has_key('S89systemd-reload'): + actionlist['S89systemd-reload'] = '/etc/e-smith/events/actions/systemd-reload' + + # now, if smechange is false (no reboot needed), we can execute actions, expand templates and adjust services + + # create an empty temp event + print "Creating temporary event 'temp' and populating it..." + createevent() + + # fill it with our list of actions + if len(actionlist)>0: + print " Adding actions to execute" + for kactions in actionlist: + log(" " + kactions) + if os.path.isfile(actionlist[kactions]): + os.symlink(actionlist[kactions],'/etc/e-smith/events/temp/' + kactions) + # fill it with our list of templates to expand if len(templateslist)>0: - print "Expanding templates" + print " Adding templates to expand" for ktemplates in templateslist: - log(" " + ktemplates) + log(" " + ktemplates) mytemplatedir = '/etc/e-smith/templates/' + ktemplates mytemplatemeta = '/etc/e-smith/templates.metadata/' + ktemplates if os.path.exists(mytemplatedir) or os.path.exists(mytemplatemeta): - os.spawnl(os.P_WAIT, expand_template, expand_template, ktemplates) - - if len(actionlist)>0: - print "Executing actions" - for kactions in actionlist: - log(" " + kactions) - if os.path.isfile(kactions): - os.spawnl(os.P_WAIT, kactions, kactions,"post-upgrade") + addtemplate2expand(ktemplates) if len(serviceslist)>0: - print "Adjusting services" + print " Adding services to adjust" for kservices in serviceslist: - print kservices + ": " + serviceslist[kservices] - os.spawnl(os.P_WAIT, service, service, kservices, serviceslist[kservices]) + log(" " + kservices + ": " + serviceslist[kservices]) + os.symlink(serviceslist[kservices], '/etc/e-smith/events/temp/services2adjust/' + kservices) - if len(actionlistpost)>0: - print "Executing late actions" - for kactions in actionlistpost: - log(" " + kactions) - if os.path.isfile(kactions): - os.spawnl(os.P_WAIT, kactions, kactions) + # execute the event ; should we really wait ?? + print "Executing signal-event temp ..........." + os.spawnl(os.P_WAIT,signal_event,signal_event, 'temp') if smechange: os.spawnl(os.P_WAIT, config_set, config_set, 'set', 'UnsavedChanges', 'yes') os.spawnl(os.P_WAIT, navigation_conf, navigation_conf) + syslog.syslog('Needs signal-event post-upgrade; signal-event reboot because of: ' + str(smechangelist.keys()) ) print "Reload yum db for server-manager" os.spawnl(os.P_WAIT, systemctl, systemctl, 'restart', 'yum') def close_hook(conduit): if ourfile and os.path.isfile('/var/run/yum.status'): os.unlink('/var/run/yum.status') - log("***Close***") if smechange: + print "\nThe following rpms urge the need of a reboot:\n" + str(smechangelist.keys()) print "\n==============================================================" print "WARNING: You now need to run BOTH of the following commands" print "to ensure consistent system state:\n"