Skip to content

Commit 00fcfe4

Browse files
authored
Merge pull request #41 from kpedro88/local_conf
call_host: automatic condor OS
2 parents fdf835c + 8e424e4 commit 00fcfe4

File tree

2 files changed

+73
-11
lines changed

2 files changed

+73
-11
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Table of Contents
1111
* [Automatic](#automatic)
1212
* [Details](#details)
1313
* [Options](#options)
14+
* [HTCondor jobs](#htcondor-jobs)
1415
* [Caveats](#caveats)
1516
* [bind_condor.sh](#bind_condorsh)
1617
* [Usage](#usage-1)
@@ -147,10 +148,19 @@ or placed in a file `~/.callhostrc` (automatically detected and sourced by `call
147148
```bash
148149
CALL_HOST_STATUS=disable cmssw-el7 ...
149150
```
151+
* To enable debug printouts by default:
152+
```bash
153+
export CALL_HOST_DEBUG=enable
154+
```
155+
or to toggle debug printouts on or off during a session:
156+
```bash
157+
call_host_debug
158+
```
159+
(if you call this inside a container, it will not silence debug printouts from the host)
150160

151-
### Caveats
161+
### HTCondor jobs
152162

153-
* cmslpc autodetection of the correct operating system for jobs is currently based on the host OS. Therefore, if you are submitting jobs in a container with a different OS, you will have to manually specify in your JDL file (the `X` in `condor_submit X`):
163+
* On cmslpc, the container OS will automatically be detected (for RHEL-based containers) and used for HTCondor jobs. To specify the job OS manually instead, include in your JDL file (the `X` in `condor_submit X`):
154164
```
155165
+DesiredOS = SL7
156166
```
@@ -160,6 +170,9 @@ or placed in a file `~/.callhostrc` (automatically detected and sourced by `call
160170
+ApptainerImage = "/path/to/your/container"
161171
```
162172
* Using the `ENV()` function in the JDL file may not function as intended, since it will be evaluated on the host node, rather than inside the container with your environment set up.
173+
174+
### Caveats
175+
163176
* Commands that require tty input (such as `nano` or `emacs -nw`) will not work with `call_host`.
164177
* Occasionally, if a command fails (especially when calling multiple commands separated by semicolons), the pipe will break and the terminal will appear to hang. The message "Interrupted system call" may be shown.
165178
It is necessary to exit and reenter the container (in order to create a new pipe) if this occurs.

call_host.sh

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# shellcheck disable=SC2155
2+
# shellcheck disable=SC2155,SC2223
33

44
# check for configuration
55
CALL_HOST_CONFIG=~/.callhostrc
@@ -8,14 +8,21 @@ if [ -f "$CALL_HOST_CONFIG" ]; then
88
source "$CALL_HOST_CONFIG"
99
fi
1010

11+
# validation
12+
call_host_valid(){
13+
VAR_TO_VALIDATE="$1"
14+
# shellcheck disable=SC2076
15+
if [[ ! " enable disable " =~ " ${!VAR_TO_VALIDATE} " ]]; then
16+
echo "Warning: unsupported value ${!VAR_TO_VALIDATE} for $VAR_TO_VALIDATE; disabling"
17+
eval "export $VAR_TO_VALIDATE=disable"
18+
fi
19+
}
20+
1121
# default values
12-
# shellcheck disable=SC2076
13-
if [ -z "$CALL_HOST_STATUS" ]; then
14-
export CALL_HOST_STATUS=enable
15-
elif [[ ! " enable disable " =~ " $CALL_HOST_STATUS " ]]; then
16-
echo "Warning: unsupported value $CALL_HOST_STATUS for CALL_HOST_STATUS; disabling"
17-
export CALL_HOST_STATUS=disable
18-
fi
22+
: ${CALL_HOST_STATUS:=enable}
23+
call_host_valid CALL_HOST_STATUS
24+
: ${CALL_HOST_DEBUG:=disable}
25+
call_host_valid CALL_HOST_DEBUG
1926
if [ -z "$CALL_HOST_DIR" ]; then
2027
if [[ "$(uname -a)" == *cms*.fnal.gov* ]]; then
2128
export CALL_HOST_DIR=~/nobackup/pipes
@@ -51,6 +58,42 @@ call_host_disable(){
5158
export CALL_HOST_STATUS=disable
5259
}
5360
export -f call_host_disable
61+
# single toggle for debug printouts
62+
call_host_debug(){
63+
if [ "$CALL_HOST_DEBUG" = "enable" ]; then
64+
export CALL_HOST_DEBUG=disable
65+
else
66+
export CALL_HOST_DEBUG=enable
67+
fi
68+
}
69+
export -f call_host_debug
70+
# helper for debug printouts
71+
call_host_debug_print(){
72+
if [ "$CALL_HOST_DEBUG" = "enable" ]; then
73+
echo "$@"
74+
fi
75+
}
76+
export -f call_host_debug_print
77+
78+
call_host_plugin_01(){
79+
# provide htcondor-specific info in container
80+
declare -A CONDOR_OS
81+
CONDOR_OS[7]="SL7"
82+
CONDOR_OS[8]="EL8"
83+
CONDOR_OS[9]="EL9"
84+
85+
# todo: only activate if function name (call_host args) includes condor?
86+
if [[ "$(uname -a)" == *cms*.fnal.gov* ]]; then
87+
OS_VERSION=$(sed -nr 's/[^0-9]*([0-9]+).*/\1/p' /etc/redhat-release 2>&1)
88+
CONDOR_OS_VAL="${CONDOR_OS[$OS_VERSION]}"
89+
if [ -n "$CONDOR_OS_VAL" ]; then
90+
echo "export FERMIHTC_OS_OVERRIDE=$CONDOR_OS_VAL;"
91+
else
92+
call_host_debug_print "echo \"could not determine condor OS from $OS_VERSION\";"
93+
fi
94+
fi
95+
}
96+
export -f call_host_plugin_01
5497

5598
# concept based on https://stackoverflow.com/questions/32163955/how-to-run-shell-script-on-host-from-docker-container
5699

@@ -63,6 +106,7 @@ listenhost(){
63106
# using { bash -c ... } >& is less fragile than eval
64107
tmpexit=0
65108
cmd="$(cat "$1")"
109+
call_host_debug_print "cmd: $cmd"
66110
{
67111
bash -c "$cmd" || tmpexit=$?
68112
} >& "$2"
@@ -99,7 +143,12 @@ call_host(){
99143
else
100144
FUNCTMP="${FUNCNAME[0]}"
101145
fi
102-
echo "cd $PWD; $FUNCTMP $*" > "$HOSTPIPE"
146+
147+
# extra environment settings; set every time because commands are executed on host in subshell
148+
# todo: evolve into full plugin system that executes detected functions/executables in order (like config.d)
149+
EXTRA="$(call_host_plugin_01)"
150+
151+
echo "cd $PWD; $EXTRA $FUNCTMP $*" > "$HOSTPIPE"
103152
cat < "$CONTPIPE"
104153
return "$(cat < "$EXITPIPE")"
105154
}

0 commit comments

Comments
 (0)