forked from vsoch/forward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·90 lines (69 loc) · 2.04 KB
/
start.sh
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#
# Starts a remote sbatch jobs and sets up correct port forwarding.
# Sample usage: bash start.sh sherlock/singularity-jupyter
# bash start.sh sherlock/singularity-jupyter /home/users/raphtown
# bash start.sh sherlock/singularity-jupyter /home/users/raphtown
if [ ! -f params.sh ]
then
echo "Need to configure params before first run, run setup.sh!"
exit
fi
. params.sh
if [ "$#" -eq 0 ]
then
echo "Need to give name of sbatch job to run!"
exit
fi
if [ ! -f helpers.sh ]
then
echo "Cannot find helpers.sh script!"
exit
fi
. helpers.sh
NAME="${1:-}"
# The user could request either <resource>/<script>.sbatch or
# <name>.sbatch
SBATCH="$NAME.sbatch"
# set FORWARD_SCRIPT and FOUND
set_forward_script
check_previous_submit
echo
echo "== Getting destination directory =="
RESOURCE_HOME=`ssh ${RESOURCE} pwd`
ssh ${RESOURCE} mkdir -p $RESOURCE_HOME/forward-util
echo
echo "== Uploading sbatch script =="
scp $FORWARD_SCRIPT ${RESOURCE}:$RESOURCE_HOME/forward-util/
# adjust PARTITION if necessary
set_partition
echo
echo "== Submitting sbatch =="
SBATCH_NAME=$(basename $SBATCH)
command="sbatch
--job-name=$NAME
--partition=$PARTITION
--output=$RESOURCE_HOME/forward-util/$SBATCH_NAME.out
--error=$RESOURCE_HOME/forward-util/$SBATCH_NAME.err
--mem=$MEM
--time=$TIME
$RESOURCE_HOME/forward-util/$SBATCH_NAME $PORT \"${@:2}\""
echo ${command}
ssh ${RESOURCE} ${command}
# Tell the user how to debug before trying
instruction_get_logs
# Wait for the node allocation, get identifier
get_machine
echo "notebook running on $MACHINE"
sleep $CONNECTION_WAIT_SECONDS
setup_port_forwarding
echo "== Connecting to notebook =="
# Print logs for the user, in case needed
print_logs
echo
instruction_get_logs
echo
echo "== Instructions =="
echo "1. Password, output, and error printed to this terminal? Look at logs (see instruction above)"
echo "2. Browser: http://$MACHINE:$PORT/ -> http://localhost:$PORT/..."
echo "3. To end session: bash end.sh ${NAME}"