Skip to content
Snippets Groups Projects
limits.sh 408 B
Newer Older
Olivier Benz's avatar
Olivier Benz committed
#!/bin/bash
# Copyright (c) 2023 b-data GmbH.
# Distributed under the terms of the MIT License.

set -e

Olivier Benz's avatar
Olivier Benz committed
DIVISOR=1024

if [[ "$SWAP_ENABLE" == "1" || "$SWAP_ENABLE" == "yes" ]]; then
  FACTOR=$(echo 1 "${SWAP_FACTOR:-1}" | awk '{ printf "%.1f", $1 + $2 }')
Olivier Benz's avatar
Olivier Benz committed
else
  FACTOR=1
fi

if [ -n "$MEM_LIMIT" ]; then
  ulimit -Sv "$(echo "$MEM_LIMIT" "$DIVISOR $FACTOR" |
    awk '{ printf "%.0f", $1 / $2 * $3 }')"
Olivier Benz's avatar
Olivier Benz committed
fi