add an RBN line to progress
[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(4);
38
39 my $count;
40 my $nodes;
41 my @ignore;
42
43 my @calls = scan(sub
44                                  {
45                                          my $k = shift;
46                                          return $_[0] =~ m{"sort":"[ACRSX]"} ? $k : ();
47                                  });
48
49 foreach my $key (@calls) {
50         my $user = DXUser::get($key);
51         if ($user->is_node) {
52                 $nodes ++;
53                 if (grep $key eq $_, (@nodes, $mycall)) {
54                         push @ignore, $key;
55                         next;
56                 }
57                 my $priv = $user->priv;
58                 if ($priv > 1) {
59                         push @ignore, $key;
60                         next;
61                 }
62                 $user->priv(1) unless $priv;
63                 $user->lockout(1);
64                 $user->put;
65                 $count++;
66                 }
67         }
68 }
69 DXUser::sync;
70 DXUser::writeoutjson;
71
72 print "locked out $count nodes out of $nodes\n";
73 print scalar @ignore, " nodes ignored (", join(',', @ignore), ")\n";
74 print "If there are any nodes missing on the above list then you MUST do\n";
75 print "a set/node (set/spider, set/clx etc) on each of them to allow them\n";
76 print "to connect to you or you to them\n"; 
77  
78 DXUser::finish();
79 exit(0);
80