This shows you the differences between two versions of the page.
— | wiki:old:job_resource_manager_2_memory_banks.pl [2013/07/10 10:49] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <code bash> | ||
+ | # $Id: job_resource_manager.pl 1648 2008-09-17 16:00:56Z neyron $ | ||
+ | # | ||
+ | # The job_resource_manager script is a perl script that oar server deploys on nodes | ||
+ | # to manage cpusets, users, job keys, ... | ||
+ | # | ||
+ | # Usage: | ||
+ | # This script is deployed from the server and executed as oar on the nodes | ||
+ | # ARGV[0] can have two different values: | ||
+ | # - " | ||
+ | # | ||
+ | # - " | ||
+ | # clean the cpuset structure | ||
+ | |||
+ | # TAKTUK_HOSTNAME environment variable must be defined and must be a name | ||
+ | # that we will be able to find in the transfered hashtable ($Cpuset variable). | ||
+ | use Fcntl ': | ||
+ | #use Data:: | ||
+ | |||
+ | sub exit_myself($$); | ||
+ | sub print_log($$); | ||
+ | |||
+ | my $Old_umask = sprintf(" | ||
+ | umask(oct(" | ||
+ | |||
+ | my $Cpuset; | ||
+ | my $Log_level; | ||
+ | |||
+ | # Retrieve parameters from STDIN in the " | ||
+ | # $Cpuset = { | ||
+ | # | ||
+ | # name => " | ||
+ | # | ||
+ | # nodes => hostname => [array with the content of the database cpuset field] | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # key => " | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # key => " | ||
+ | # } | ||
+ | # | ||
+ | # | ||
+ | # user => "user name" | ||
+ | # | ||
+ | # | ||
+ | # types => hashtable with job types as keys | ||
+ | # | ||
+ | # | ||
+ | my $tmp = ""; | ||
+ | while (< | ||
+ | $tmp .= $_; | ||
+ | } | ||
+ | $Cpuset = eval($tmp); | ||
+ | | ||
+ | if (!defined($Cpuset-> | ||
+ | exit_myself(2," | ||
+ | } | ||
+ | $Log_level = $Cpuset-> | ||
+ | my $Cpuset_path_job; | ||
+ | my @Cpuset_cpus; | ||
+ | # Get the data structure only for this node | ||
+ | if (defined($Cpuset-> | ||
+ | $Cpuset_path_job = $Cpuset-> | ||
+ | @Cpuset_cpus = @{$Cpuset-> | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | print_log(3," | ||
+ | if ($ARGV[0] eq " | ||
+ | # Initialize cpuset for this node | ||
+ | # First, create the tmp oar directory | ||
+ | if (!(((-d $Cpuset-> | ||
+ | exit_myself(13," | ||
+ | } | ||
+ | | ||
+ | if (defined($Cpuset-> | ||
+ | my $prevuser = getpwuid($Cpuset-> | ||
+ | system(" | ||
+ | my @tmp = getpwnam($Cpuset-> | ||
+ | if ($#tmp < 0){ | ||
+ | exit_myself(15," | ||
+ | } | ||
+ | if (system(" | ||
+ | exit_myself(15," | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | if (defined($Cpuset_path_job)){ | ||
+ | if (open(LOCKFILE,"> | ||
+ | flock(LOCKFILE, | ||
+ | if (system(' | ||
+ | if (system(' | ||
+ | exit_myself(4," | ||
+ | } | ||
+ | } | ||
+ | if (!(-d '/ | ||
+ | if (system( ' | ||
+ | ' | ||
+ | '/ | ||
+ | '/ | ||
+ | 'cat / | ||
+ | 'cat / | ||
+ | )){ | ||
+ | exit_myself(4," | ||
+ | } | ||
+ | } | ||
+ | flock(LOCKFILE, | ||
+ | close(LOCKFILE); | ||
+ | }else{ | ||
+ | exit_myself(16," | ||
+ | } | ||
+ | | ||
+ | my $mem = ""; | ||
+ | my $c = 0; | ||
+ | while (($c <= $# | ||
+ | my $core_id=$Cpuset_cpus[$c]; | ||
+ | my $physical_id=`cat / | ||
+ | | ||
+ | if ($physical_id == 1){ | ||
+ | if (($mem eq "" | ||
+ | $mem = " | ||
+ | | ||
+ | $mem = " | ||
+ | | ||
+ | | ||
+ | if (($mem eq "" | ||
+ | $mem = " | ||
+ | | ||
+ | $mem = " | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | #'for c in ' | ||
+ | | ||
+ | # Be careful with the physical_package_id. Is it corresponding to the memory banc? | ||
+ | if (system( ' | ||
+ | ' | ||
+ | '/ | ||
+ | '/ | ||
+ | '/ | ||
+ | '/ | ||
+ | )){ | ||
+ | exit_myself(5," | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | # Copy ssh key files | ||
+ | if ($Cpuset-> | ||
+ | # private key | ||
+ | if (open(PRIV, ">" | ||
+ | chmod(0600, | ||
+ | if (!print(PRIV $Cpuset-> | ||
+ | unlink($Cpuset-> | ||
+ | exit_myself(8," | ||
+ | } | ||
+ | close(PRIV); | ||
+ | if (defined($Cpuset-> | ||
+ | system(" | ||
+ | } | ||
+ | }else{ | ||
+ | exit_myself(7," | ||
+ | } | ||
+ | | ||
+ | # public key | ||
+ | if (open(PUB," | ||
+ | flock(PUB, | ||
+ | seek(PUB, | ||
+ | my $out = " | ||
+ | while (< | ||
+ | if ($_ =~ / | ||
+ | # We are reading a OAR key | ||
+ | $_ =~ / | ||
+ | my $oar_key = $2; | ||
+ | $Cpuset-> | ||
+ | my $curr_key = $2; | ||
+ | if ($curr_key eq $oar_key){ | ||
+ | exit_myself(13," | ||
+ | } | ||
+ | $out .= $_; | ||
+ | }elsif ($_ =~ / | ||
+ | # Remove from authorized keys outdated keys (typically after a reboot) | ||
+ | if (-d "/ | ||
+ | $out .= $_; | ||
+ | } | ||
+ | }else{ | ||
+ | $out .= $_; | ||
+ | } | ||
+ | } | ||
+ | if (!(seek(PUB, | ||
+ | exit_myself(9," | ||
+ | } | ||
+ | flock(PUB, | ||
+ | close(PUB); | ||
+ | }else{ | ||
+ | unlink($Cpuset-> | ||
+ | exit_myself(10," | ||
+ | } | ||
+ | } | ||
+ | }elsif ($ARGV[0] eq " | ||
+ | # delete ssh key files | ||
+ | if ($Cpuset-> | ||
+ | # private key | ||
+ | unlink($Cpuset-> | ||
+ | if (defined($Cpuset-> | ||
+ | unlink(" | ||
+ | } | ||
+ | | ||
+ | # public key | ||
+ | if (open(PUB," | ||
+ | flock(PUB, | ||
+ | seek(PUB, | ||
+ | #Change file on the fly | ||
+ | my $out = ""; | ||
+ | while (< | ||
+ | if (($_ ne " | ||
+ | $out .= $_; | ||
+ | } | ||
+ | } | ||
+ | if (!(seek(PUB, | ||
+ | exit_myself(12," | ||
+ | } | ||
+ | flock(PUB, | ||
+ | close(PUB); | ||
+ | }else{ | ||
+ | exit_myself(11," | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | # Clean cpuset on this node | ||
+ | if (defined($Cpuset_path_job)){ | ||
+ | system(' | ||
+ | while [ " | ||
+ | do | ||
+ | oardodo kill -9 $PROCESSES | ||
+ | PROCESSES=$(cat / | ||
+ | done' | ||
+ | ); | ||
+ | | ||
+ | if (system(' | ||
+ | # Uncomment this line if you want to use several network_address properties | ||
+ | # which are the same physical computer (linux kernel) | ||
+ | # | ||
+ | exit_myself(6," | ||
+ | } | ||
+ | } | ||
+ | if (defined($Cpuset-> | ||
+ | my $ipcrm_args=""; | ||
+ | if (open(IPCMSG,"< | ||
+ | < | ||
+ | while (< | ||
+ | if (/ | ||
+ | $ipcrm_args .= " -q $1"; | ||
+ | } | ||
+ | } | ||
+ | close (IPCMSG); | ||
+ | }else{ | ||
+ | exit_myself(14," | ||
+ | } | ||
+ | if (open(IPCSHM,"< | ||
+ | < | ||
+ | while (< | ||
+ | if (/ | ||
+ | $ipcrm_args .= " -m $1"; | ||
+ | } | ||
+ | } | ||
+ | close (IPCSHM); | ||
+ | }else{ | ||
+ | exit_myself(14," | ||
+ | } | ||
+ | if (open(IPCSEM,"< | ||
+ | < | ||
+ | while (< | ||
+ | if (/ | ||
+ | $ipcrm_args .= " -s $1"; | ||
+ | } | ||
+ | } | ||
+ | close (IPCSEM); | ||
+ | }else{ | ||
+ | exit_myself(14," | ||
+ | } | ||
+ | if ($ipcrm_args) { | ||
+ | print_log(3," | ||
+ | if(system(" | ||
+ | exit_myself(14," | ||
+ | } | ||
+ | } | ||
+ | print_log(3," | ||
+ | # | ||
+ | system(" | ||
+ | system(" | ||
+ | } | ||
+ | }else{ | ||
+ | exit_myself(3," | ||
+ | } | ||
+ | exit(0); | ||
+ | |||
+ | # Print error message and exit | ||
+ | sub exit_myself($$){ | ||
+ | my $exit_code = shift; | ||
+ | my $str = shift; | ||
+ | |||
+ | warn(" | ||
+ | exit($exit_code); | ||
+ | } | ||
+ | |||
+ | # Print log message depending on the LOG_LEVEL config value | ||
+ | sub print_log($$){ | ||
+ | my $l = shift; | ||
+ | my $str = shift; | ||
+ | |||
+ | if ($l <= $Log_level){ | ||
+ | print(" | ||
+ | } | ||
+ | } | ||
+ | </ |