|
| 1 | +#!/bin/bash |
| 2 | +# Adapted from https://github.com/htcondor/htcondor |
| 3 | + |
| 4 | +set -xe |
| 5 | + |
| 6 | +prog=${0##*/} |
| 7 | + |
| 8 | +fail () { |
| 9 | + echo "$prog:" "$@" >&2 |
| 10 | + exit 1 |
| 11 | +} |
| 12 | + |
| 13 | +add_values_to () { |
| 14 | + config=$1 |
| 15 | + shift |
| 16 | + printf "%s=%s\n" >> "/etc/condor/config.d/$config" "$@" |
| 17 | +} |
| 18 | + |
| 19 | +# Create a config file from the environment. |
| 20 | +# The config file needs to be on disk instead of referencing the env |
| 21 | +# at run time so condor_config_val can work. |
| 22 | +echo "# This file was created by $prog" > /etc/condor/config.d/01-env.conf |
| 23 | +add_values_to 01-env.conf \ |
| 24 | + CONDOR_HOST "${CONDOR_SERVICE_HOST:-${CONDOR_HOST:-\$(FULL_HOSTNAME)}}" \ |
| 25 | + NUM_CPUS "${NUM_CPUS:-1}" \ |
| 26 | + MEMORY "${MEMORY:-1024}" \ |
| 27 | + RESERVED_DISK "${RESERVED_DISK:-1024}" \ |
| 28 | + USE_POOL_PASSWORD "${USE_POOL_PASSWORD:-no}" |
| 29 | + |
| 30 | + |
| 31 | +bash -x "/usr/local/bin/update-secrets" || fail "Failed to update secrets" |
| 32 | +bash -x "/usr/local/bin/update-config" || fail "Failed to update config" |
| 33 | + |
| 34 | + |
| 35 | +# Bug workaround: daemons will die if they can't raise the number of FD's; |
| 36 | +# cap the request if we can't raise it. |
| 37 | +hard_max=$(ulimit -Hn) |
| 38 | + |
| 39 | +rm -f /etc/condor/config.d/01-fdfix.conf |
| 40 | +# Try to raise the hard limit ourselves. If we can't raise it, lower |
| 41 | +# the limits in the condor config to the maximum allowable. |
| 42 | +for attr in COLLECTOR_MAX_FILE_DESCRIPTORS \ |
| 43 | + SHARED_PORT_MAX_FILE_DESCRIPTORS \ |
| 44 | + SCHEDD_MAX_FILE_DESCRIPTORS \ |
| 45 | + MAX_FILE_DESCRIPTORS; do |
| 46 | + config_max=$(condor_config_val -evaluate $attr ||: ) |
| 47 | + if [[ $config_max =~ ^[0-9]+$ && $config_max -gt $hard_max ]]; then |
| 48 | + if ! ulimit -Hn "$config_max" &>/dev/null; then |
| 49 | + add_values_to 01-fdfix.conf "$attr" "$hard_max" |
| 50 | + fi |
| 51 | + ulimit -Hn "$hard_max" |
| 52 | + fi |
| 53 | +done |
| 54 | +[[ -s /etc/condor/config.d/01-fdfix.conf ]] && \ |
| 55 | + echo "# This file was created by $prog" >> /etc/condor/config.d/01-fdfix.conf |
| 56 | + |
| 57 | +chown -R condor:condor /var/log/condor /var/lib/condor/spool |
| 58 | + |
| 59 | +set +xe |
0 commit comments