-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjaminstall
executable file
·133 lines (105 loc) · 2.86 KB
/
jaminstall
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
#!/bin/bash
IDIR="${BASH_SOURCE%/*}"
if [[ ! -d "$IDIR" ]]; then IDIR="$PWD"; fi
source "$IDIR/inc/misc_tools.sh"
# Edit the following locations to provide the
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
jamkill --all
kills all running instances
jamkill app-id
kills all running instances that are from application app-id
Usage: jamkill --all|app-id
EOF
}
killtmux() {
local tmid=$1
tmux has-session -t $tmid 2>/dev/null
local res=$?
if [ $res == "0" ]; then
tmux kill-session -t $tmid
fi
}
killprocess() {
if [ -e $1/shellpid ]; then
local pid=`cat $1/shellpid`
local present=`ps -p $pid | grep jamrun | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
kill $pid
fi
fi
if [ -e $1/processId ]; then
local pid=`cat $1/processId`
local present=`ps -p $pid | grep node | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
kill -9 $pid
fi
elif [ -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
docker kill $didp
docker rm $didp
fi
fi
}
killjob() {
local jobid=$1
for jruns in */; do
if [ $jruns != "*/" ]; then
for jexs in `ls $appsfolder/$jruns`; do
dir=$appsfolder/$jruns$jexs
if [ -d $dir ]; then
local appid=`cat $dir/appid`
if [ $appid == $jobid ]; then
echo "Killing application running at " $jexs
killprocess $dir
if [ -e $dir/tmuxid ]; then
killtmux `cat $dir/tmuxid`
fi
fi
fi
done
fi
done
}
killalljobs() {
for jruns in */; do
if [ $jruns != "*/" ]; then
for jexs in `ls $appsfolder/$jruns`; do
dir=$appsfolder/$jruns$jexs
if [ -d $dir ]; then
echo "Killing application running at " $jexs
killprocess $dir
if [ -e $dir/tmuxid ]; then
killtmux `cat $dir/tmuxid`
fi
fi
done
fi
done
}
if [ -z $1 ] || [ $1 == "-h" ] || [ $1 == "--help" ]; then
show_usage
exit
fi
jamfolder=$HOME"/__jamruns"
exit_missingdir $jamfolder "No running instances of JAMScript."
appsfolder=$jamfolder/apps
if [ "$(ls -A $appsfolder)" ]; then
cd $appsfolder
if [ $1 == "--all" ]; then
killalljobs
exit
fi
killjob $1
fi