]>
Commit | Line | Data |
---|---|---|
b320f022 | 1 | #!/usr/bin/perl -w |
2 | ||
3 | use Getopt::Std; | |
4 | ||
5 | getopts('s:h'); | |
6 | ||
7 | 0 if $opt_h; | |
8 | 0 if $opt_s; | |
9 | ||
10 | printHelpAndExit() if ($opt_h)||(@ARGV<1); | |
11 | ||
12 | my $server = shift @ARGV; | |
13 | my $spool = $opt_s; | |
14 | $spool = "/var/spool/pbs" if !$spool; | |
15 | die "pbsconfig: PBS spool directory $spool does not exist!\n" if ! -d $spool; | |
16 | ||
17 | my $serverName = $server; | |
18 | my @server = split(/\./,$server); | |
19 | die "pbsconfig: PBS server name [$server] should be fully qualified, eg [yourhost.yourdomain.com]\n" if @server < 2; | |
20 | shift @server; | |
21 | my $restricted = "*.".join(".",@server); | |
22 | ||
23 | my $cpuinfo = `cat /proc/cpuinfo`; | |
24 | my @cpuinfo = split(/\n/,$cpuinfo); | |
25 | ||
26 | my $numcpu = scalar grep(/processor/,@cpuinfo); | |
27 | my $cputype = join(", ",getvalues("model name",@cpuinfo)); | |
28 | my $cpuspeed = join(", ",getvalues("cpu MHz",@cpuinfo)); | |
29 | ||
30 | print "PBS Server name: $serverName\n"; | |
31 | print "PBS Subnet: $restricted\n"; | |
32 | print "Number of CPUs: $numcpu\n"; | |
33 | print "CPU type: $cputype\n"; | |
34 | print "CPU speed: $cpuspeed\n"; | |
35 | ||
36 | my $ideal_load = $numcpu - 0.1; | |
37 | my $max_load = $numcpu - 0.1; | |
38 | ||
39 | my $momconfig = "$spool/mom_priv/config"; | |
40 | my $mom = ""; | |
41 | ||
42 | $mom = `cat $momconfig` if -r $momconfig; | |
43 | ||
44 | #print "old [$mom]\n"; | |
45 | ||
46 | $mom = insert($mom,'$clienthost',$serverName); | |
47 | $mom = insert($mom,'$restricted',$restricted); | |
48 | $mom = insert($mom,'$usecp', "*:/ /"); | |
49 | $mom = insert($mom,'$ideal_load',$numcpu - 0.1); | |
50 | $mom = insert($mom,'$max_load', $numcpu - 0.1); | |
51 | ||
52 | #print "new [$mom]\n"; | |
53 | ||
54 | writeFile($momconfig,$mom); | |
55 | writeFile("$spool/default_server","$serverName\n"); | |
56 | writeFile("$spool/server_name","$serverName\n"); | |
57 | ||
58 | system "/etc/rc.d/init.d/pbs_mom restart"; | |
59 | ||
60 | exit 0; | |
61 | ||
62 | sub writeFile | |
63 | { | |
64 | my $filename = shift @_; | |
65 | my $content = shift @_; | |
66 | open(TMPOUT,">$filename") || die "pbsconfig: Cannot write to $filename: $!\n"; | |
67 | print TMPOUT $content; | |
68 | close TMPOUT; | |
69 | } | |
70 | ||
71 | sub insert | |
72 | { | |
73 | my $cfg = shift @_; | |
74 | my $key = shift @_; | |
75 | my $value = shift @_; | |
76 | ||
77 | return $cfg . "$key $value\n" if ! ($cfg =~ /\Q$key\E/); | |
78 | ||
79 | $cfg =~ s/^\Q$key\E\b.*$/$key $value/m; | |
80 | ||
81 | return $cfg; | |
82 | } | |
83 | ||
84 | sub printHelpAndExit | |
85 | { | |
86 | print STDERR "Usage: pbsconfig [-h] [-s spooldir] servername\n"; | |
87 | exit 1; | |
88 | } | |
89 | ||
90 | sub getvalues | |
91 | { | |
92 | my $key = shift @_; | |
93 | my @ret; | |
94 | foreach my $v (@_) | |
95 | { | |
96 | #print "[$v]\n"; | |
97 | next if !($v =~ /$key/); | |
98 | my ($key,$value) = split(/: /,$v); | |
99 | push @ret,$value; | |
100 | } | |
101 | return @ret; | |
102 | } | |
103 | ||
104 | #end file |