Added function to check if proftpd is running
authorJamie Cameron <jcameron@webmin.com>
Tue, 24 Apr 2007 04:18:52 +0000 (04:18 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 24 Apr 2007 04:18:52 +0000 (04:18 +0000)
proftpd/proftpd-lib.pl
status/proftpd-monitor.pl

index 7adfab0..0ee5d87 100644 (file)
@@ -701,23 +701,29 @@ if ($config{'test_always'}) {
 # Returns HTML for a link to put in the top-right corner of every page
 sub restart_button
 {
-local $conf = &get_config();
-local $st = &find_directive("ServerType", $conf);
-return undef if (lc($st) eq "inetd");
-local $rv;
-local $pidfile = $config{'pid_file'};
-$args = "redir=".&urlize(&this_url());
-if (open(PID, $pidfile) && <PID> =~ /(\d+)/ && kill(0, $1)) {
+local $r = &is_proftpd_running();
+return undef if ($r < 0);p
+local $args = "redir=".&urlize(&this_url());
+if ($r) {
        $rv .= "<a href=\"apply.cgi?$args&pid=$1\">$text{'proftpd_apply'}</a><br>\n";
        $rv .= "<a href=\"stop.cgi?$args&pid=$1\">$text{'proftpd_stop'}</a>\n";
        }
 else {
        $rv = "<a href=\"start.cgi?$args\">$text{'proftpd_start'}</a><br>\n";
        }
-close(PID);
 return $rv;
 }
 
+# is_proftpd_running()
+# Returns the PID if ProFTPd is running, 0 if down, -1 if running under inetd
+sub is_proftpd_running
+{
+local $conf = &get_config();
+local $st = &find_directive("ServerType", $conf);
+return -1 if (lc($st) eq "inetd");
+return &check_pid_file($config{'pid_file'});
+}
+
 # this_url()
 # Returns the URL in the apache directory of the current script
 sub this_url
index d5668c6..03c67ac 100644 (file)
@@ -8,7 +8,11 @@ return { 'up' => -1 } if (!&foreign_check($_[1]));
 local %pconfig = &foreign_config($_[1]);
 -r $pconfig{'proftpd_path'} || return { 'up' => -1 };
 &foreign_require($_[1], "proftpd-lib.pl");
-if (&foreign_call($_[1], "get_proftpd_pid")) {
+local $r = &foreign_call($_[1], "is_proftpd_running");
+if ($r < 0) {
+       return { 'up' => -1 };
+       }
+elsif ($r > 0) {
        return { 'up' => 1 };
        }
 else {