-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjamlist
executable file
·213 lines (182 loc) · 5.6 KB
/
jamlist
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# Edit the following locations to provide the correct location if needed
TMUX=`which tmux`
if [ -z $TMUX ]; then
TMUX=/usr/local/bin/tmux
fi
# No need to edit below this line unless you find a bug!
die() {
printf '%s\n' "$1" >&2
exit 1
}
show_usage() {
cat << EOF
Usage: jamlist [--app=appl_name]
Lists details about all activated instances of JAMScript programs. Use the --app=X
option to limit the listing to programs that match the given name (i.e., X).
EOF
}
checkprocess() {
if [ -e $1/processId ]; then
local pid=`cat $1/processId`
if [ $pid == "new" ]; then
running="new"
else
local present=`ps -p $pid | grep node | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
running="ps"
else
running="none"
fi
fi
elif [ -e $1/dockerId ]; then
local didp=`cat $1/dockerId`
local appid=`cat $1/appid`
if [ -z $didp ] || [ $didp == "-" ]; then
running="none"
else
local present=`docker ps --filter id=$didp | grep $didp | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
local present=`docker exec -it $didp jamlist | grep $appid | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
running="docker"
else
running="none"
fi
else
running="none"
fi
fi
else
running="none"
fi
}
# save information in global varibales
# appl=
# prog=
saveapplinfo() {
prog=`echo $1 | awk '{split($0,a,"_"); print a[1]}'`
appl=`echo $1 | awk '{split($0,a,"_"); split(a[2],b, "/"); print b[1]}'`
}
printnodeinfo() {
local port=$1
local mtype=`cat $2/machType`
local appid=`cat $2/appid`
local dstore=`cat $2/dataStore`
if [ -e $2/tmuxid ]; then
local tmuxid=`cat $2/tmuxid`
else
local tmuxid="-"
fi
if [ -e $2/parentId ]; then
local parid=`cat $2/parentId`
else
local parid='-'
fi
if [ $mtype == "device" ]; then
local cdevs=0
for pidf in `ls $2/cdevProcessId.*`; do
local pid=`cat $pidf`
local pidok=`ps -p $pid | grep a.out | wc -l | tr -d '[:space:]'`
if [ $pidok == 1 ]; then
((cdevs++))
fi
done
printf "%6s %12s %12s %12s %12s %15s %10s %7s %10s\n" "$appid" "$appl" "$prog" "Local:$port" "$parid" "$dstore" "$mtype" "$cdevs" "$tmuxid"
else
printf "%6s %12s %12s %12s %12s %15s %10s %7s %10s\n" "$appid" "$appl" "$prog" "Local:$port" "$parid" "$dstore" "$mtype" "--" "$tmuxid"
fi
}
printdockerinfo() {
local port=$1
local mtype=`cat $2/machType`
local appid=`cat $2/appid`
local dstore=`cat $2/dataStore`
if [ -e $2/tmuxid ]; then
local tmuxid=`cat $2/tmuxid`
else
local tmuxid="-"
fi
if [ -e $2/tmuxid_c ]; then
local tmuxid_c=`cat $2/tmuxid_c`
else
local tmuxid_c="-"
fi
local dockerid=`cat $2/dockerId`
tmux has-session -t $tmuxid 2>/dev/null
local res=$?
if [ $res == "1" ]; then
tmuxid="-"
fi
if [ $mtype == "device" ]; then
# local cdevs=`docker exec $dockerid jamquery $appid cdevs`
cdevs=`cat $2/cdevs`
printf "%6s %12s %12s %12s %12s %15s %10s %7s %10s\n" "$appid" "$appl" "$prog" "$dockerid" "" "$dstore" "$mtype" "$cdevs" "$tmuxid,$tmuxid_c"
else
printf "%6s %12s %12s %12s %12s %15s %10s %7s %10s\n" "$appid" "$appl" "$prog" "$dockerid" "" "$dstore" "$mtype" "--" "$tmuxid"
fi
}
printheader() {
printf "\n%6s %12s %12s %12s %12s %15s %10s %7s %10s\n" "ID" "NAME" "PROGRAM" "HOST" "PARENT" "D-STORE" "TYPE" "C-NODES" "TMUX-ID"
}
app=
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.'
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
appsfolder=$HOME"/__jamruns/apps"
if [ ! -d $appsfolder ]; then
echo "No running instances of JAMScript."
exit 0
fi
if [ "$(ls -A $appsfolder)" ]; then
cd $appsfolder
printheader
for jruns in */; do
if [ $jruns != "*/" ]; then
saveapplinfo $jruns
for jexs in `ls $appsfolder/$jruns`; do
dir=$appsfolder/$jruns$jexs
if [ -d $dir ]; then
checkprocess $dir
if [ $running == "ps" ] || [ $running == "new" ]; then
printnodeinfo $jexs $dir
elif [ $running == "docker" ]; then
printdockerinfo $jexs $dir
fi
fi
done
fi
done
else
echo "No running instances of JAMScript."
exit 0
fi