put dx.pl into an explicit handle sub
[spider.git] / perl / lock_nodes.pl
1 #!/usr/bin/env perl
2 #
3 # Lock all non local nodes that have a privileges <= 1
4 #
5 # WARNING - this must be run when the cluster.pl is down!
6 #
7 # Copyright (c) 1998 Dirk Koopman G1TLH
8 #
9 #
10
11
12 # make sure that modules are searched in the order local then perl
13
14 BEGIN {
15         # root of directory tree for this system
16         $root = "/spider"; 
17         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
18     unshift @INC, "$root/perl";     # this IS the right way round!
19         unshift @INC, "$root/local";
20 }
21
22 use SysVar;
23 use DXUser;
24 use DXUtil;
25
26 $lockfn = "$main::local_data/cluster.lck";       # lock file name (now in local d
27 if (-e $lockfn) {
28         open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
29         my $pid = <CLLOCK>;
30         chomp $pid;
31         die "Sorry, Lockfile ($lockfn) and process $pid exist, a cluster is running\n" if kill 0, $pid;
32         close CLLOCK;
33 }
34
35 my @nodes = map { uc } @ARGV;
36
37 DXUser::init(1);
38
39 my $count;
40 my $nodes;
41 my @ignore;
42 my ($action, $key, $data) = (0,0,0);
43 for ($action = DXUser::R_FIRST, $count = 0; !$DXUser::dbm->seq($key, $data, $action); $action = DXUser::R_NEXT) {
44         if ($data =~ m{sort => '[ACRSX]'}) {
45                 my $user = DXUser::get($key);
46                 if ($user->is_node) {
47                         $nodes ++;
48                         if (grep $key eq $_, (@nodes, $mycall)) {
49                                 push @ignore, $key;
50                                 next;
51                         }
52                         my $priv = $user->priv;
53                         if ($priv > 1) {
54                                 push @ignore, $key;
55                                 next;
56                         }
57                         $user->priv(1) unless $priv;
58                         $user->lockout(1);
59                         $user->put;
60                         $count++;
61                 }
62         }
63 }
64
65 print "locked out $count nodes out of $nodes\n";
66 print scalar @ignore, " nodes ignored (", join(',', @ignore), ")\n";
67 print "If there are any nodes missing on the above list then you MUST do\n";
68 print "a set/node (set/spider, set/clx etc) on each of them to allow them\n";
69 print "to connect to you or you to them\n"; 
70  
71 DXUser::finish();
72 exit(0);
73