/[smeserver]/rpms/smeserver-yum/sme10/smeserver-yum-2.6.0-bz11300-improve-postupdate-events.patch
ViewVC logotype

Annotation of /rpms/smeserver-yum/sme10/smeserver-yum-2.6.0-bz11300-improve-postupdate-events.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Mon Jul 11 15:20:20 2022 UTC (2 years, 3 months ago) by jpp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
bump version

1 jpp 1.1 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
2     --- smeserver-yum-2.6.0.old/root/usr/lib/yum-plugins/smeserver.py 2021-02-15 17:05:10.702000000 -0500
3     +++ smeserver-yum-2.6.0/root/usr/lib/yum-plugins/smeserver.py 2021-02-15 17:07:34.080000000 -0500
4     @@ -1,6 +1,9 @@
5     # vim: noexpandtab tabstop=4
6    
7     import os
8     +import shutil
9     +import subprocess
10     +import syslog
11     from yum.constants import *
12     from yum.plugins import PluginYumExit
13     from yum.plugins import TYPE_CORE
14     @@ -21,8 +24,6 @@
15    
16     eventlist = dict()
17     actionlist = dict()
18     -actionlistpre = dict()
19     -actionlistpost = dict()
20     templateslist = dict()
21     serviceslist = dict()
22    
23     @@ -62,13 +63,35 @@
24     servicenames['qpsmtpd']='qpsmtpd'
25    
26     smechange = False
27     +smechangelist = dict()
28     ourfile = False
29     erasing = False
30     DEBUG = False
31    
32     def log(s):
33     - if DEBUG:
34     + if DEBUG :
35     print s
36     +def createevent():
37     + if os.path.isdir('/etc/e-smith/events/temp'):
38     + shutil.rmtree('/etc/e-smith/events/temp')
39     + os.makedirs('/etc/e-smith/events/temp/services2adjust', 0o777)
40     + os.makedirs('/etc/e-smith/events/temp/templates2expand', 0o777)
41     +
42     +def addtemplate2expand(template):
43     + #check filename
44     + head_tail = os.path.split(template)
45     + head = head_tail[0];
46     + filename = head_tail[1];
47     + # create dir
48     + if not os.path.isdir('/etc/e-smith/events/temp/templates2expand' + head):
49     + os.makedirs('/etc/e-smith/events/temp/templates2expand' + head, 0o777)
50     + #touch file
51     + fname= '/etc/e-smith/events/temp/templates2expand'+ template
52     + fhandle = open(fname, 'a')
53     + try:
54     + os.utime(fname, None)
55     + finally:
56     + fhandle.close()
57    
58     def report_yum_status(status):
59     fileHandle = open(status_file, 'w')
60     @@ -100,6 +123,7 @@
61     report_yum_status('postresolve')
62    
63     def pretrans_hook(conduit):
64     +# we might need to change the strategy here to make a difference between update and removal.
65     #transaction set states
66     #TS_UPDATE = 10
67     #TS_INSTALL = 20
68     @@ -122,20 +146,23 @@
69     global smechange
70     global eventlist
71     global actionlist
72     - global actionlistpre
73     - global actionlistpost
74     global templateslist
75     global serviceslist
76     global erasing
77    
78     + # reinstall are not listed there so already skipped
79     + # downgrade are going there
80     + # update are going there, we filter them out
81     + # real removal are the real deal there ; downgrade are played like if they were removal
82     for tsmem in removes:
83     erasing = True
84     (n, a, e, v, r) = tsmem.po.pkgtup
85     - #only for debug
86     - log('**Package: ' + tsmem.name + ' remove')
87     + if tsmem.output_state == TS_UPDATED :
88     + # if we are actually updating then we are not removing, and new package will do better... skipping
89     + log('skiping as updating ==> state ' + str(tsmem.po.state) + " RPM current state" + str(tsmem.current_state) + " RPM output state" + str(tsmem.output_state))
90     + continue
91     + log('**Package: ' + tsmem.name + ' to be removed')
92     smeevent = tsmem.name + '-update'
93     - #only for debug
94     - #log(smeevent)
95     if os.path.isdir(events_path + os.sep + smeevent):
96     tmppath = events_path + os.sep + smeevent + os.sep
97     eventlist[tsmem.name] = smeevent
98     @@ -147,8 +174,7 @@
99     mytmptemplate = os.path.join(subdir, file).replace(tmppathtmpl,os.sep)
100     if not templateslist.has_key(mytmptemplate):
101     templateslist[mytmptemplate]=mytmptemplate
102     - #tmptmplpath = subdir + os.sep + file
103     - log(" template " + file)
104     + log(" template " + mytmptemplate)
105    
106     # nothing for actions ???
107    
108     @@ -173,12 +199,29 @@
109     else:
110     if (n.startswith('smeserver') or n.startswith('e-smith')) and not n.startswith('smeserver-locale'):
111     smechange = True
112     + smechangelist[n]=str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state)
113     + log("smechange set to True because of " + n + " with " + str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) )
114    
115     #only for debug
116     log('## smechange: '+str(smechange))
117     log('## eventlist: '+ str(eventlist.keys()))
118     log('## templateslist: '+str(templateslist.keys()))
119     - log('## serviceslist: '+str(serviceslist.keys()))
120     + log('## serviceslist: '+str(serviceslist.items()))
121     + log('## smechangelist: ' + str(smechangelist.keys()))
122     +
123     + # would it be a good idea to do some action/event there to stop service being removed ?
124     + # create an empty temp event
125     + print "Creating temporary event 'temp' and populating it..."
126     + createevent()
127     + if len(serviceslist)>0:
128     + print " Adding services to adjust"
129     + for kservices in serviceslist:
130     + log(" " + kservices + ": " + serviceslist[kservices])
131     + os.symlink(serviceslist[kservices], '/etc/e-smith/events/temp/services2adjust/' + kservices)
132     +
133     + # execute the event ; should we really wait ??
134     + print "Executing signal-event temp before uninstalling ..........."
135     + os.spawnl(os.P_WAIT,signal_event,signal_event, 'temp')
136    
137     def posttrans_hook(conduit):
138     report_yum_status('posttrans')
139     @@ -188,8 +231,6 @@
140     global smechange
141     global eventlist
142     global actionlist
143     - global actionlistpre
144     - global actionlistpost
145     global templateslist
146     global serviceslist
147     global erasing
148     @@ -197,42 +238,34 @@
149    
150     for tsmem in ts.getMembers():
151     (n, a, e, v, r) = tsmem.po.pkgtup
152     - #print 'smechange: '+str(smechange)
153    
154     # we're upgrading/installing/removing a rebootpkgs package.. a reboot is required
155     for pkg in rebootpkgs:
156     if n.startswith(pkg):
157     log('**Package: ' + tsmem.name + ' triggers reboot')
158     - #smechange = True
159     # we do some exclusions -devel -doc ...
160     if pkg in rebootpkgsexclude:
161     - #print 'lista'
162     cont=False
163     for name in rebootpkgsexclude[pkg]:
164     - #print name
165     if n.startswith(pkg + name):
166     - #print pkg + name + ' => smechange'
167     cont=True
168     - #smechange = True
169     if cont:
170     # this is an exception we do not need reboot : -devel, -doc ...
171     continue
172     # either no exception or does not fit exceptions: we need reboot
173     smechange = True
174     + smechangelist[n]=str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state)
175     + log("smechange set to True because of " + n + " with " + str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state))
176     + #log("smechange set to True because of " + pkg)
177    
178     # check if we're upgrading a restartpkgs rpm
179     for pkg in restartpkgs:
180     - #print pkg
181     if n.startswith(pkg):
182     if pkg in servicenames:
183     - #print 'lista'
184     for name in servicenames[pkg]:
185     - #print name
186     if not serviceslist.has_key(name):
187     serviceslist[name] = 'restart'
188     else:
189     - #only for debug
190     - #print pkg
191     if not serviceslist.has_key(pkg):
192     serviceslist[pkg] = 'restart'
193    
194     @@ -244,7 +277,6 @@
195     # if not smechange and not erasing:
196     if True:
197    
198     - #smeevent = 'yum-reconfigure-' + tsmem.name
199     smeevent = tsmem.name + '-update'
200     if os.path.isdir(events_path + os.sep + smeevent):
201     tmppath = events_path + os.sep + smeevent + os.sep
202     @@ -256,19 +288,8 @@
203    
204     mytmpaction = os.path.realpath(os.readlink(tmppath + f).replace("..",events_path))
205     #log(" link " + f + ": " + mytmpaction)
206     + actionlist[f]=mytmpaction
207    
208     - if f < "S05generic_template_expand":
209     - if not actionlistpre.has_key(mytmpaction):
210     - actionlistpre[mytmpaction] = mytmpaction
211     - log(" action Pre : " + f + " -> " + mytmpaction)
212     - elif f > "S90adjust-services":
213     - if not actionlistpost.has_key(mytmpaction):
214     - actionlistpost[mytmpaction] = mytmpaction
215     - log(" action Post : " + f + " -> " + mytmpaction)
216     - else:
217     - if not actionlist.has_key(mytmpaction):
218     - actionlist[mytmpaction] = mytmpaction
219     - log(" action : " + f + " -> " + mytmpaction)
220    
221     if os.path.isdir(tmppath + "templates2expand" + os.sep):
222     tmppathtmpl = tmppath + "templates2expand" + os.sep
223     @@ -277,7 +298,6 @@
224     mytmptemplate = os.path.join(subdir, file).replace(tmppathtmpl,os.sep)
225     if not templateslist.has_key(mytmptemplate):
226     templateslist[mytmptemplate]=mytmptemplate
227     - #tmptmplpath = subdir + os.sep + file
228     log(" template " + mytmptemplate)
229    
230     if os.path.isdir(tmppath + "services2adjust" + os.sep):
231     @@ -298,18 +318,16 @@
232     else:
233     if (n.startswith('smeserver') or n.startswith('e-smith')) and not n.startswith('smeserver-locale'):
234     smechange = True
235     -
236     + smechangelist[n]=str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state)
237     + log("smechange set to True because of " + n + " with " + str(tsmem.po.state) + " " + str(tsmem.current_state) + " " + str(tsmem.output_state) )
238    
239     #only for debug
240     log('## smechange: '+str(smechange))
241     - #print 'post-trans'
242     log('## eventlist: '+ str(eventlist))
243     - log('## actions early: ' + str(actionlistpre.keys()))
244     log('## templateslist: '+str(templateslist.keys()))
245     - log('## actions: ' + str(actionlist.keys()))
246     - log('## serviceslist: '+str(serviceslist.keys()))
247     - log('## actions late: ' + str(actionlistpost.keys()))
248     -
249     + log('## serviceslist: '+str(serviceslist.items()))
250     + log('## actions ALL: ' + str(actionlist.keys()))
251     + log('## smechangelist: ' + str(smechangelist.keys()))
252    
253     # check if smechange is true or if eventlist has items.. in both cases we must initialize databases
254     if smechange == True or len(eventlist)>0:
255     @@ -317,62 +335,58 @@
256     os.spawnl(os.P_WAIT, initialize_database, initialize_database)
257    
258     # just in case we add systemd-default and systemd-reload
259     - if not actionlist.has_key('/etc/e-smith/events/actions/systemd-default'):
260     - actionlist['/etc/e-smith/events/actions/systemd-default'] = '/etc/e-smith/events/actions/systemd-default'
261     - if not actionlist.has_key('/etc/e-smith/events/actions/systemd-reload'):
262     - actionlist['/etc/e-smith/events/actions/systemd-reload'] = '/etc/e-smith/events/actions/systemd-reload'
263     -
264     - # now, if smechange is false (no reboot needed), we can execute actions, expan templates and adjust services
265     - #if not smechange:
266     -
267     - if len(actionlistpre)>0:
268     - print "Executing early actions"
269     - for kactions in actionlistpre:
270     - log(" " + kactions)
271     - if os.path.isfile(kactions):
272     - os.spawnl(os.P_WAIT, kactions, kactions)
273     + if not actionlist.has_key('S88systemd-default'):
274     + actionlist['S88systemd-default'] = '/etc/e-smith/events/actions/systemd-default'
275     + if not actionlist.has_key('S89systemd-reload'):
276     + actionlist['S89systemd-reload'] = '/etc/e-smith/events/actions/systemd-reload'
277     +
278     + # now, if smechange is false (no reboot needed), we can execute actions, expand templates and adjust services
279     +
280     + # create an empty temp event
281     + print "Creating temporary event 'temp' and populating it..."
282     + createevent()
283     +
284     + # fill it with our list of actions
285     + if len(actionlist)>0:
286     + print " Adding actions to execute"
287     + for kactions in actionlist:
288     + log(" " + kactions)
289     + if os.path.isfile(actionlist[kactions]):
290     + os.symlink(actionlist[kactions],'/etc/e-smith/events/temp/' + kactions)
291    
292     + # fill it with our list of templates to expand
293     if len(templateslist)>0:
294     - print "Expanding templates"
295     + print " Adding templates to expand"
296     for ktemplates in templateslist:
297     - log(" " + ktemplates)
298     + log(" " + ktemplates)
299     mytemplatedir = '/etc/e-smith/templates/' + ktemplates
300     mytemplatemeta = '/etc/e-smith/templates.metadata/' + ktemplates
301     if os.path.exists(mytemplatedir) or os.path.exists(mytemplatemeta):
302     - os.spawnl(os.P_WAIT, expand_template, expand_template, ktemplates)
303     -
304     - if len(actionlist)>0:
305     - print "Executing actions"
306     - for kactions in actionlist:
307     - log(" " + kactions)
308     - if os.path.isfile(kactions):
309     - os.spawnl(os.P_WAIT, kactions, kactions,"post-upgrade")
310     + addtemplate2expand(ktemplates)
311    
312     if len(serviceslist)>0:
313     - print "Adjusting services"
314     + print " Adding services to adjust"
315     for kservices in serviceslist:
316     - print kservices + ": " + serviceslist[kservices]
317     - os.spawnl(os.P_WAIT, service, service, kservices, serviceslist[kservices])
318     + log(" " + kservices + ": " + serviceslist[kservices])
319     + os.symlink(serviceslist[kservices], '/etc/e-smith/events/temp/services2adjust/' + kservices)
320    
321     - if len(actionlistpost)>0:
322     - print "Executing late actions"
323     - for kactions in actionlistpost:
324     - log(" " + kactions)
325     - if os.path.isfile(kactions):
326     - os.spawnl(os.P_WAIT, kactions, kactions)
327     + # execute the event ; should we really wait ??
328     + print "Executing signal-event temp ..........."
329     + os.spawnl(os.P_WAIT,signal_event,signal_event, 'temp')
330    
331     if smechange:
332     os.spawnl(os.P_WAIT, config_set, config_set, 'set', 'UnsavedChanges', 'yes')
333     os.spawnl(os.P_WAIT, navigation_conf, navigation_conf)
334     + syslog.syslog('Needs signal-event post-upgrade; signal-event reboot because of: ' + str(smechangelist.keys()) )
335     print "Reload yum db for server-manager"
336     os.spawnl(os.P_WAIT, systemctl, systemctl, 'restart', 'yum')
337    
338     def close_hook(conduit):
339     if ourfile and os.path.isfile('/var/run/yum.status'):
340     os.unlink('/var/run/yum.status')
341     - log("***Close***")
342    
343     if smechange:
344     + print "\nThe following rpms urge the need of a reboot:\n" + str(smechangelist.keys())
345     print "\n=============================================================="
346     print "WARNING: You now need to run BOTH of the following commands"
347     print "to ensure consistent system state:\n"

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed