Make miniserv restart function better handle case where it is down or another
authorJamie Cameron <jcameron@webmin.com>
Mon, 2 May 2011 22:38:57 +0000 (15:38 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 2 May 2011 22:38:57 +0000 (15:38 -0700)
web server is in use.
https://sourceforge.net/tracker/?func=detail&atid=117457&aid=3296493&group_id=17457

web-lib-funcs.pl

index 0b2d785..1c122e9 100755 (executable)
@@ -1869,6 +1869,10 @@ my ($nowait) = @_;
 return undef if (&is_readonly_mode());
 my %miniserv;
 &get_miniserv_config(\%miniserv) || return;
+if ($main::webmin_script_type eq 'web' && !$ENV{"MINISERV_CONFIG"}) {
+       # Running under some web server other than miniserv, so do nothing
+       return;
+       }
 
 my $i;
 if ($gconfig{'os_type'} ne 'windows') {
@@ -1878,11 +1882,22 @@ if ($gconfig{'os_type'} ne 'windows') {
        my @oldst = stat($miniserv{'pidfile'});
        $pid = $ENV{'MINISERV_PID'};
        if (!$pid) {
-               open(PID, $miniserv{'pidfile'}) ||
-                       &error("Failed to open PID file $miniserv{'pidfile'}");
+               if (!open(PID, $miniserv{'pidfile'})) {
+                       print STDERR "PID file $miniserv{'pidfile'} does ",
+                                    "not exist\n";
+                       return;
+                       }
                chop($pid = <PID>);
                close(PID);
-               $pid || &error("Invalid PID file $miniserv{'pidfile'}");
+               if (!$pid) {
+                       print STDERR "Invalid PID file $miniserv{'pidfile'}\n";
+                       return;
+                       }
+               if (!kill(0, $pid)) {
+                       print STDERR "PID $pid from file $miniserv{'pidfile'} ",
+                                    "is not valid\n";
+                       return;
+                       }
                }
 
        # Just signal miniserv to restart