[LON-CAPA-cvs] cvs: loncom / apachereload
raeburn
raeburn at source.lon-capa.org
Sat Jan 25 16:09:18 EST 2020
raeburn Sat Jan 25 21:09:18 2020 EDT
Modified files:
/loncom apachereload
Log:
- Support reload of Apache for both systemd and SysV.
- Discontinue dependency on LONCAPA::Configuration and distprobe.
Index: loncom/apachereload
diff -u loncom/apachereload:1.7 loncom/apachereload:1.8
--- loncom/apachereload:1.7 Sat May 14 16:12:53 2011
+++ loncom/apachereload Sat Jan 25 21:09:17 2020
@@ -3,7 +3,7 @@
#
# apachereload - setuid script that reloads the apache daemon.
#
-# $Id: apachereload,v 1.7 2011/05/14 16:12:53 raeburn Exp $
+# $Id: apachereload,v 1.8 2020/01/25 21:09:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -32,29 +32,73 @@
use strict;
#
# This script is a setuid script that must be run as user www
-# it effectively just executes /etc/init.d/httpd reload.
-# causing the apache daemon to get HUP'd. The script is
-# run by lond after re-initing it's host information.
+# it effectively just executes one of the following five commands:
+# /etc/init.d/httpd reload
+# /etc/init.d/apache reload
+# /etc/init.d/apache2 reload
+# /bin/systemctl reload httpd.service
+# /bin/systemctl reload apache2.service
+# (depending on Linux distro) causing the apache daemon to get HUP'd.
+# The script is run by lond after re-initing its host information.
$ENV{'PATH'}='/bin:/usr/bin:/usr/local/sbin:/home/httpd/perl'; # Nullify path
# information
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # nullify potential taints
-my $command = "/etc/init.d/httpd reload";
-
-use lib '/home/httpd/lib/perl/';
-use LONCAPA::Configuration;
-my %perlvar= %{&LONCAPA::Configuration::read_conf('loncapa.conf')};
-
-my ($execdir) = ($perlvar{'lonDaemons'} =~/(.*)/);
-my $dist=`$execdir/distprobe`;
-if ($dist =~ /^(suse|sles)/) {
- $command = "/etc/init.d/apache reload";
+my $command;
+my $checker_bin = '/sbin/chkconfig';
+my $sysctl_bin = '/bin/systemctl';
+my $sysv_bin = '/usr/sbin/sysv-rc-conf';
+
+if (-x $sysctl_bin) {
+ if (open(PIPE,"$sysctl_bin list-unit-files --type=service 2>/dev/null |")) {
+ my @lines = <PIPE>;
+ chomp(@lines);
+ close(PIPE);
+ if (grep(/^httpd\.service/, at lines)) {
+ $command = '/bin/systemctl reload httpd.service';
+ } elsif (grep(/^apache2\.service/, at lines)) {
+ $command = '/bin/systemctl reload apache2.service';
+ }
+ }
+}
+if (($command eq '') && (-x $checker_bin)) {
+ if (open(PIPE,"$checker_bin --list 2>/dev/null |")) {
+ my @lines = <PIPE>;
+ chomp(@lines);
+ close(PIPE);
+ if (grep(/^httpd/, at lines)) {
+ $command = '/etc/init.d/httpd reload';
+ } elsif (grep(/^apache2/, at lines)) {
+ $command = '/etc/init.d/apache2 reload';
+ } elsif (grep(/^apache\s+/, at lines)) {
+ $command = '/etc/init.d/apache reload';
+ }
+ }
+}
+if (($command eq '') && (-x $sysv_bin)) {
+ if (open(PIPE,"$checker_bin --list 2>/dev/null |")) {
+ my @lines = <PIPE>;
+ chomp(@lines);
+ close(PIPE);
+ if (grep(/^apache2/, at lines)) {
+ $command = '/etc/init.d/apache2 reload';
+ } elsif (grep(/^apache\s+/, at lines)) {
+ $command = '/etc/init.d/apache reload';
+ }
+ }
}
+
# Do not print error messages
my $noprint=1;
-print "In apachereload" unless $noprint;
+if ($command eq '') {
+ print("Could not determine command to reload Apache.\n")
+ unless $noprint;
+ exit 1;
+} else {
+ print "In apachereload" unless $noprint;
+}
# ----------------------------- Make sure this process is running from user=www
my $wwwid=getpwnam('www');
@@ -75,7 +119,7 @@
# Now run the reload:
#
-system($command);
+system("$command > /dev/null 2>&1);
&disable_root_capability;
exit 0;
More information about the LON-CAPA-cvs
mailing list