/ /home/httpd/perl use strict; my $service = 'apache2.service'; my $use_systemctl; my ($dist,$version) = ('' =~ /^([A-Za-z]+)([\d\.]+)$/); if (($dist eq 'sles') || ($dist eq 'suse')) { if ($version >= 12) { $use_systemctl = 1; } } elsif ($dist eq 'fedora') { if ($version >= 16) { $use_systemctl = 1; } $service = 'httpd.service'; } elsif ($dist =~ /^(centos|rhes|scientific|oracle|rocky|alma)$/) { if ($version >= 7) { $use_systemctl = 1; } $service = 'httpd.service'; } elsif ($dist eq 'ubuntu') { if ($version >= 16) { $use_systemctl = 1; } } elsif ($dist eq 'debian') { if ($version >= 9) { $use_systemctl = 1; } } if ($use_systemctl) { system('systemctl daemon-reload'); if (open(PIPE,"systemctl show $service --property=ProtectHome 2>/dev/null |")) { my $protection = <PIPE>; close(PIPE); chomp($protection); if ($protection =~ /^ProtectHome=(read-only|yes)$/i) { if (!-d '/etc/systemd/system/'.$service.'.d') { mkdir '/etc/systemd/system/'.$service.'.d', 0755; } if (-d '/etc/systemd/system/'.$service.'.d') { if (-e '/etc/systemd/system/'.$service.'.d/override.conf') { if (open(my $fh,'<','/etc/systemd/system/'.$service.'.d/override.conf')) { my ($inservice,$addservice,$protectoff,$linenum,$change,@lines); while (my $entry = <$fh>) { $linenum ++; chomp($entry); if ($entry eq '[Service]') { if (!$protectoff) { $inservice = $linenum; push(@lines,$entry); } else { $addservice = 1; next; } } if ($entry =~ /^ProtectHome\s*=\s*([\w-]+)\s*$/) { my $value = $1; if ($protectoff) { next; if (lc($value) eq 'no') { $protectoff = $linenum; push(@lines,$entry); } else { if ($protectoff) { next; } else { push(@lines,'ProtectHome=no'); $protectoff = $linenum; $change = $linenum; } } } } } close($fh); if ($addservice || $change || !$protectoff) { if (open(my $fh,'>','/etc/systemd/system/'.$service.'.d/override.conf')) { if ($addservice) { print $fh "[Service]\n"; } foreach my $entry (@lines) { print $fh "$entry\n"; } close($fh); print 'Updated /etc/systemd/system/'.$service.'.d/override.conf'."\n"; system('systemctl daemon-reload'); } else { print '**** ERROR: Could not open /etc/systemd/system/'.$service.'.d/override.conf to write ProtectHome=no.'."\n". 'LON-CAPA web interface will not be usable.'."\n"; } } } } else { if (open(my $fh,'>','/etc/systemd/system/'.$service.'.d/override.conf')) { print $fh '[Service]'."\n".'ProtectHome=no'."\n"; close($fh); print 'Created /etc/systemd/system/'.$service.'.d/override.conf'."\n"; system('systemctl daemon-reload'); } else { print '**** ERROR: Could not open /etc/systemd/system/'.$service.'.d/override.conf to write ProtectHome=no.'."\n". 'LON-CAPA web interface will not be usable.'."\n"; } } } else { print '**** ERROR: No /etc/systemd/system/'.$service.'.d directory exists and creating one failed.'."\n". 'LON-CAPA web interface will not be usable.'."\n"; } } } else { print '**** WARNING *** Could not determine status of ProtectHome property for systemd '.$service.".\n". 'It was not possible to determine whether LON-CAPA web interface will be usable.'."\n"; } }