forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-shutdown-lib.pl
55 lines (49 loc) · 1.11 KB
/
cluster-shutdown-lib.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
do '../web-lib.pl';
&init_config();
do '../ui-lib.pl';
&foreign_require("servers", "servers-lib.pl");
%access = &get_module_acl();
$cron_cmd = "$module_config_directory/check.pl";
sub find_cron_job
{
&foreign_require("cron", "cron-lib.pl");
local ($job) = grep { $_->{'command'} eq $cron_cmd } &cron::list_cron_jobs();
return $job;
}
# get_all_statuses(&servers)
# Returns a hash mapping servers to their statuses. The possible values are:
# 0 = down
# 1 = up
# 2 = up but login is not possible
# 3 = up but login failed
sub get_all_statuses
{
# Check which ones are up, in parallel
my ($servers) = @_;
my %pid;
foreach my $s (@$servers) {
my $pid;
if (!($pid = fork())) {
my $out = `ping -c 1 -w 1 $s->{'host'} 2>&1`;
if ($config{'login'} && !$?) {
# Attempt a Webmin login too
if (!$s->{'user'}) {
exit(101);
}
local $err = &servers::test_server($s->{'host'});
exit($err ? 102 : 0);
}
exit($? ? 1 : 0);
}
$pid{$s} = $pid;
}
my %up;
foreach my $s (@$servers) {
my $pid = waitpid($pid{$s}, 0);
$up{$s} = $? == 0 ? 1 :
$?/256 == 101 ? 2 :
$?/256 == 102 ? 3 : 0;
}
return %up;
}
1;