Annotation of doc/loncapafiles/systemd_config_check.piml, revision 1.1
1.1 ! raeburn 1: <!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN"
! 2: "http://lpml.sourceforge.net/DTD/piml.dtd">
! 3: <!-- systemd_config_check.piml -->
! 4:
! 5: <!-- $Id: systemd_config_check.piml,v 1.1 2024/07/28 12:51:00 raeburn Exp $ -->
! 6:
! 7: <!--
! 8:
! 9: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 10:
! 11: LON-CAPA is free software; you can redistribute it and/or modify
! 12: it under the terms of the GNU General Public License as published by
! 13: the Free Software Foundation; either version 2 of the License, or
! 14: (at your option) any later version.
! 15:
! 16: LON-CAPA is distributed in the hope that it will be useful,
! 17: but WITHOUT ANY WARRANTY; without even the implied warranty of
! 18: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 19: GNU General Public License for more details.
! 20:
! 21: You should have received a copy of the GNU General Public License
! 22: along with LON-CAPA; if not, write to the Free Software
! 23: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 24:
! 25: /home/httpd/html/adm/gpl.txt
! 26:
! 27: http://www.lon-capa.org/
! 28:
! 29: -->
! 30:
! 31: <piml>
! 32: <targetroot>/</targetroot>
! 33: <files>
! 34: <file>
! 35: <target dist="default">/home/httpd/perl</target>
! 36: <perlscript mode="fg">
! 37:
! 38: use strict;
! 39:
! 40: my $service = 'apache2.service';
! 41: my $use_systemctl;
! 42: my ($dist,$version) = ('<DIST />' =~ /^([A-Za-z]+)([\d\.]+)$/);
! 43: if (($dist eq 'sles') || ($dist eq 'suse')) {
! 44: if ($version >= 12) {
! 45: $use_systemctl = 1;
! 46: }
! 47: } elsif ($dist eq 'fedora') {
! 48: if ($version >= 16) {
! 49: $use_systemctl = 1;
! 50: }
! 51: $service = 'httpd.service';
! 52: } elsif ($dist =~ /^(centos|rhes|scientific|oracle|rocky|alma)$/) {
! 53: if ($version >= 7) {
! 54: $use_systemctl = 1;
! 55: }
! 56: $service = 'httpd.service';
! 57: } elsif ($dist eq 'ubuntu') {
! 58: if ($version >= 16) {
! 59: $use_systemctl = 1;
! 60: }
! 61: } elsif ($dist eq 'debian') {
! 62: if ($version >= 9) {
! 63: $use_systemctl = 1;
! 64: }
! 65: }
! 66:
! 67: if ($use_systemctl) {
! 68: system('systemctl daemon-reload');
! 69: if (open(PIPE,"systemctl show $service --property=ProtectHome 2>/dev/null |")) {
! 70: my $protection = <PIPE>;
! 71: close(PIPE);
! 72: chomp($protection);
! 73: if ($protection =~ /^ProtectHome=(read-only|yes)$/i) {
! 74: if (!-d '/etc/systemd/system/'.$service.'.d') {
! 75: mkdir '/etc/systemd/system/'.$service.'.d', 0755;
! 76: }
! 77: if (-d '/etc/systemd/system/'.$service.'.d') {
! 78: if (-e '/etc/systemd/system/'.$service.'.d/override.conf') {
! 79: if (open(my $fh,'<','/etc/systemd/system/'.$service.'.d/override.conf')) {
! 80: my ($inservice,$addservice,$protectoff,$linenum,$change,@lines);
! 81: while (my $entry = <$fh>) {
! 82: $linenum ++;
! 83: chomp($entry);
! 84: if ($entry eq '[Service]') {
! 85: if (!$protectoff) {
! 86: $inservice = $linenum;
! 87: push(@lines,$entry);
! 88: } else {
! 89: $addservice = 1;
! 90: next;
! 91: }
! 92: }
! 93: if ($entry =~ /^ProtectHome\s*=\s*([\w-]+)\s*$/) {
! 94: my $value = $1;
! 95: if ($protectoff) {
! 96: next;
! 97: if (lc($value) eq 'no') {
! 98: $protectoff = $linenum;
! 99: push(@lines,$entry);
! 100: } else {
! 101: if ($protectoff) {
! 102: next;
! 103: } else {
! 104: push(@lines,'ProtectHome=no');
! 105: $protectoff = $linenum;
! 106: $change = $linenum;
! 107: }
! 108: }
! 109: }
! 110: }
! 111: }
! 112: close($fh);
! 113: if ($addservice || $change || !$protectoff) {
! 114: if (open(my $fh,'>','/etc/systemd/system/'.$service.'.d/override.conf')) {
! 115: if ($addservice) {
! 116: print $fh "[Service]\n";
! 117: }
! 118: foreach my $entry (@lines) {
! 119: print $fh "$entry\n";
! 120: }
! 121: close($fh);
! 122: print 'Updated /etc/systemd/system/'.$service.'.d/override.conf'."\n";
! 123: system('systemctl daemon-reload');
! 124: } else {
! 125: print '**** ERROR: Could not open /etc/systemd/system/'.$service.'.d/override.conf to write ProtectHome=no.'."\n".
! 126: 'LON-CAPA web interface will not be usable.'."\n";
! 127: }
! 128: }
! 129: }
! 130: } else {
! 131: if (open(my $fh,'>','/etc/systemd/system/'.$service.'.d/override.conf')) {
! 132: print $fh '[Service]'."\n".'ProtectHome=no'."\n";
! 133: close($fh);
! 134: print 'Created /etc/systemd/system/'.$service.'.d/override.conf'."\n";
! 135: system('systemctl daemon-reload');
! 136: } else {
! 137: print '**** ERROR: Could not open /etc/systemd/system/'.$service.'.d/override.conf to write ProtectHome=no.'."\n".
! 138: 'LON-CAPA web interface will not be usable.'."\n";
! 139: }
! 140: }
! 141: } else {
! 142: print '**** ERROR: No /etc/systemd/system/'.$service.'.d directory exists and creating one failed.'."\n".
! 143: 'LON-CAPA web interface will not be usable.'."\n";
! 144: }
! 145: }
! 146: } else {
! 147: print '**** WARNING *** Could not determine status of ProtectHome property for systemd '.$service.".\n".
! 148: 'It was not possible to determine whether LON-CAPA web interface will be usable.'."\n";
! 149: }
! 150: }
! 151:
! 152: </perlscript>
! 153: </file>
! 154: </files>
! 155: </piml>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>