Skip to content

Commit fa2a3ba

Browse files
authored
Comment-only change to cronjobs to clarify our general error checking strategy in relation to PR382 (#383)
Comment-only change to cronjobs to clarify our general error checking strategy and explain why we sometimes choose to deviate from it. Tries to capture the central points from a longer internal discussion in relation to issue #381 and the fix in PR #382. Adds the missing fixture for the existing miglustrequota cronjob.
2 parents a5847cd + 63bf059 commit fa2a3ba

File tree

10 files changed

+111
-13
lines changed

10 files changed

+111
-13
lines changed

mig/install/migcheckssl-template.sh.cronjob

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
2121
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
2222
# exit midway, so it can be a trade-off.
23+
# IMPORTANT: we currently opt for manual exit code checks here since we deem
24+
# the consequences of an early script exit worse.
25+
# TODO: introduce individual exit code checks and re-enable '-eE' below?
26+
#set -eEuo pipefail
2327
set -uo pipefail
2428

2529
# Send output to another email address

mig/install/migimportdoi-template.sh.cronjob

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#
33
# run importdoi as mig user
44

5-
# Force bash to handle uninitialized variables and errors
5+
# By default bash silently ignores and continues on most errors but we can set
6+
# options to e.g. catch uninitialized variables and errors as explained in:
67
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
7-
# NOTE: 'set -eE' exits on failure, which is good when we handle all errors
8+
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
9+
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
10+
# exit midway, so it can be a trade-off.
811
set -eEuo pipefail
912

1013
# Add any custom domains to lookup DOIs for here and format according to

mig/install/migindexdoi-template.sh.cronjob

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#
33
# run indexdoi as mig user
44

5-
# Force bash to handle uninitialized variables and errors
5+
# By default bash silently ignores and continues on most errors but we can set
6+
# options to e.g. catch uninitialized variables and errors as explained in:
67
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
7-
# NOTE: 'set -eE' exits on failure, which is good when we handle all errors
8+
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
9+
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
10+
# exit midway, so it can be a trade-off.
811
set -eEuo pipefail
912

1013

mig/install/miglustrequota-template.sh.cronjob

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
# This is a limitation on the run-parts wrapper used by cron
1313
# (see man run-parts for the rationale behind this).
1414

15-
# Force bash to handle uninitialized variables and errors
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:
1617
# 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.
1721
set -eEuo pipefail
1822

1923
# Send output to another email address

mig/install/migverifyarchives-template.sh.cronjob

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
# any effect. Basically the ready-finalized-YYYYMMDD.txt files in archivestaging
88
# must be filled with root paths of pending archives to check.
99

10-
# Force bash to handle uninitialized variables and errors
10+
# By default bash silently ignores and continues on most errors but we can set
11+
# options to e.g. catch uninitialized variables and errors as explained in:
1112
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
12-
# NOTE: 'set -eE' exits on failure, good for debug but we want to handle errors
13+
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
14+
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
15+
# exit midway, so it can be a trade-off.
16+
# IMPORTANT: we currently opt for manual exit code checks here since we deem
17+
# the consequences of an early script exit worse.
18+
# TODO: introduce individual exit code checks and re-enable '-eE' below?
1319
#set -eEuo pipefail
1420
set -uo pipefail
1521

tests/fixture/confs-stdlocal/migcheckssl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
2121
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
2222
# exit midway, so it can be a trade-off.
23+
# IMPORTANT: we currently opt for manual exit code checks here since we deem
24+
# the consequences of an early script exit worse.
25+
# TODO: introduce individual exit code checks and re-enable '-eE' below?
26+
#set -eEuo pipefail
2327
set -uo pipefail
2428

2529
# Send output to another email address

tests/fixture/confs-stdlocal/migimportdoi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#
33
# run importdoi as mig user
44

5-
# Force bash to handle uninitialized variables and errors
5+
# By default bash silently ignores and continues on most errors but we can set
6+
# options to e.g. catch uninitialized variables and errors as explained in:
67
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
7-
# NOTE: 'set -eE' exits on failure, which is good when we handle all errors
8+
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
9+
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
10+
# exit midway, so it can be a trade-off.
811
set -eEuo pipefail
912

1013
# Add any custom domains to lookup DOIs for here and format according to

tests/fixture/confs-stdlocal/migindexdoi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#
33
# run indexdoi as mig user
44

5-
# Force bash to handle uninitialized variables and errors
5+
# By default bash silently ignores and continues on most errors but we can set
6+
# options to e.g. catch uninitialized variables and errors as explained in:
67
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
7-
# NOTE: 'set -eE' exits on failure, which is good when we handle all errors
8+
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
9+
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
10+
# exit midway, so it can be a trade-off.
811
set -eEuo pipefail
912

1013

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

tests/fixture/confs-stdlocal/migverifyarchives

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
# any effect. Basically the ready-finalized-YYYYMMDD.txt files in archivestaging
88
# must be filled with root paths of pending archives to check.
99

10-
# Force bash to handle uninitialized variables and errors
10+
# By default bash silently ignores and continues on most errors but we can set
11+
# options to e.g. catch uninitialized variables and errors as explained in:
1112
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
12-
# NOTE: 'set -eE' exits on failure, good for debug but we want to handle errors
13+
# NOTE: 'set -eE' exits on non-zero exit codes to add safety and as recommended
14+
# best-practice (CWE-252, CWE-248, ...), yet, in some cases it hurts more to
15+
# exit midway, so it can be a trade-off.
16+
# IMPORTANT: we currently opt for manual exit code checks here since we deem
17+
# the consequences of an early script exit worse.
18+
# TODO: introduce individual exit code checks and re-enable '-eE' below?
1319
#set -eEuo pipefail
1420
set -uo pipefail
1521

0 commit comments

Comments
 (0)