-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdmtcp_starter
executable file
·66 lines (61 loc) · 2.6 KB
/
dmtcp_starter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# dmtcp_starter - dmtcp job starter - runs jobs under dmtcp checkpointing
#
# Copyright 2012 Orion Poplawski <orion@cora.nwra.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Apparently SGE_STARTER_SHELL_PATH doesn't always get set with qrshd
[ -z "$SGE_STARTER_SHELL_PATH" ] && SGE_STARTER_SHELL_PATH=$SHELL
# starter_methods need to be installed per queue, but we only
# want to setup dmtcp checkpointing for jobs that use it
if [ "${SGE_CKPT_ENV/dmtcp}" != "${SGE_CKPT_ENV}" ]
then
# Get the base from the config file
eval `grep ^ckpt_dir= $SGE_JOB_SPOOL_DIR/config`
# Make the per task checkpoint directory if it doesn't already exist
CKPTDIR=${ckpt_dir}/${JOB_ID}.${SGE_TASK_ID/undefined/1}
mkdir -p $CKPTDIR
# Setup dmtcp_coordinator - this will get killed by the shepherd
dmtcp_coordinator --quiet --port 0 --port-file $TMPDIR/dmtcp_port --ckptdir $CKPTDIR --exit-on-last --daemon 2>&1
if [ "$RESTARTED" -eq 2 ]
then
# Override the setting in dmtcp_restart_script.sh
export DMTCP_HOST=`hostname`
# Restart the job
exec $CKPTDIR/dmtcp_restart_script.sh
else
# We need to move the job script to remove the hostname from the path
cp $1 $CKPTDIR/jobscript
shift
# Start the job (TODO - be able to set the argv[0] for login shell)
exec dmtcp_checkpoint -p `cat $TMPDIR/dmtcp_port` --quiet $SGE_STARTER_SHELL_PATH $CKPTDIR/jobscript "$@"
fi
else
# Start the job normally with proper shell handling
case "$SGE_STARTER_SHELL_START_MODE" in
unix_behavior)
exec "$@" ;;
#
# Although posix_compliant and script_from_stdin are the same, the behavior is different:
# posix_compliant => $1 is the name of the script
# script_from_stdin => $1 is -s (option to the shell to read from stdin)
#
posix_compliant | script_from_stdin)
if [ "$SGE_STARTER_USE_LOGIN_SHELL" = "true" ]; then
exec -l -a "${SGE_STARTER_SHELL_PATH##*/}" "$SGE_STARTER_SHELL_PATH" "${@}"
else
exec -a "${SGE_STARTER_SHELL_PATH##*/}" "$SGE_STARTER_SHELL_PATH" "${@}"
fi ;;
esac
fi