Skip to content

Commit 696ebcc

Browse files
committed
Adjust migimportdoi crontjob to bail out if freeze or doi is not configured.
Changed to absoulute path in importdoi.py call. Add bash flags to catch and fail hard on errors while at it. Synced updates to unit test fixture.
1 parent 535d071 commit 696ebcc

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

mig/install/migimportdoi-template.sh.cronjob

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,38 @@
22
#
33
# run importdoi as mig user
44

5+
# Force bash to handle uninitialized variables and errors
6+
# 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+
set -eEuo pipefail
9+
510
# Add any custom domains to lookup DOIs for here and format according to
611
# https://support.datacite.org/docs/api-queries
712
# where we simply filter on our own FQDN in the registered DOI url.
813
doi_fqdn="url:__PUBLIC_ALIAS_FQDN__"
914

1015
# No more edits below
11-
su - mig -c "PYTHONPATH=__MIG_BASE__ mig/server/importdoi.py $doi_fqdn"
16+
check_enabled() {
17+
su - mig -c "PYTHONPATH=__MIG_BASE__ __MIG_CODE__/server/chkenabled.py $1" >& /dev/null
18+
}
19+
check_set() {
20+
VALUE=$(su - mig -c "PYTHONPATH=__MIG_BASE__ __MIG_CODE__/server/readconfval.py $1")
21+
if [ -z "$VALUE" ]; then
22+
#echo "DEBUG: $1 not set in MiGserver conf - skipping"
23+
return 1
24+
fi
25+
return 0
26+
}
27+
28+
if ! check_enabled "freeze" ; then
29+
#echo "DEBUG: nothing to do with freeze disabled"
30+
exit 0
31+
fi
32+
if ! check_set "site_freeze_doi_url" ; then
33+
#echo "DEBUG: nothing to do with freeze doi url disabled"
34+
exit 0
35+
fi
36+
37+
su - mig -c "PYTHONPATH=__MIG_BASE__ __MIG_CODE__/server/importdoi.py $doi_fqdn"
1238

1339
exit 0

tests/fixture/confs-stdlocal/migimportdoi

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,38 @@
22
#
33
# run importdoi as mig user
44

5+
# Force bash to handle uninitialized variables and errors
6+
# 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+
set -eEuo pipefail
9+
510
# Add any custom domains to lookup DOIs for here and format according to
611
# https://support.datacite.org/docs/api-queries
712
# where we simply filter on our own FQDN in the registered DOI url.
813
doi_fqdn="url:"
914

1015
# No more edits below
11-
su - mig -c "PYTHONPATH=/home/mig mig/server/importdoi.py $doi_fqdn"
16+
check_enabled() {
17+
su - mig -c "PYTHONPATH=/home/mig /home/mig/mig/server/chkenabled.py $1" >& /dev/null
18+
}
19+
check_set() {
20+
VALUE=$(su - mig -c "PYTHONPATH=/home/mig /home/mig/mig/server/readconfval.py $1")
21+
if [ -z "$VALUE" ]; then
22+
#echo "DEBUG: $1 not set in MiGserver conf - skipping"
23+
return 1
24+
fi
25+
return 0
26+
}
27+
28+
if ! check_enabled "freeze" ; then
29+
#echo "DEBUG: nothing to do with freeze disabled"
30+
exit 0
31+
fi
32+
if ! check_set "site_freeze_doi_url" ; then
33+
#echo "DEBUG: nothing to do with freeze doi url disabled"
34+
exit 0
35+
fi
36+
37+
su - mig -c "PYTHONPATH=/home/mig /home/mig/mig/server/importdoi.py $doi_fqdn"
1238

1339
exit 0

0 commit comments

Comments
 (0)