-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-prep0.sh
55 lines (46 loc) · 1.51 KB
/
run-prep0.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
set -Ceuo pipefail
PATH=/bin:/usr/bin:/usr/local/bin
TZ=UTC; export TZ
: ${phase:=p0}
: ${nwp:=${HOME}/nwp-test}
: ${base:=${nwp}/${phase}}
# simply using wall-clock time in UTC
: ${reftime:=`date +%Y-%m-%d`}
datedir="${base}/${reftime}.new"
export phase base reftime datedir nwp
test -f "$1"
cd ${base}
# aborts by -e if nwp or base is ill-configured
if test -f stop ; then
logger --tag run-prep --id=$$ -p news.err "suspended - remove ${base}/stop"
false
fi
if mkdmsg=$(mkdir ${datedir} 2>&1)
then
: --- rotation 1: minimal renaming ---
incomplete=$(readlink incomplete || echo missing)
yesterday=$(basename $incomplete .new)
if [ -d "${incomplete}" ]; then
mv -f "${incomplete}" "${yesterday}"
ln -Tfs "${yesterday}" latest
logger --tag run-prep --id=$$ -p news.info "latest -> ${yesterday}, incomplete -> ${datedir}"
export yesterday
msg="$(echo "cd $base; nwp=$nwp bash $nwp/bin/act-p0-housekeep.sh" | TZ=UTC at -q Z 0:30 2>&1)"
logger --tag run-prep --id=$$ -p news.info "$msg"
fi
ln -Tfs ${reftime}.new incomplete
mkdir incomplete/logs
touch incomplete/logs-${reftime}.tar
gdbm incomplete/pshb.db clear
chmod o+rw incomplete/pshb.db
ln -Tf incomplete/pshb.db incomplete/psbm-${reftime}.db
if [ -f latest/jmx-${yesterday}.idx1 ]; then
ruby ${nwp}/bin/idxshadow.rb latest/jmx-${yesterday}.idx1 incomplete/jmx-${reftime}.idx1
fi
if [ -f ${nwp}/bin/act-wxmon-housekeep.sh ]; then
bash ${nwp}/bin/act-wxmon-housekeep.sh
fi
fi
cd ${datedir}
bash -$- "$@"