|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# this script is invoked by the OSG container init setup |
| 4 | + |
| 5 | + |
| 6 | +function kill_container() |
| 7 | +{ |
| 8 | + echo "Restarting container: $1" 2>&1 |
| 9 | + sleep 180 |
| 10 | + exit 1 |
| 11 | +} |
| 12 | + |
| 13 | +# create an env file so we can have the cron jobs run with the |
| 14 | +# same environment as the init.d run |
| 15 | +if [ -e /etc/ospool.env ]; then |
| 16 | + . /etc/ospool.env |
| 17 | +else |
| 18 | + cat >/etc/ospool.env <<EOF |
| 19 | +export OSPOOL_ENVIRONMENT=$OSPOOL_ENVIRONMENT |
| 20 | +export OSPOOL_CCB_HOSTNAME=$OSPOOL_CCB_HOSTNAME |
| 21 | +EOF |
| 22 | +fi |
| 23 | + |
| 24 | +# git repo - fetch / check for updates |
| 25 | +NEEDS_UPDATE=1 |
| 26 | +cd /opt |
| 27 | +if [ ! -e osg-flock ]; then |
| 28 | + git clone https://github.com/opensciencegrid/osg-flock.git || kill_container "Unable to pull Git repo" |
| 29 | +else |
| 30 | + # only continue with the config if changes are found |
| 31 | + cd osg-flock |
| 32 | + git fetch --quiet |
| 33 | + # Count commits that exist on the upstream branch but NOT on local branch |
| 34 | + CHANGES_COUNT=$(git rev-list --count HEAD..@{u}) |
| 35 | + if [ "$CHANGES_COUNT" -eq 0 ]; then |
| 36 | + echo "The osg-flock checkout is in sync with git repo. Nothing to do." |
| 37 | + NEEDS_UPDATE=0 |
| 38 | + fi |
| 39 | + git pull |
| 40 | +fi |
| 41 | + |
| 42 | +if [ $NEEDS_UPDATE -eq 1 ]; then |
| 43 | + |
| 44 | + # fix ownership/permissions on mounted directories |
| 45 | + chown -R condor:condor /var/log/condor |
| 46 | + chown -R condor:condor /var/lib/condor/spool |
| 47 | + |
| 48 | + # most config comes from the shared github repo below, but here is |
| 49 | + # what is specific to the cm pod |
| 50 | + cat >/etc/condor/config.d/10-ospool-ccb.config <<EOF |
| 51 | +
|
| 52 | +DAEMON_LIST = MASTER, SHARED_PORT, COLLECTOR |
| 53 | +
|
| 54 | +# FULL_HOSTNAME seems to be causing issues with HTCondor 23 |
| 55 | +#CONDOR_HOST = \$(FULL_HOSTNAME) |
| 56 | +CONDOR_HOST = 127.0.0.1 |
| 57 | +
|
| 58 | +HOST_ALIAS = $OSPOOL_CCB_HOSTNAME |
| 59 | +TCP_FORWARDING_HOST = $OSPOOL_CCB_HOSTNAME |
| 60 | +
|
| 61 | +UPDATE_COLLECTOR_WITH_TCP = True |
| 62 | +
|
| 63 | +USE_SHARED_PORT = True |
| 64 | +SHARED_PORT_MAX_WORKERS = 1000 |
| 65 | +SHARED_PORT_PORT = 9618 |
| 66 | +
|
| 67 | +# Setup 10 child collectors |
| 68 | +use feature:ChildCollector(1) |
| 69 | +use feature:ChildCollector(2) |
| 70 | +use feature:ChildCollector(3) |
| 71 | +use feature:ChildCollector(4) |
| 72 | +use feature:ChildCollector(5) |
| 73 | +use feature:ChildCollector(6) |
| 74 | +use feature:ChildCollector(7) |
| 75 | +use feature:ChildCollector(8) |
| 76 | +use feature:ChildCollector(9) |
| 77 | +use feature:ChildCollector(10) |
| 78 | +
|
| 79 | +# no forwarding here - these are only used for CCB |
| 80 | +TOP_COLLECTOR_HOST = |
| 81 | +
|
| 82 | +# limit logging |
| 83 | +COLLECTOR1.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 84 | +COLLECTOR2.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 85 | +COLLECTOR3.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 86 | +COLLECTOR4.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 87 | +COLLECTOR5.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 88 | +COLLECTOR6.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 89 | +COLLECTOR7.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 90 | +COLLECTOR8.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 91 | +COLLECTOR9.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 92 | +COLLECTOR10.MAX_COLLECTOR_LOG = \$(MAX_DEFAULT_LOG) |
| 93 | +
|
| 94 | +EOF |
| 95 | + |
| 96 | + echo "Installing HTCondor credentials..." |
| 97 | + cd /etc/ospool-creds/idkeys.d |
| 98 | + for FILE in *; do |
| 99 | + install -o root -g root -m 0600 $FILE /etc/condor/passwords.d/$FILE |
| 100 | + done |
| 101 | + cd /etc/ospool-creds/idtokens.d |
| 102 | + for FILE in *; do |
| 103 | + install -o root -g root -m 0600 $FILE /etc/condor/tokens.d/$FILE |
| 104 | + done |
| 105 | + # the gwms frontend generates tokens with kid=FRONTEND - for now make |
| 106 | + # sure we have a copy of our flock.opensciencegrid.org password in the |
| 107 | + # correct location |
| 108 | + install -o root -g root -m 0600 \ |
| 109 | + /etc/condor/passwords.d/flock.opensciencegrid.org \ |
| 110 | + /etc/condor/passwords.d/FRONTEND |
| 111 | + # SSL auth - the main hostcert comes from k8s certmanager |
| 112 | + cd /etc/ospool-creds/tls.d |
| 113 | + install -o root -g root -m 0644 tls.crt /etc/pki/tls/certs/localhost.crt |
| 114 | + install -o root -g root -m 0600 tls.key /etc/pki/tls/private/localhost.key |
| 115 | + |
| 116 | + # condor config |
| 117 | + rm -f /etc/condor/config.d/*ospoolgit* |
| 118 | + cp /opt/osg-flock/ospool.osg-htc.org/$OSPOOL_ENVIRONMENT/htcondor-config.d/* /etc/condor/config.d/ |
| 119 | + rm -f /etc/condor/config.d/90_high_availability.config |
| 120 | + rm -f /etc/condor/config.d/95_negotiator_osgflockgit.config |
| 121 | + |
| 122 | + cd /opt/osg-flock/ospool.osg-htc.org |
| 123 | + echo "Writing out new /etc/condor/certs/condor_mapfile ..." |
| 124 | + mkdir -p /etc/condor/certs |
| 125 | + ./fe-admin --target-env $OSPOOL_ENVIRONMENT --htcondor-mapfile >/etc/condor/certs/condor_mapfile |
| 126 | + echo "Writing out new /etc/condor/config.d/95_flocking_ospoolgit.config ..." |
| 127 | + ./fe-admin --target-env $OSPOOL_ENVIRONMENT --htcondor-config >/etc/condor/config.d/95_flocking_ospoolgit.config |
| 128 | + |
| 129 | + # this will fail during initial configuration, but work once the pool is up |
| 130 | + /usr/sbin/condor_reconfig || true |
| 131 | + |
| 132 | +fi |
| 133 | + |
0 commit comments