/[smeserver]/rpms/e-smith-base/sme10/e-smith-base-5.8.0-bz11231-systemd-preset-all-workaround.patch
ViewVC logotype

Annotation of /rpms/e-smith-base/sme10/e-smith-base-5.8.0-bz11231-systemd-preset-all-workaround.patch

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


Revision 1.4 - (hide annotations) (download)
Sun Jun 6 20:38:29 2021 UTC (3 years, 4 months ago) by jpp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
FILE REMOVED
5.8.1

1 jpp 1.1 diff -Nur e-smith-base-5.8.0.old/root/etc/e-smith/events/actions/systemd-default e-smith-base-5.8.0/root/etc/e-smith/events/actions/systemd-default
2     --- e-smith-base-5.8.0.old/root/etc/e-smith/events/actions/systemd-default 2020-12-05 22:56:11.568000000 -0500
3     +++ e-smith-base-5.8.0/root/etc/e-smith/events/actions/systemd-default 2020-12-05 23:22:36.254000000 -0500
4     @@ -1,5 +1,208 @@
5     -#!/usr/bin/bash
6     -/usr/bin/systemctl enable sme-server.target
7     -ln -fs sme-server.target /lib/systemd/system/default.target
8     -/usr/bin/systemctl preset-all
9     -/usr/bin/systemctl set-default sme-server.target
10     +#!/usr/bin/perl -w
11     +
12     +use strict;
13     +use Errno;
14     +use esmith::ConfigDB;
15     +use File::Temp;
16     +use esmith::templates;
17     +use File::Basename;
18     +use Cwd 'abs_path';
19     +
20     +my $conf = esmith::ConfigDB->open_ro;
21     +
22     +
23     +my $event = $ARGV [0];
24     +my $second = $ARGV [1];
25     +
26     +my @servicedirpaths = ("/usr/lib/systemd/system/","/etc/systemd/system/");
27     +my @presetdirpaths = ("/usr/lib/systemd/system-preset/","/etc/systemd/system-preset/");
28     +my $filename = "/etc/systemd/system-preset/49-koozali.preset";
29     +my %services;
30     +my %files;
31     +my @WantedBy;
32     +
33     +# make sure our target is enabled
34     +system("/usr/bin/systemctl enable sme-server.target");
35     +# force the main default target in /usr/lib
36     +#ln -fs sme-server.target /lib/systemd/system/default.target
37     +my $old_qfn = "sme-server.target";
38     +my $new_qfn = "/lib/systemd/system/default.target";
39     +if (!symlink($old_qfn, $new_qfn)) {
40     + if ($!{EEXIST}) {
41     + unlink($new_qfn)
42     + or die("Can't remove \"$new_qfn\": $!\n");
43     + symlink($old_qfn, $new_qfn)
44     + or die("Can't create symlink \"$new_qfn\": $!\n");
45     + } else {
46     + die("Can't create symlink \"$new_qfn\": $!\n");
47     + }
48     +}
49     +# we let the dedicated systemd command tryin to do what we will do later in this script
50     +# as up to systemd 236 it is bugged see:
51     +# https://github.com/systemd/systemd/pull/7158 and https://github.com/systemd/systemd/pull/7289
52     +system("/usr/bin/systemctl preset-all");
53     +# in case preset-all messed up with our default target
54     +system("/usr/bin/systemctl set-default sme-server.target");
55     +
56     +
57     +#warn "expanding $filename\n";
58     +esmith::templates::processTemplate({
59     + MORE_DATA => { },
60     + TEMPLATE_PATH => $filename,
61     + OUTPUT_FILENAME => $filename,
62     + });
63     +
64     +# list both preset directories
65     +# seek files to be removed from usr/lib if same basename exist
66     +foreach my $d (@presetdirpaths) {
67     + opendir my $dir, "$d" or die "Cannot open directory: $!";
68     + my @dirfiles = readdir $dir;
69     + closedir $dir;
70     + foreach my $fi (@dirfiles) {
71     + next unless ($fi =~ /.preset$/);
72     + $files{$fi}="$d$fi"
73     + }
74     +}
75     +
76     +# list wanted services in the sme-server.target
77     +#Wants=acpid.service atd.service auditd.service avahi-daemon.service brandbot.path crond.service irqbalance.service nfs-client.target remote-fs.target rhel-configure.service rsyslog.service smartd.service yum-cron.service
78     +my $smewants = `grep -P '^Wants=' /usr/lib/systemd/system/sme-server.target -rs`;
79     +chomp $smewants;
80     +my @smematches = ( $smewants =~ /([a-zA-Z0-9\-_]+\.service)/g );
81     +
82     +
83     +# parse all files on reverse order : lower number take precedence
84     +# we ignore joker lines *
85     +# we ignore @ lines
86     +# we ignore multiple in one line
87     +# our default at the end is to disable if not listed
88     +foreach my $filen (reverse sort keys %files) {
89     +#print "==============> $filen : ".$files{$filen} ."\n";
90     + # parsing $filename content
91     + # should end with hash with 2 possible value : enable and disable
92     + # ignore lines starting with # or empty character
93     + open(FILE, '<', $files{$filen}) or die $!;
94     + while (<FILE>) {
95     + chomp; # remove newlines
96     + next if (/^\s+$/);
97     + next if (/^#/);
98     + s/^\s+//; # remove leading whitespace
99     + s/\s+$//; # remove trailing whitespace
100     + next unless length; # next rec unless anything left
101     +# print $_ ."\n";
102     + next unless (/^(enable|disable)\s+([a-zA-Z0-9\-_.@]+\.service)/);
103     +# print $_ ."\n";
104     + #ignore service that does not exists !
105     + next unless ( -e "/usr/lib/systemd/system/$2" or -e "/etc/lib/systemd/system/$2" );
106     + # eliminate duplicates, this way we keep only the last entry of the lowest file as we do it in reverse order of file,
107     + # but from top to bottom of file.
108     + $services{$2}=$1;
109     +
110     + # list all Services explicitely listed in preset that are also in Wants= or with WantedBy= sme-server.target
111     + my $service=$2;
112     + next if (/^$service$/ ~~ @WantedBy);
113     + if ( /^$service$/ ~~ @smematches ) {
114     + push(@WantedBy, $service);
115     + #print "want $service \n";
116     + }
117     + else {
118     + my $wanted = `grep -P '^WantedBy=.*sme-server.target' /usr/lib/systemd/system/$service* /etc/systemd/system/$service* -rsh` ;
119     + chomp $wanted;
120     + push(@WantedBy , $service) unless ( $wanted eq "") ;
121 jpp 1.2 + #print "want $service \n" unless ( $wanted eq "") ;
122 jpp 1.1 + }
123     +
124     + }
125     +}
126     +
127     +# then check content of /etc/systemd/system/sme-server.target.wants/
128     +# remove what is not in enable
129     +my $d = "/etc/systemd/system/sme-server.target.wants/";
130     +opendir my $dir, "$d" or die "Cannot open directory: $!";
131     +my @dirfiles = readdir $dir;
132     +closedir $dir;
133     +foreach my $fi (@dirfiles) {
134     + # we ignore . and ..
135     + next if $fi =~ /\.+$/;
136     + # for the moment we only consider service files and ignore target, mount, device, socket...
137     + next unless ($fi =~ /.service$/);
138     + # remove if file but not a link
139     + print "remove $d$fi : not a link\n" unless ( -l "$d$fi");
140     + unlink "$d$fi" unless ( -l "$d$fi");
141     + # remove if link is not to an existing file
142     + my $absFilePath = abs_path("$d$fi") ;
143     + print "remove $d$fi target '$absFilePath' does not exist or is not regular file\n" unless ( -f "$absFilePath");
144     + unlink "$d$fi" unless ( -f "$absFilePath");
145     + # is not enable in preset : remove
146     + #print "==$fi \n";
147     + if ( ! defined $services{$fi} or $services{$fi} ne "enable") {
148     + print "remove $d$fi as not enabled in preset\n";
149     + unlink "$d$fi";
150     + }
151     + # if not wanted remove
152     + unless ( /^$fi$/ ~~ @WantedBy) {
153     + print "remove $d$fi as not declared as WantedBy or in Wants for sme-server.target\n";
154     + unlink "$d$fi";
155     + }
156     +}
157     +
158     +
159     +# and we add wanted enabled services
160     +# we only do it for sme-server.target, ignoring the remaining of WantedBy
161     +foreach my $service (sort keys %services) {
162     + my $wanted= "not";
163     + $wanted = "want" if ( /^$service$/ ~~ @WantedBy );
164     + my $status = $services{$service};
165     + my $linkedU = ( -e "/usr/lib/systemd/system/sme-server.target.wants/$service" ) ? "linked" : "not";
166     + my $linkedE = ( -e "/etc/systemd/system/sme-server.target.wants/$service" ) ? "linked" : "not";
167     + my $linkedD = ( -e "/etc/systemd/system/default.target.wants/$service" or -e "/usr/lib/systemd/system/default.target.wants/$service" ) ? "linked" : "not";
168     + my $add = ($linkedU eq "not" and $linkedE eq "not" and $linkedD eq "not" and $status eq "enable" and $wanted eq "want") ? "ADDME!!" : "";
169     + ## adding link if needed in /etc/systemd/system/sme-server.target.wants
170     + if ( $status eq "enable" and $linkedU eq "not" and $linkedE eq "not" and $linkedD eq "not" and $wanted eq "want"){
171     + print "systemctl add-wants sme-server.target $service\n";
172     + `systemctl add-wants sme-server.target $service `;
173     + }
174     +}
175     +
176     +
177     +
178     +# do something about /usr/lib/systemd/system/sme-server.target.wants/
179     +# we check for rpm owned and not rpm owned
180     +# we only inform there, we do not do anything else
181     +$d = "/usr/lib/systemd/system/sme-server.target.wants/";
182     +opendir $dir, "$d" or die "Cannot open directory: $!";
183     +@dirfiles = readdir $dir;
184     +closedir $dir;
185     +foreach my $fi (@dirfiles) {
186     + # we ignore . and ..
187     + next if $fi =~ /\.+$/;
188     + # for the moment we only consider service files and ignore target, mount, device, socket...
189     + next unless ($fi =~ /.service$/);
190     + # remove if file but not a link
191     + print "$d$fi is not a link\n" unless ( -l "$d$fi");
192     + # remove if link is not to an existing file
193     + my $absFilePath = abs_path("$d$fi") ;
194     + print "$d$fi target '$absFilePath' does not exist or is not regular file\n" unless ( -f "$absFilePath");
195     + # check if owned by rpm
196     + my $rpmowned = `rpm -qf $d$fi`;
197     + chomp $rpmowned;
198     + if ($rpmowned ne "" ) {
199     + #print "$d$fi is owned by $rpmowned\n";
200     + #next;
201     + } else {
202     + print "$d$fi has been manually added\n";
203     + }
204     + if ( ! defined $services{$fi} or $services{$fi} ne "enable") {
205     + print "$d$fi is not enabled in preset\n";
206     + }
207     + # if not wanted remove
208     + # need to check its own files also here
209     + my $service = $fi;
210     + my $wanted = `grep -P '^WantedBy=.*sme-server.target' /usr/lib/systemd/system/$service* /etc/systemd/system/$service* -rsh` ;
211     + chomp $wanted;
212     + #unless ( /^$fi$/ ~~ @WantedBy ) {
213     + unless (grep(/^$fi$/, @WantedBy ) ) {
214     + print "$d$fi is not declared as WantedBy or in Wants for sme-server.target\n";
215     + }
216     +}
217     +
218     diff -Nur e-smith-base-5.8.0.old/root/etc/e-smith/templates/etc/systemd/system-preset/49-koozali.preset/20services e-smith-base-5.8.0/root/etc/e-smith/templates/etc/systemd/system-preset/49-koozali.preset/20services
219     --- e-smith-base-5.8.0.old/root/etc/e-smith/templates/etc/systemd/system-preset/49-koozali.preset/20services 2020-12-05 22:56:11.611000000 -0500
220     +++ e-smith-base-5.8.0/root/etc/e-smith/templates/etc/systemd/system-preset/49-koozali.preset/20services 2020-12-05 23:27:36.869000000 -0500
221     @@ -12,7 +12,7 @@
222     $status = "disable" if -e "/etc/rc.d/init.d/".$service->key || -e "/etc/rc.d/init.d/supervise/".$service->key;
223     }
224     $OUT .= "# Systemd service file does not exist : " unless -e "/usr/lib/systemd/system/$servicename" || -e "/etc/lib/systemd/system/$servicename";
225     - $OUT .= "$status $servicename\n";
226     + $OUT .= "$status $servicename\n";
227    
228     }
229    
230     diff -Nur e-smith-base-5.8.0.old/root/usr/lib/systemd/system/bootstrap-console.service e-smith-base-5.8.0/root/usr/lib/systemd/system/bootstrap-console.service
231     --- e-smith-base-5.8.0.old/root/usr/lib/systemd/system/bootstrap-console.service 2020-12-05 22:56:11.447000000 -0500
232     +++ e-smith-base-5.8.0/root/usr/lib/systemd/system/bootstrap-console.service 2020-12-05 22:56:54.442000000 -0500
233     @@ -24,4 +24,4 @@
234    
235     [Install]
236     WantedBy=multi-user.target
237     -
238     +WantedBy=sme-server.target
239     diff -Nur e-smith-base-5.8.0.old/root/usr/lib/systemd/system/sme-server.target e-smith-base-5.8.0/root/usr/lib/systemd/system/sme-server.target
240     --- e-smith-base-5.8.0.old/root/usr/lib/systemd/system/sme-server.target 2020-12-05 22:56:11.555000000 -0500
241     +++ e-smith-base-5.8.0/root/usr/lib/systemd/system/sme-server.target 2020-12-05 23:09:13.423000000 -0500
242     @@ -1,4 +1,4 @@
243     -# This file is part of Koozali SME Server.
244     +# This file is part of Koozali SME Server.
245     #
246    
247     [Unit]
248     @@ -9,3 +9,8 @@
249     After=basic.target rescue.service rescue.target
250     AllowIsolate=yes
251     Wants=acpid.service atd.service auditd.service avahi-daemon.service brandbot.path crond.service irqbalance.service nfs-client.target remote-fs.target rhel-configure.service rsyslog.service smartd.service yum-cron.service
252     +Wants=dbus.service plymouth-quit-wait.service plymouth-quit.service systemd-logind.service systemd-update-utmp-runlevel.service systemd-user-sessions.service
253     +Wants=php-fpm.service php55-php-fpm.service php56-php-fpm.service php70-php-fpm.service php71-php-fpm.service php72-php-fpm.service php73-php-fpm.service php74-php-fpm.service
254     +Wants=runit.service bootstrap-console.service wan.service networking.service masq.service tinydns.service qpsmtpd.service sqpsmtpd.service qmail.service ftp.service dnscache.service dnscache.forwarder.service lpd.service dhcpd.service dovecot.service mariadb.service ntpd.service nut.service clamd.service freshclam.service httpd-admin.service httpd-e-smith.service ldap.service ldap.init.service local.service mysql.init.service spamd.service
255     +
256     +
257     diff -Nur e-smith-base-5.8.0.old/root/usr/lib/systemd/system-preset/50-koozali.preset e-smith-base-5.8.0/root/usr/lib/systemd/system-preset/50-koozali.preset
258     --- e-smith-base-5.8.0.old/root/usr/lib/systemd/system-preset/50-koozali.preset 1969-12-31 19:00:00.000000000 -0500
259     +++ e-smith-base-5.8.0/root/usr/lib/systemd/system-preset/50-koozali.preset 2020-12-05 23:25:48.139000000 -0500
260     @@ -0,0 +1,72 @@
261     +enable sme-server.target
262     +disable multi-user.target
263     +disable graphical.target
264     +
265     +enable dbus.service
266     +enable plymouth-quit-wait.service
267     +enable plymouth-quit.service
268     +enable systemd-logind.service
269     +enable systemd-update-utmp-runlevel.service
270     +enable systemd-user-sessions.service
271     +
272     +enable runit.service
273     +enable bootstrap-console.service
274     +enable networking.service
275     +enable wan.service
276     +enable masq.service
277     +enable php-fpm.service
278     +enable php55-php-fpm.service
279     +enable php56-php-fpm.service
280     +enable php70-php-fpm.service
281     +enable php71-php-fpm.service
282     +enable php72-php-fpm.service
283     +enable php73-php-fpm.service
284     +enable php74-php-fpm.service
285     +enable httpd-e-smith.service
286     +enable httpd-admin.service
287     +enable crond.service
288     +disable dhcpd.service
289     +enable dnscache.service
290     +enable dnscache.forwarder.service
291     +enable dovecot.service
292     +enable irqbalance.service
293     +disable isdn.service
294     +enable lpd.service
295     +enable ldap.service
296     +enable ldap.init.service
297     +enable local.service
298     +
299     +#need to change after integration
300     +#enable mariadb.service
301     +
302     +# need change after deciding service name
303     +# enable mdmonitor.service
304     +# enable raidmonitor.service
305     +
306     +enable ntpd.service
307     +disable nut.service
308     +disable oidentd.service
309     +disable pptpd.service
310     +enable qmail.service
311     +enable qpsmtpd.service
312     +disable radiusd.service
313     +enable raidmonitor.service
314     +enable rsyslog.service
315     +enable smartd.service
316     +
317     +#need to change after integration
318     +#enable smb.service
319     +#enable nmdb.service
320     +#enable smbd.service
321     +
322     +disable smtp-auth-proxy.service
323     +disable spamd.service
324     +disable sqpsmtpd.service
325     +disable squid.service
326     +disable sshd.service
327     +enable tinydns.service
328     +enable wan.service
329     +disable nut-server.service
330     +disable nut-monitor.service
331     +disable ntpdate.service
332     +
333     diff -Nur e-smith-base-5.8.0.old/root/usr/lib/systemd/system-preset/50koozali.preset e-smith-base-5.8.0/root/usr/lib/systemd/system-preset/50koozali.preset
334     --- e-smith-base-5.8.0.old/root/usr/lib/systemd/system-preset/50koozali.preset 2020-12-05 22:56:11.568000000 -0500
335     +++ e-smith-base-5.8.0/root/usr/lib/systemd/system-preset/50koozali.preset 1969-12-31 19:00:00.000000000 -0500
336     @@ -1,18 +0,0 @@
337     -enable sme-server.target
338     -disable multi-user.target
339     -disable graphical.target
340     -
341     -enable runit.service
342     -enable bootstrap-console.service
343     -enable networking.service
344     -enable wan.service
345     -enable masq.service
346     -enable php-fpm.service
347     -enable php55-php-fpm.service
348     -enable php56-php-fpm.service
349     -enable php70-php-fpm.service
350     -enable php71-php-fpm.service
351     -enable php72-php-fpm.service
352     -enable php73-php-fpm.service
353     -enable php74-php-fpm.service
354     -
355 jpp 1.3 diff -Nur e-smith-base-5.8.0.old/root/etc/e-smith/events/actions/systemd-default e-smith-base-5.8.0/root/etc/e-smith/events/actions/systemd-default
356     --- e-smith-base-5.8.0.old/root/etc/e-smith/events/actions/systemd-default 2020-12-06 16:08:47.304000000 -0500
357     +++ e-smith-base-5.8.0/root/etc/e-smith/events/actions/systemd-default 2020-12-06 16:08:55.969000000 -0500
358     @@ -109,7 +109,7 @@
359     my $wanted = `grep -P '^WantedBy=.*sme-server.target' /usr/lib/systemd/system/$service* /etc/systemd/system/$service* -rsh` ;
360     chomp $wanted;
361     push(@WantedBy , $service) unless ( $wanted eq "") ;
362     - #print "want $service \n" unless ( $wanted eq "") ;
363     + #print "want $service \n" unless ( $wanted eq "") ;
364     }
365    
366     }
367     @@ -127,17 +127,30 @@
368     # for the moment we only consider service files and ignore target, mount, device, socket...
369     next unless ($fi =~ /.service$/);
370     # remove if file but not a link
371     - print "remove $d$fi : not a link\n" unless ( -l "$d$fi");
372     - unlink "$d$fi" unless ( -l "$d$fi");
373     - # remove if link is not to an existing file
374     + unless ( -l "$d$fi") {
375     + print "remove $d$fi : not a link\n";
376     + unlink "$d$fi";
377     + next;
378     + }
379     + # remove if also un /usr/lib .. not as preset-all does not care
380     + #if ( -l "/usr/lib/systemd/system/sme-server.target.wants/$fi") {
381     + # print "remove $d$fi : also in /usr/lib/systemd/system/sme-server.target.wants/\n";
382     + # unlink "$d$fi";
383     + # next;
384     + #}
385     + # remove if link is not to an existing file # we should also check if poiting to an authorized path!
386     my $absFilePath = abs_path("$d$fi") ;
387     - print "remove $d$fi target '$absFilePath' does not exist or is not regular file\n" unless ( -f "$absFilePath");
388     - unlink "$d$fi" unless ( -f "$absFilePath");
389     + if ( ! -f "$absFilePath" or ( ! -f "/etc/systemd/system/$fi" and ! -f "/usr/lib/systemd/system/$fi") ) {
390     + print "remove $d$fi target '$absFilePath' does not exist or is not regular file in expeted path\n";
391     + unlink "$d$fi";
392     + next;
393     + }
394     # is not enable in preset : remove
395     #print "==$fi \n";
396     if ( ! defined $services{$fi} or $services{$fi} ne "enable") {
397     print "remove $d$fi as not enabled in preset\n";
398     unlink "$d$fi";
399     + next;
400     }
401     # if not wanted remove
402     unless ( /^$fi$/ ~~ @WantedBy) {
403     @@ -156,10 +169,10 @@
404     my $linkedU = ( -e "/usr/lib/systemd/system/sme-server.target.wants/$service" ) ? "linked" : "not";
405     my $linkedE = ( -e "/etc/systemd/system/sme-server.target.wants/$service" ) ? "linked" : "not";
406     my $linkedD = ( -e "/etc/systemd/system/default.target.wants/$service" or -e "/usr/lib/systemd/system/default.target.wants/$service" ) ? "linked" : "not";
407     - my $add = ($linkedU eq "not" and $linkedE eq "not" and $linkedD eq "not" and $status eq "enable" and $wanted eq "want") ? "ADDME!!" : "";
408     ## adding link if needed in /etc/systemd/system/sme-server.target.wants
409     - if ( $status eq "enable" and $linkedU eq "not" and $linkedE eq "not" and $linkedD eq "not" and $wanted eq "want"){
410     - print "systemctl add-wants sme-server.target $service\n";
411     + ## readd event if present in usr/lib as preste-all does not care about that.
412     + if ( $status eq "enable" and $linkedE eq "not" and $linkedD eq "not" and $wanted eq "want"){
413     + #print "systemctl add-wants sme-server.target $service\n";
414     `systemctl add-wants sme-server.target $service `;
415     }
416     }

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