|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Run lustre quota for MiG servers |
| 4 | +# |
| 5 | +# The script depends on a miglustrequota setup |
| 6 | +# (please refer to mig/src/pylustrequota/README). |
| 7 | +# |
| 8 | +# IMPORTANT: if placed in /etc/cron.X the script filename must be |
| 9 | +# something consisting entirely of upper and lower case letters, digits, |
| 10 | +# underscores, and hyphens. I.e. if the script name contains e.g. a period, |
| 11 | +# '.', it will be silently ignored! |
| 12 | +# This is a limitation on the run-parts wrapper used by cron |
| 13 | +# (see man run-parts for the rationale behind this). |
| 14 | + |
| 15 | +# By default bash silently ignores and continues on most errors but we can set |
| 16 | +# options to e.g. catch uninitialized variables and errors as explained in: |
| 17 | +# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ |
| 18 | +# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended |
| 19 | +# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to |
| 20 | +# exit midway, so it can be a trade-off. |
| 21 | +set -eEuo pipefail |
| 22 | + |
| 23 | +# Send output to another email address |
| 24 | +#MAILTO="root" |
| 25 | + |
| 26 | +MIG_CONF=/home/mig/mig/server/MiGserver.conf |
| 27 | + |
| 28 | +# Specify if migrid runs natively or inside containers with lustre at host. |
| 29 | +# Value is the container manager (docker, podman, or empty string for none) |
| 30 | +container_manager="" |
| 31 | +container="migrid-lustre-quota" |
| 32 | + |
| 33 | +# Look in miglustrequota install dir first |
| 34 | +export PATH="/usr/local/bin:${PATH}" |
| 35 | + |
| 36 | +if [[ $(id -u) -ne 0 ]]; then |
| 37 | + echo "Please run $0 as root" |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +if [ -z "${container_manager}" ]; then |
| 42 | + miglustrequota=$(which "miglustrequota.py" 2>/dev/null) |
| 43 | + if [ ! -x "${miglustrequota}" ]; then |
| 44 | + echo "ERROR: Missing miglustrequota.py" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + quota_cmd="${miglustrequota} -c ${MIG_CONF}" |
| 48 | +else |
| 49 | + check_cmd="${container_manager} container ls -a | grep -q '${container}'" |
| 50 | + eval "$check_cmd" |
| 51 | + ret=$? |
| 52 | + if [ "$ret" -ne 0 ]; then |
| 53 | + echo "ERROR: Missing ${container} container" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + quota_cmd="${container_manager} start -a ${container}" |
| 57 | +fi |
| 58 | + |
| 59 | +eval "$quota_cmd" |
| 60 | +ret=$? |
| 61 | + |
| 62 | +exit $ret |
0 commit comments