-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.sh
executable file
·160 lines (132 loc) · 2.9 KB
/
process.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
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
#!/bin/bash
#
# Author: Fernando Israél García Martínez
# mail: [email protected]
#
# Limitation: This script only runs in bash version 4 or higher.
#
declare -a PIDS
RUN_FILE=/tmp/run_file
function techo(){
# Color Code
# Black 0
# Red 1
# Green 2
# Yellow 3
# Blue 4
# Magenta 5
# Cyan 6
# White 7
local COLOR=${1}
shift
tput setaf ${COLOR}
echo "$@"
tput sgr0
}
function error(){
case $1 in
1)
cat << __EOF__
There's a similar screen/process runnig, check it or remove ${RUN_FILE}.
__EOF__
;;
2)
cat << __EOF__
There isn't ${RUN_FILE}, check your 'screen' execution.
__EOF__
;;
esac
exit $1
}
function get_pids(){
local PID=$1
if [ $(ps h --ppid ${PID} -o pid) ]
then
get_pids $(ps h --ppid ${PID} -o pid)
PIDS+=(${PID})
elif [ "$(ps --pid ${PID} -o pid)" != "PID" ]
then
PIDS+=${PID}
fi
}
function start(){
[ -f ${RUN_FILE} ] && error 1
#### ----------- ####
ID="jboss_$(openssl rand -hex 4)"
COMMAND="/bin/bash /inLog/jboss-as-7.1.1.Final/bin/standalone.sh -b 0.0.0.0 -bmanagement=0.0.0.0"
SCREEN_OPTIONS="-S ${ID} -t ${ID} -m -d"
#### ---------- ####
techo 2 "Starting screen-jboss process"
screen ${SCREEN_OPTIONS} ${COMMAND}
echo "ID=${ID}" > ${RUN_FILE}
SCREEN=$(screen -ls | awk '/'${ID}'/ {print $1}')
echo "SCREEN=${SCREEN}" >> ${RUN_FILE}
echo "SCREEN_PID=${SCREEN%.*}" >> ${RUN_FILE}
screen -ls
}
function stop(){
[ ! -f ${RUN_FILE} ] && error 2
source ${RUN_FILE}
get_pids ${SCREEN_PID}
techo 1 "Stoping screen-jboss process ${SCREEN_PID}"
kill -9 ${PIDS[*]}
screen -wipe
[ $? ] && rm ${RUN_FILE}
}
function status(){
techo 2 "screens UP"
screen -ls
[ ! -f ${RUN_FILE} ] && error 2
source ${RUN_FILE}
get_pids ${SCREEN_PID}
techo 3 "screen: ${SCREEN}"
techo 1 "pids : ${PIDS[*]}"
for PID in ${PIDS[*]}
do
ps h --pid ${PID}
done
}
function flush(){
# brute force
for SCREEN in $(screen -ls | awk '/jboss_/ {print $1}')
do
get_pids ${SCREEN%.*}
techo 6 "Killing all screens ${PIDS[*]}"
kill -9 ${PIDS[*]}
done
[ $? ] && rm ${RUN_FILE}
sleep 5
screen -wipe
}
function usage(){
cat << __EOF__
Script to start/stop/status JBoss standalone process:
Usage:
./process.sh {start|stop|status|flush|help}
* start :Start JBoss, It start jboss standalone mode into a screen, this screen is detach automaticaly.
* stop :Stop JBoss, It stop jboss, It kill all java process and screen process associate to it.
* status :Show status about "screens process", not about JBoss, if you want to see JBoss status you should see the logs.
* flush :It is a brute force cleaner killer of all screens and jboss process, You can use it if the "stop procedure" fail.
JBoss log:
You can see the JBoss logs with the tail tool.
tail -f ${JBOSS_HOME}/standalone/log/*.log
__EOF__
}
ACTION=${1:-stop}
case $ACTION in
start)
start
;;
stop)
stop
;;
status)
status
;;
flush)
flush
;;
*)
usage
;;
esac