-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
60 lines (49 loc) · 1.86 KB
/
entrypoint.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
56
57
58
59
60
#!/usr/bin/env bash
# ===================================================
# TRAINING TASK LAUNCHER
# ===================================================
# make sure that there is exactly one script argument
if [ $# -ne 1 ]; then
echo "Invalid entrypoint arguments! Expecting exactly one argument!"
exit 1
fi
# when the help option is used, print the USAGE to console and exit
if [ "--help" == "$1" ]; then
echo "USAGE"
echo "================================"
echo "docker run nwins <settings_file>"
echo "settings_file: relative path to the settings file in $SETTINGS_ROOT location"
exit 0
fi
# write environment settings to docker logs
echo "environment settings:"
echo "==========================================="
echo " src root: $SRC_ROOT"
echo " settings root: $SETTINGS_ROOT"
echo " logs root: $LOGS_ROOT"
echo " models root: $MODELS_ROOT"
echo "==========================================="
echo ""
# determine the settings file to be used
SETTINGS=$1
# determine the logfile path
LOGFILE=$LOGS_ROOT/log_$(echo $SETTINGS | cut -f 1 -d '.')_$(date "+%Y-%m-%d_%H-%M-%S").txt
# create dirs to store logs and trained models
mkdir -p $LOGS_ROOT
mkdir -p $MODELS_ROOT
# write training task settings to docker logs
echo "training settings:"
echo "==========================================="
echo " settings file: $SETTINGS_ROOT/$SETTINGS"
echo " log file: $LOGFILE"
echo "==========================================="
echo ""
# start the training task
dotnet nWins.Training.dll --settings $SETTINGS 2>&1 | tee $LOGFILE &
# add handler for SIGTERM ('docker stop') and INT (Ctrl+C) signal
# on signal -> gracefully exit training loop
trap 'kill -15 $(pgrep dotnet) && sleep 8' SIGTERM INT
wait
# ===================================================
# 2021-01-01
# ===================================================