Commit 22f19994 authored by Andrew McNab's avatar Andrew McNab
Browse files

mjf.init mjf.csh mjf.sh

parent 94a7bd95
......@@ -31,11 +31,9 @@
include VERSION
INSTALL_FILES=prologue.user VERSION
INSTALL_FILES=VERSION prologue.user mjf.init mjf.sh mjf.csh
TGZ_FILES=$(INSTALL_FILES) Makefile vac.spec
PYTHON_SITEARCH=/usr/lib64/python2.6/site-packages
TGZ_FILES=$(INSTALL_FILES) Makefile mjf-torque.spec
GNUTAR ?= tar
mjf-torque.tgz: $(TGZ_FILES)
......@@ -46,9 +44,14 @@ mjf-torque.tgz: $(TGZ_FILES)
install: $(INSTALL_FILES)
mkdir -p $(RPM_BUILD_ROOT)/var/lib/torque/mom_priv \
$(RPM_BUILD_ROOT)/etc/rc.d/init.d
$(RPM_BUILD_ROOT)/etc/rc.d/init.d \
$(RPM_BUILD_ROOT)/etc/profile.d
cp prologue.user \
$(RPM_BUILD_ROOT)/var/lib/torque/mom_priv
cp mjf.init \
$(RPM_BUILD_ROOT)/etc/rc.d/init.d/mjf
cp mjf.sh mjf.csh \
$(RPM_BUILD_ROOT)/etc/profile.d
rpm: mjf-torque.tgz
rm -Rf RPMTMP
......
......@@ -21,6 +21,10 @@ MJF for Torque/PBS
%install
make install
%post
chkconfig mjf on
service mjf start
%files
/var/lib/torque/mom_priv
/etc/rc.d/init.d/*
setenv MACHINEFEATURES /etc/machinefeatures
if ( "$PBS_JOBID" != "" ) then
setenv JOBFEATURES $HOME/jobfeatures-$PBS_JOBID
endif
#!/bin/bash
#
# mjf Create /etc/machinefeatures files
#
# chkconfig: 345 90 10
# description: Create /etc/machinefeatures files following the Machine/Job Features specification in HSF-TN-2016-02
# Source function library.
. /etc/init.d/functions
#
# Set the following variables in the configuration files
# to set/override them when populating /etc/machinfeatures
# - total_cpu
# - hs06
# - shutdowntime
# - grace_secs
#
# Persistent configuration goes in sysconfig
. /etc/sysconfig/mjf
# Transient configuration goes in run - for example shutdowntime
# Files put in mjf get deleted when the machine boots up
. /var/run/mjf
start() {
[ "$EUID" != "0" ] && exit 1
# Create files
echo -n $"Set up /etc/machinefeatures: "
mkdir -p /etc/machinefeatures
if [ "$total_cpu" == "" ] ; then
# If not explicitly configured then calculate from hardware
total_cpu=`grep '^processor[[:space:]]*:' /proc/cpuinfo | wc --lines`
fi
echo -n "$total_cpu" > /etc/machinefeatures/total_cpu
if [ "$hs06" == "" ] ; then
rm -f /etc/machinefeatures/hs06
else
echo -n "$hs06" > /etc/machinefeatures/hs06
fi
if [ "$shutdowntime" == "" ] ; then
rm -f /etc/machinefeatures/shutdowntime
else
echo -n "$shutdowntime" > /etc/machinefeatures/shutdowntime
fi
if [ "$grace_secs" == "" ] ; then
rm -f /etc/machinefeatures/grace_secs
else
echo -n "$grace_secs" > /etc/machinefeatures/grace_secs
fi
echo
return 0
}
stop() {
[ "$EUID" != "0" ] && exit 3
# We do not currently do anything for this!
echo -n $"Tidy up machinefeatures: "
echo
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|force-reload|reload}"
exit 4
esac
export MACHINEFEATURES=/etc/machinefeatures
if [ "$PBS_JOBID" != "" ] ; then
export JOBFEATURES=$HOME/jobfeatures-$PBS_JOBID
fi
......@@ -33,6 +33,7 @@
#
import os
import re
import sys
import time
......@@ -40,27 +41,44 @@ import time
# PROGRAM MAIN !!!
#
# Make sure the per-user tmp directory exists
homdeDir = os.path.expanduser('~')
job_id = os.environ['PBS_JOBID']
jobfeaturesDir = homeDir + '/jobfeatures-' + jobID
os.mkdir(jobfeaturesDir)
open(jobfeaturesDir + '/job_id', 'w').write(job_id)
try:
os.mkdir('/tmp/' + os.environ['USER'])
except OSError:
pass
allocated_cpu = int(os.environ['PBS_NUM_PPN'])
except:
sys.exit(1)
# And that it is owned by this user
if os.stat('/tmp/' + os.environ['USER']).st_uid != os.getuid():
sys.exit(2)
allocated_cpu = 1
open(jobfeaturesDir + '/job_id', 'w').write(str(allocated_cpu))
try:
jobid = os.environ['JOB_ID']
hs06 = float(open('/etc/machinefeatures/hs06','r').readline())
except:
sys.exit(3)
hs06 = None
jobfeaturesDir = '/tmp/' + os.environ['USER'] + '/jobfeatures-' + jobid
try:
os.mkdir(jobfeaturesDir)
total_cpu = int(open('/etc/machinefeatures/total_cpu','r').readline())
except:
sys.exit(4)
total_cpu = None
if hs06 and total_cpu:
# Simple pro-rata allocation of total hs06 depending on processors for this job
hs06_job = (allocated_cpu * hs06) / total_cpu
open(jobfeaturesDir + '/hs06_job', 'w').write(str(hs06_job))
try:
qstatResult = os.popen('qstat -f ' + jobID,'r').read()
except:
pass
jobstart_secs = int(time.time())
open(jobfeaturesDir + '/jobstart_secs', 'w').write(str(jobstart_secs))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment