Skip to content

Commit afe054f

Browse files
committed
Copy in Hosted CE image contents (SOFTWARE-4300)
1 parent f8319d0 commit afe054f

File tree

7 files changed

+575
-0
lines changed

7 files changed

+575
-0
lines changed

hosted-ce/30-remote-site-setup.sh

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
# save old -e status
6+
if [[ $- = *e* ]]; then
7+
olde=-e
8+
else
9+
olde=+e
10+
fi
11+
12+
set -e
13+
14+
BOSCO_KEY=/etc/osg/bosco.key
15+
ENDPOINT_CONFIG=/etc/endpoints.ini
16+
SKIP_WN_INSTALL=no
17+
18+
function errexit {
19+
echo "$1" >&2
20+
exit 1
21+
}
22+
23+
24+
function debug_file_contents {
25+
filename=$1
26+
echo "Contents of $filename"
27+
echo "===================="
28+
cat "$filename"
29+
echo "===================="
30+
}
31+
32+
function fetch_remote_os_info {
33+
ruser=$1
34+
rhost=$2
35+
ssh -q -i $BOSCO_KEY "$ruser@$rhost" "cat /etc/os-release"
36+
}
37+
38+
setup_ssh_config () {
39+
echo "Adding user ${ruser}"
40+
ssh_dir="/home/${ruser}/.ssh"
41+
# setup user and SSH dir
42+
adduser --base-dir /home/ "${ruser}"
43+
mkdir -p $ssh_dir
44+
chown "${ruser}": $ssh_dir
45+
chmod 700 $ssh_dir
46+
47+
# copy Bosco key
48+
ssh_key=$ssh_dir/bosco_key.rsa
49+
cp $BOSCO_KEY $ssh_key
50+
chmod 600 $ssh_key
51+
chown "${ruser}": $ssh_key
52+
53+
ssh_config=$ssh_dir/config
54+
cat <<EOF > "$ssh_config"
55+
Host $remote_fqdn
56+
Port $remote_port
57+
IdentityFile ${ssh_key}
58+
IdentitiesOnly yes
59+
EOF
60+
debug_file_contents "$ssh_config"
61+
62+
# setup known hosts
63+
known_hosts=$ssh_dir/known_hosts
64+
echo "$REMOTE_HOST_KEY" >> "$known_hosts"
65+
debug_file_contents $known_hosts
66+
67+
for ssh_file in $ssh_dir/config $ssh_dir/known_hosts; do
68+
chown "${ruser}": "$ssh_file"
69+
done
70+
71+
# debugging
72+
ls -l "$ssh_dir"
73+
}
74+
75+
76+
# Install the WN client, CAs, and CRLs on the remote host
77+
# Store logs in /var/log/condor-ce/ to simplify serving logs via Kubernetes
78+
setup_endpoints_ini () {
79+
echo "Setting up endpoint.ini entry for ${ruser}@$remote_fqdn..."
80+
remote_os_major_ver=$1
81+
# The WN client updater uses "remote_dir" for WN client
82+
# configuration and remote copy. We need the absolute path
83+
# specifically for fetch-crl
84+
remote_home_dir=$(ssh -q -i $BOSCO_KEY "${ruser}@$remote_fqdn" pwd)
85+
osg_ver=3.4
86+
if [[ $remote_os_major_ver -gt 6 ]]; then
87+
osg_ver=3.5
88+
fi
89+
cat <<EOF >> $ENDPOINT_CONFIG
90+
[Endpoint ${RESOURCE_NAME}-${ruser}]
91+
local_user = ${ruser}
92+
remote_host = $remote_fqdn
93+
remote_user = ${ruser}
94+
remote_dir = $remote_home_dir/bosco-osg-wn-client
95+
upstream_url = https://repo.opensciencegrid.org/tarball-install/${osg_ver}/osg-wn-client-latest.el${remote_os_major_ver}.x86_64.tar.gz
96+
EOF
97+
}
98+
99+
# $REMOTE_HOST needs to be specified in the environment
100+
remote_fqdn=${REMOTE_HOST%:*}
101+
if [[ $REMOTE_HOST =~ :[0-9]+$ ]]; then
102+
remote_port=${REMOTE_HOST#*:}
103+
else
104+
remote_port=22
105+
fi
106+
107+
REMOTE_HOST_KEY=`ssh-keyscan -p "$remote_port" "$remote_fqdn"`
108+
[[ -n $REMOTE_HOST_KEY ]] || errexit "Failed to determine host key for $remote_fqdn:$remote_port"
109+
110+
# HACK: Symlink the Bosco key to the location expected by
111+
# bosco_cluster so it doesn't go and try to generate a new one
112+
root_ssh_dir=/root/.ssh/
113+
mkdir -p $root_ssh_dir
114+
chmod 700 $root_ssh_dir
115+
ln -s $BOSCO_KEY $root_ssh_dir/bosco_key.rsa
116+
117+
cat <<EOF > /etc/ssh/ssh_config
118+
Host $remote_fqdn
119+
Port $remote_port
120+
IdentityFile ${BOSCO_KEY}
121+
ControlMaster auto
122+
ControlPath /tmp/cm-%i-%r@%h:%p
123+
ControlPersist 15m
124+
EOF
125+
debug_file_contents /etc/ssh/ssh_config
126+
127+
echo "$REMOTE_HOST_KEY" >> /etc/ssh/ssh_known_hosts
128+
debug_file_contents /etc/ssh/ssh_known_hosts
129+
130+
# Populate the bosco override dir from a Git repo
131+
if [[ -n $BOSCO_GIT_ENDPOINT && -n $BOSCO_DIRECTORY ]]; then
132+
OVERRIDE_DIR=/etc/condor-ce/bosco_override
133+
/usr/local/bin/bosco-override-setup.sh "$BOSCO_GIT_ENDPOINT" "$BOSCO_DIRECTORY" /etc/osg/git.key
134+
fi
135+
unset GIT_SSH_COMMAND
136+
137+
users=$(cat /etc/grid-security/grid-mapfile /etc/grid-security/voms-mapfile | \
138+
awk '/^"[^"]+" +[a-zA-Z0-9\-\._]+$/ {print $NF}' | \
139+
sort -u)
140+
[[ -n $users ]] || errexit "Did not find any user mappings in the VOMS or Grid mapfiles"
141+
142+
# Allow the condor user to run the WN client updater as the local users
143+
CONDOR_SUDO_FILE=/etc/sudoers.d/10-condor-ssh
144+
condor_sudo_users=`tr ' ' ',' <<< $users`
145+
echo "condor ALL = ($condor_sudo_users) NOPASSWD: /usr/bin/update-remote-wn-client" \
146+
> $CONDOR_SUDO_FILE
147+
chmod 644 $CONDOR_SUDO_FILE
148+
149+
grep -qs '^OSG_GRID="/cvmfs/oasis.opensciencegrid.org/osg-software/osg-wn-client' \
150+
/var/lib/osg/osg-job-environment*.conf && SKIP_WN_INSTALL=yes
151+
152+
# Enable bosco_cluster debug output
153+
bosco_cluster_opts=(-d )
154+
if [[ -n $OVERRIDE_DIR ]]; then
155+
if [[ -d $OVERRIDE_DIR ]]; then
156+
bosco_cluster_opts+=(-o "$OVERRIDE_DIR")
157+
else
158+
echo "WARNING: $OVERRIDE_DIR is not a directory. Skipping Bosco override."
159+
fi
160+
fi
161+
162+
[[ $REMOTE_BOSCO_DIR ]] && bosco_cluster_opts+=(-b "$REMOTE_BOSCO_DIR") \
163+
|| REMOTE_BOSCO_DIR=bosco
164+
165+
echo "Using Bosco tarball: $(bosco_findplatform --url)"
166+
for ruser in $users; do
167+
setup_ssh_config
168+
done
169+
170+
###################
171+
# REMOTE COMMANDS #
172+
###################
173+
174+
# We have to pick a user for SSH, may as well be the first one
175+
remote_os_info=$(fetch_remote_os_info "$(printf "%s\n" $users | head -n1)" "$remote_fqdn")
176+
remote_os_ver=$(echo "$remote_os_info" | awk -F '=' '/^VERSION_ID/ {print $2}' | tr -d '"')
177+
178+
# Skip WN client installation for non-RHEL-based remote clusters
179+
[[ $remote_os_info =~ (^|$'\n')ID_LIKE=.*(rhel|centos|fedora) ]] || SKIP_WN_INSTALL=yes
180+
181+
# HACK: By default, Singularity containers don't specify $HOME and
182+
# bosco_cluster needs it
183+
[[ -n $HOME ]] || HOME=/root
184+
185+
for ruser in $users; do
186+
echo "Installing remote Bosco installation for ${ruser}@$remote_fqdn"
187+
[[ $SKIP_WN_INSTALL == 'no' ]] && setup_endpoints_ini "${remote_os_ver%%.*}"
188+
# $REMOTE_BATCH needs to be specified in the environment
189+
bosco_cluster "${bosco_cluster_opts[@]}" -a "${ruser}@$remote_fqdn" "$REMOTE_BATCH"
190+
191+
echo "Installing environment files for $ruser@$remote_fqdn..."
192+
# Copy over environment files to allow for dynamic WN variables (SOFTWARE-4117)
193+
rsync -av /var/lib/osg/osg-*job-environment.conf \
194+
"${ruser}@$remote_fqdn:$REMOTE_BOSCO_DIR/glite/etc"
195+
done
196+
197+
if [[ $SKIP_WN_INSTALL == 'no' ]]; then
198+
echo "Installing remote WN client tarballs..."
199+
sudo -u condor update-all-remote-wn-clients --log-dir /var/log/condor-ce/
200+
else
201+
echo "SKIP_WNCLIENT = True" > /etc/condor-ce/config.d/50-skip-wnclient-cron.conf
202+
echo "Skipping remote WN client tarball installation, using CVMFS..."
203+
fi
204+
205+
set $olde

hosted-ce/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARGS BASE_YUM_REPO=release
2+
3+
FROM opensciencegrid/compute-entrypoint:$BASE_YUM_REPO
4+
LABEL maintainer "OSG Software <[email protected]>"
5+
6+
ARGS BASE_YUM_REPO=release
7+
8+
RUN if [[ $BASE_YUM_REPO = release ]]; then \
9+
yumrepo=osg-upcoming; else \
10+
yumrepo=osg-upcoming-$BASE_YUM_REPO; fi && \
11+
yum install -y --enablerepo=$yumrepo \
12+
osg-ce-bosco && \
13+
rm -rf /var/cache/yum/
14+
15+
COPY 30-remote-site-setup.sh /etc/osg/image-config.d/
16+
17+
# HACK: override condor_ce_jobmetrics from SOFTWARE-4183 until it is released in
18+
# HTCondor-CE.
19+
ADD overrides/condor_ce_jobmetrics /usr/share/condor-ce/condor_ce_jobmetrics
20+
21+
# Use "ssh -q" in bosco_cluster until the chang has been upstreamed to condor
22+
COPY overrides/ssh_q.patch /tmp
23+
RUN patch -d / -p0 < /tmp/ssh_q.patch
24+
25+
# Enable bosco_cluster xtrace
26+
COPY overrides/bosco_cluster_xtrace.patch /tmp
27+
RUN patch -d / -p0 < /tmp/bosco_cluster_xtrace.patch
28+
29+
# HACK: Don't copy over the SSH pub key to the remote side. We set
30+
# this up with the site out of band.
31+
COPY overrides/skip_key_copy.patch /tmp
32+
RUN patch -d / -p0 < /tmp/skip_key_copy.patch
33+
34+
# Fix Ubuntu20 OS detection (SOFTWARE-4463)
35+
# Can be dropped when HTCONDOR-242 is involved
36+
COPY overrides/HTCONDOR-242.remote-os-detection.patch /tmp
37+
RUN patch -d / -p0 < /tmp/HTCONDOR-242.remote-os-detection.patch
38+
39+
# Set up Bosco override dir from Git repo (SOFTWARE-3903)
40+
# Expects a Git repo with the following directory structure:
41+
# RESOURCE_NAME_1/
42+
# bosco_override/
43+
# ...
44+
# RESOURCE_NAME_2/
45+
# bosco_override/
46+
# ...
47+
# ...
48+
COPY bosco-override-setup.sh /usr/local/bin
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--- /usr/bin/bosco_cluster
2+
+++ /usr/bin/bosco_cluster
3+
@@ -253,31 +253,51 @@ ssh_find_remote () {
4+
# Find the platform of the remote host
5+
# 1. remote host
6+
remote_host=$1
7+
- cmd_out=`ssh $remote_host "python3 -c \"import sys; import platform; mydist = platform.dist(); print('%s %s%s' % (sys.platform, mydist[0], mydist[1]))\"" 2>/dev/null`
8+
- if [ $? -eq 0 ]; then
9+
- # check for linux
10+
- case "$cmd_out" in
11+
- (*redhat7* | *centos7*)
12+
- echo "CentOS7" ;;
13+
- (*redhat8* | *centos8*)
14+
- echo "CentOS8" ;;
15+
- (*debian9*)
16+
- echo "Debian9" ;;
17+
- (*debian10*)
18+
- echo "Debian10" ;;
19+
- (*Ubuntu16*)
20+
- echo "Ubuntu16" ;;
21+
- (*Ubuntu18*)
22+
- echo "Ubuntu18" ;;
23+
- (*Ubuntu20*)
24+
- echo "Ubuntu20" ;;
25+
- (*darwin*)
26+
- echo "MacOSX" ;;
27+
- (*) ;;
28+
- esac
29+
- return 0
30+
- fi
31+
- return 1
32+
+
33+
+ # Returns 'Darwin' for Mac OS X or 'Linux'
34+
+ detect_os=`ssh $remote_host "uname -s"`
35+
+ [[ $? -eq 0 ]] || return 1
36+
+
37+
+ case "$detect_os" in
38+
+ Linux)
39+
+ ssh_detect_linux_distro "$remote_host"
40+
+ return $?
41+
+ ;;
42+
+ Darwin)
43+
+ echo "MacOSX"
44+
+ return 0
45+
+ ;;
46+
+ *)
47+
+ return 1
48+
+ ;;
49+
+ esac
50+
+}
51+
+
52+
+
53+
+ssh_detect_linux_distro () {
54+
+ # Find the linux distro of the remote host
55+
+ # 1. remote host
56+
+ remote_host=$1
57+
+
58+
+ os_release=`ssh $remote_host "cat /etc/os-release" 2> /dev/null`
59+
+ [[ $? -eq 0 ]] || return 1
60+
+
61+
+ dist=`echo "$os_release" | awk -F '=' '/^ID=/ {print $2}' | tr -d '"'`
62+
+ ver=`echo "$os_release" | awk -F '=' '/^VERSION_ID=/ {print $2}' | tr -d '"'`
63+
+ major_ver="${ver%%.*}"
64+
+
65+
+ case "$dist" in
66+
+ (rhel|centos)
67+
+ echo "CentOS${major_ver}" ;;
68+
+ debian)
69+
+ echo "Debian${major_ver}" ;;
70+
+ ubuntu)
71+
+ echo "Ubuntu${major_ver}" ;;
72+
+ (*)
73+
+ return 1
74+
+ ;;
75+
+ esac
76+
+ return 0
77+
}
78+
79+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/src/condor_contrib/bosco/bosco_cluster b/src/condor_contrib/bosco/bosco_cluster
2+
index ebcb582ab4..7afd1c7c5e 100755
3+
--- /usr/bin/bosco_cluster
4+
+++ /usr/bin/bosco_cluster
5+
@@ -778,6 +778,7 @@ while true; do
6+
esac
7+
done
8+
9+
+[[ $debug -eq 1 ]] && set -x
10+
11+
################################################################
12+
# The rest of the file covers the 'add' cluster functionality.

0 commit comments

Comments
 (0)