From b320f0225cdcc53cc99d1e3554e5eff7f544f1c5 Mon Sep 17 00:00:00 2001 From: dobrek Date: Tue, 19 Nov 2002 18:48:21 +0000 Subject: [PATCH] - init files for OpenPBS Changed files: pbs_mom -> 1.1 pbs_sched -> 1.1 pbs_server -> 1.1 pbsconfig -> 1.1 pbsrun -> 1.1 --- pbs_mom | 45 +++++++++++ pbs_sched | 45 +++++++++++ pbs_server | 45 +++++++++++ pbsconfig | 104 ++++++++++++++++++++++++ pbsrun | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 465 insertions(+) create mode 100755 pbs_mom create mode 100755 pbs_sched create mode 100755 pbs_server create mode 100755 pbsconfig create mode 100755 pbsrun diff --git a/pbs_mom b/pbs_mom new file mode 100755 index 0000000..9c84dc2 --- /dev/null +++ b/pbs_mom @@ -0,0 +1,45 @@ +#!/bin/sh +# +# pbs_mom This script will start and stop the PBS daemons +# +# chkconfig: 345 85 85 +# description: PBS is a batch versitle batch system for SMPs and clusters +# + +# Source the library functions +. /etc/rc.d/init.d/functions + +# let see how we were called +case "$1" in + start) + if [ ! -f /var/lock/subsys/pbs_mom ]; then + msg_starting "pbs_mom" + daemon /usr/sbin/pbs_mom + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pbs_mom + else + msg_already_running "pbs_mom" + fi + ;; + stop) + if [ -f /var/lock/subsys/pbs_mom ]; then + msg_stopping "pbs_mom" + killproc pbs_mom + rm -rf /var/lock/subsys/pbs_mom >/dev/null 2>&1 + else + msg_not_running pbs_mom + exit 1 + fi + ;; + status) + status pbs_mom + ;; + restart) + $0 stop + $0 start + ;; + *) + msg_usage "$0 {start|stop|status|restart|reload|force-reload}" + exit 1 +esac +exit $RETVAL diff --git a/pbs_sched b/pbs_sched new file mode 100755 index 0000000..6146c0f --- /dev/null +++ b/pbs_sched @@ -0,0 +1,45 @@ +#!/bin/sh +# +# pbs_sched This script will start and stop the PBS daemons +# +# chkconfig: 345 85 85 +# description: PBS is a batch versitle batch system for SMPs and clusters +# + +# Source the library functions +. /etc/rc.d/init.d/functions + +# let see how we were called +case "$1" in + start) + if [ ! -f /var/lock/subsys/pbs_sched ]; then + msg_starting "pbs_sched" + daemon /usr/sbin/pbs_sched + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pbs_sched + else + msg_already_running "pbs_sched" + fi + ;; + stop) + if [ -f /var/lock/subsys/pbs_sched ]; then + msg_stopping "pbs_sched" + killproc pbs_sched + rm -rf /var/lock/subsys/pbs_sched >/dev/null 2>&1 + else + msg_not_running pbs_sched + exit 1 + fi + ;; + status) + status pbs_sched + ;; + restart) + $0 stop + $0 start + ;; + *) + msg_usage "$0 {start|stop|status|restart|reload|force-reload}" + exit 1 +esac +exit $RETVAL diff --git a/pbs_server b/pbs_server new file mode 100755 index 0000000..8fa162f --- /dev/null +++ b/pbs_server @@ -0,0 +1,45 @@ +#!/bin/sh +# +# pbs_server This script will start and stop the PBS daemons +# +# chkconfig: 345 85 85 +# description: PBS is a batch versitle batch system for SMPs and clusters +# + +# Source the library functions +. /etc/rc.d/init.d/functions + +# let see how we were called +case "$1" in + start) + if [ ! -f /var/lock/subsys/pbs_server ]; then + msg_starting "pbs_server" + daemon /usr/sbin/pbs_server + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pbs_server + else + msg_already_running "pbs_server" + fi + ;; + stop) + if [ -f /var/lock/subsys/pbs_server ]; then + msg_stopping "pbs_server" + killproc pbs_server + rm -rf /var/lock/subsys/pbs_server >/dev/null 2>&1 + else + msg_not_running pbs_server + exit 1 + fi + ;; + status) + status pbs_server + ;; + restart) + $0 stop + $0 start + ;; + *) + msg_usage "$0 {start|stop|status|restart|reload|force-reload}" + exit 1 +esac +exit $RETVAL diff --git a/pbsconfig b/pbsconfig new file mode 100755 index 0000000..12da000 --- /dev/null +++ b/pbsconfig @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w + +use Getopt::Std; + +getopts('s:h'); + +0 if $opt_h; +0 if $opt_s; + +printHelpAndExit() if ($opt_h)||(@ARGV<1); + +my $server = shift @ARGV; +my $spool = $opt_s; +$spool = "/var/spool/pbs" if !$spool; +die "pbsconfig: PBS spool directory $spool does not exist!\n" if ! -d $spool; + +my $serverName = $server; +my @server = split(/\./,$server); +die "pbsconfig: PBS server name [$server] should be fully qualified, eg [yourhost.yourdomain.com]\n" if @server < 2; +shift @server; +my $restricted = "*.".join(".",@server); + +my $cpuinfo = `cat /proc/cpuinfo`; +my @cpuinfo = split(/\n/,$cpuinfo); + +my $numcpu = scalar grep(/processor/,@cpuinfo); +my $cputype = join(", ",getvalues("model name",@cpuinfo)); +my $cpuspeed = join(", ",getvalues("cpu MHz",@cpuinfo)); + +print "PBS Server name: $serverName\n"; +print "PBS Subnet: $restricted\n"; +print "Number of CPUs: $numcpu\n"; +print "CPU type: $cputype\n"; +print "CPU speed: $cpuspeed\n"; + +my $ideal_load = $numcpu - 0.1; +my $max_load = $numcpu - 0.1; + +my $momconfig = "$spool/mom_priv/config"; +my $mom = ""; + +$mom = `cat $momconfig` if -r $momconfig; + +#print "old [$mom]\n"; + +$mom = insert($mom,'$clienthost',$serverName); +$mom = insert($mom,'$restricted',$restricted); +$mom = insert($mom,'$usecp', "*:/ /"); +$mom = insert($mom,'$ideal_load',$numcpu - 0.1); +$mom = insert($mom,'$max_load', $numcpu - 0.1); + +#print "new [$mom]\n"; + +writeFile($momconfig,$mom); +writeFile("$spool/default_server","$serverName\n"); +writeFile("$spool/server_name","$serverName\n"); + +system "/etc/rc.d/init.d/pbs_mom restart"; + +exit 0; + +sub writeFile + { + my $filename = shift @_; + my $content = shift @_; + open(TMPOUT,">$filename") || die "pbsconfig: Cannot write to $filename: $!\n"; + print TMPOUT $content; + close TMPOUT; + } + +sub insert + { + my $cfg = shift @_; + my $key = shift @_; + my $value = shift @_; + + return $cfg . "$key $value\n" if ! ($cfg =~ /\Q$key\E/); + + $cfg =~ s/^\Q$key\E\b.*$/$key $value/m; + + return $cfg; + } + +sub printHelpAndExit + { + print STDERR "Usage: pbsconfig [-h] [-s spooldir] servername\n"; + exit 1; + } + +sub getvalues + { + my $key = shift @_; + my @ret; + foreach my $v (@_) + { + #print "[$v]\n"; + next if !($v =~ /$key/); + my ($key,$value) = split(/: /,$v); + push @ret,$value; + } + return @ret; + } + +#end file diff --git a/pbsrun b/pbsrun new file mode 100755 index 0000000..4dba4cf --- /dev/null +++ b/pbsrun @@ -0,0 +1,226 @@ +#!/usr/bin/perl -w + +use Getopt::Std; + +my $confQsub = "/usr/bin/qsub"; # qsub command +my $confShell = "/bin/sh"; # the submit script is written for this shell +my $confMaxAge = 7*24*60*60; # maximum life time for files in $HOME/.pbsrun: 7 days +my $confHistory = "history.txt"; + +my $workdir = gotoWorkDir(); +cleanup(); + +getopts('nvN:m:e:q:o:h'); + +printHelpAndExit() if ($opt_h) || (@ARGV < 1); + +if ($opt_m) + { + die "pbsrun: -m argument [$opt_m] does not look like an email address\n" unless $opt_m =~ /.*@.*/; + $opt_m = "-m abe -M $opt_m"; + } +else + { + $opt_m = "-m n"; + } + +$opt_N = '\"'.$ARGV[0].'\"' unless $opt_N; + +$opt_q = "-q " . $opt_q if $opt_q; + +0 if $opt_n; +0 if $opt_h; +0 if $opt_v; +$opt_o = "" if !$opt_o; +$opt_q = "" if !$opt_q; + +my $cmd = join(" ",@ARGV); + + +my $jobName = NewJob(); + +WriteHistory(time(),$jobName,"Command: ",$cmd); + +open(JOBFILE,">$jobName.script") || die "pbsrun: Could not open $jobName: $!\n"; + +print JOBFILE "#!$confShell\n"; +print JOBFILE "# This file was generated automatically.\n"; +print JOBFILE "# on ".(scalar localtime)."\n"; +print JOBFILE "#\n"; +print JOBFILE "# restore the user environment\n"; +foreach my $key (sort keys %ENV) + { + next if ($key eq "DISPLAY"); + next if ($key eq "HOSTNAME"); + next if ($key eq "HOSTTYPE"); + next if ($key eq "LOGNAME"); + next if ($key eq "MACHTYPE"); + next if ($key eq "MAIL"); + next if ($key eq "OSTYPE"); + next if ($key eq "OLDPWD"); + next if ($key eq "PWD"); + next if ($key eq "SHELL"); + next if ($key eq "SHLVL"); + next if ($key =~ /^SSH/); + next if ($key eq "TERM"); + next if ($key eq "USER"); + next if ($key eq "WINDOWID"); + next if ($key eq "LS_COLORS"); + next if ($key eq "XAUTHORITY"); + next if ($key eq "_"); + my $val = $ENV{$key}; + print JOBFILE "export $key=\"$val\"\n"; + } + +print JOBFILE "#\n"; +print JOBFILE "# restore the user working directory\n"; +my $pwd = $ENV{"PWD"}; +print JOBFILE "cd $pwd\n" ; +WriteHistory(time(),$jobName,"Pwd: ",$pwd); + +print JOBFILE "# save the node name\n"; +print JOBFILE "hostname >$workdir/$jobName.hostname\n"; +print JOBFILE "# run the user command:\n"; +print JOBFILE "(".$cmd.")"." >/dev/null 2>/dev/null\n"; +print JOBFILE "# save the exit status: \n"; +print JOBFILE "echo \$\? >$workdir/$jobName.status\n"; +#print JOBFILE "printenv | grep PBS\n"; +#print JOBFILE "set\n"; +print JOBFILE "exit \$\?\n"; +print JOBFILE "# end of file\n"; +close JOBFILE; + +my $outputfile = "$workdir/$jobName.stderr"; + +my $qsubcmd = "$confQsub -S $confShell -r n -j eo -e $outputfile -N $opt_N $opt_o $opt_m $opt_q < $jobName.script"; +print "pbsrun: $qsubcmd\n" if $opt_v; + +WriteHistory(time(),$jobName,"Qsub: ",$qsubcmd); + +if ($opt_n) + { + WriteHistory(time(),$jobName,"Pbs job: not submitted"); + + print "PBS Job id: not submitted\n"; + print "Job output: $outputfile\n"; + } +else + { + my $jobid = submitJob($qsubcmd); + + die "pbsrun: Failed to submit the pbs job!\n" if !$jobid; + + WriteHistory(time(),$jobName,"Pbs job: ",$jobid); + + print "PBS Job id: $jobid\n"; + print "Job output: $outputfile\n"; + } + +exit 0; + +sub NewJob + { + my @now = localtime(); + return sprintf("%04d%02d%02d-%02d%02d%02d-%d", + 1900+$now[5],1+$now[4],$now[3], + $now[2],$now[1],$now[0],$$); + } + +sub submitJob + { + my $cmd = shift @_; + open(QSUBPROC, "$cmd 2>&1 |") || die "pbsrun: Cannot spawn $confQsub: $!\n"; + + my $jobid; + + while () + { + print "qsub: ".$_ if $opt_v; + $jobid = $_ if /^\d+/; + } + close QSUBPROC; + + $jobid =~ s/\n$// if defined $jobid; + + return $jobid; + } + +sub gotoWorkDir + { + my $workdir = $ENV{"HOME"}."/.pbsrun"; + if (! -d $workdir) + { + print "pbsrun: no $workdir directory. Making one.\n"; + mkdir($workdir,0744) || die "pbsrun: Could not make $workdir: $!\n"; + } + chdir $workdir || die "pbsrun: Cannot chdir to $workdir: $!\n"; + return $workdir; + } + +sub WriteHistory + { + my $now = localtime(shift @_); + open(TMPOUT,">>$confHistory"); + print TMPOUT $now,": job ",shift @_,": ",join("",@_),"\n"; + close TMPOUT; + } + +sub cleanup + { + my $now = time(); + my @ls = `/bin/ls -1`; + foreach $ls (sort @ls) + { + chop $ls; + next if $ls eq $confHistory; + + my @stat = stat $ls; + my $mtime = $stat[9]; + + if ($ls =~ /(.*)\.status/) + { + my $status = `cat $ls`; + chop $status; + #print "time $mtime, status [$status]\n"; + WriteHistory($mtime,$1,"Exit status: ",$status); + unlink $ls; + next; + } + + if ($ls =~ /(.*)\.hostname/) + { + my $hostname = `cat $ls`; + chop $hostname; + #print "time $mtime, hostname [$hostname]\n"; + WriteHistory($mtime,$1,"Started on: ",$hostname); + unlink $ls; + next; + } + + my $age = $now - $mtime; + + #print "file [$ls] age: [$age]\n"; + + if ($age > $confMaxAge) + { + unlink $ls; + } + } + } + +sub printHelpAndExit +{ + print "Usage: pbsrun [-q queue] [-N job_name] command...\n"; + print " Options: \n"; + print " [-h] Prints out this message.\n"; + print " [-N job_name] name this job.\n"; + print " [-m user\@host] emails you when the job begin, ends or aborts.\n"; + print " [-o qsub_options] passes options to the call to qsub.\n"; + print " [-q queue] selects a queue.\n"; + print " [-n] test mode: do not run any pbs commands.\n"; + print " [-k] keep, do not delete temp files.\n"; + print " [-v] be verbose, show progress.\n"; + exit 1; +} + +#end file -- 2.44.0