-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjamclean
executable file
·77 lines (64 loc) · 1.68 KB
/
jamclean
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
#!/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: jamclean
Purges inactive JAMScript programs from the listing.
EOF
}
checkrunning() {
local folder=$1
local runf=$2
local runflag="false"
for q in `ls $folder/$runf`; do
local dir=$folder/$runf$q
if [ -d $dir ]; then
if [ -e $1$q/processId ]; then
local pid=`cat $1$q/processId`
local present=`ps -p $pid | grep node | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
runflag="true"
fi
elif [ -e $1$q/dockerId ]; then
local didp=`cat $1$q/dockerId`
local present=`docker ps --filter id=$didp | grep $didp | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
runflag="true"
fi
fi
fi
done
running=$runflag
}
if [ ! -z $1 ]; then
if [ $1 == "-h" ] || [ $1 == "--help" ]; then
show_usage
exit
fi
fi
jamfolder=$HOME"/__jamruns"
if [ ! -d $jamfolder ]; then
exit 0
fi
if [ "$(ls -A $jamfolder)" ]; then
cd $jamfolder
for jruns in */; do
if [ $jruns != "*/" ]; then
if [[ $jruns =~ .*$app.* ]]; then
checkrunning $jamfolder/$jruns
if [ $running == "false" ]; then
rm -rf $jamfolder/$jruns
fi
fi
fi
done
fi