-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdjamlog
executable file
·149 lines (122 loc) · 3.91 KB
/
djamlog
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
IDIR="${BASH_SOURCE%/*}"
if [[ ! -d "$IDIR" ]]; then IDIR="$PWD"; fi
source "$IDIR/inc/misc_tools.sh"
die() {
printf '%s\n' "$1" >&2
exit 1
}
show_usage() {
cat << EOF
Extracts the logs written by the C nodes and displays them in the terminal.
Usage: djamlog [--program=pgm --app=app_name]
djamlog
Extracts the logs from the last program that was run or is running.
djamlog --program=stringlog --app=q5
Extracts the logs from the execution of stringlog under the application ID q5
if logs from such a run exists.
This is the docker version of jamlog.
EOF
}
checkdocker() {
if [ -e $1/dockerId ]; then
local didp=`cat $1/dockerId`
local present=`docker ps --filter id=$didp | grep $didp | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
running="docker"
else
running="none"
fi
fi
}
###
# Main script execution begins here...
#
jamfolder=$HOME"/__jamruns"
exit_missingdir $jamfolder "__jamruns folder missing. JAMScript tools not setup?"
appsfolder=$jamfolder/apps
exit_missingdir $appsfolder "__jamruns/apps folder missing. JAMScript tools not setup?"
cd $appsfolder
j=
while :; do
case $1 in
-h|-\?|--help)
show_usage # Display a usage synopsis.
exit
;;
-a|--app) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
app=$2
shift
else
die 'ERROR: "--app" requires a non-empty option argument.'
fi
;;
--app=?*)
app=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--app=) # Handle the case of an empty
die 'ERROR: "--app" requires a non-empty option argument.'
;;
-p|--program) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
program=$2
shift
else
die 'ERROR: "--program" requires a non-empty option argument.'
fi
;;
--program=?*)
program=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--program=) # Handle the case of an empty
die 'ERROR: "--program" requires a non-empty option argument.'
;;
-j|--j)
j=1
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
if [ -z $app ] && [ -z $program ]; then
# no args specified.. get it from previous runs
lprogram=`cat $appsfolder/program`
lapp=`cat $appsfolder/app`
else
lprogram=$program
lapp=$app
fi
if [ -e $appsfolder/$lprogram"_"$lapp ]; then
cd $appsfolder
for jruns in `ls $appsfolder/$lprogram"_"$lapp`; do
dir=$appsfolder/$lprogram"_"$lapp/$jruns
if [ -d $dir ]; then
checkdocker $dir
echo "Running " $running
if [ $running == "docker" ]; then
runon=`cat $dir/dockerId`
if [ -z $app ] && [ -z $program ]; then
if [ -z $j ]; then
docker exec -it $runon jamlog
else
docker exec -it $runon jamlog --j
fi
else
if [ -z $j ]; then
docker exec -it $runon jamlog --program=$program --app=$app
else
docker exec -it $runon jamlog --program=$program --app=$app --j
fi
fi
fi
fi
done
fi
# for jruns in */; do
# if [ -d $jruns ] && [ -e $jruns/dockerId ]; then
# dockerId=`cat $jruns/dockerId`
# docker exec -it $dockerId jamlog --program=$program --app=$app
# fi
# done