/
mycollab.sh
271 lines (236 loc) · 7.83 KB
/
mycollab.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/sh
# -----------------------------------------------------------------------------
# Control Script for the MyCollab Server
#
# Environment Variable Prerequisites
# MYCOLLAB_OPTS (Optional) Java runtime options used when the "start",
# "stop" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by MyCollab itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.
#
# JAVA_HOME Must point at your Java Development Kit installation.
# Required to run the with the "debug" argument.
#
# MYCOLLAB_PID (Optional) Path of the file which should contains the pid
# of the catalina startup java process, when start (fork) is
# used
# -----------------------------------------------------------------------------
# OS specific support. $var _must_ be set to either true or false.
export MYCOLLAB_PORT=8080
export MYCOLLAB_OPTS=-noverify -server -Xms394m -Xmx768m -XX:NewSize=128m -XX:+DisableExplicitGC -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC
cygwin=false
darwin=false
os400=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
esac
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
# Get standard environment variables
PRGDIR=`dirname "$PRG"`
# Only set MYCOLLAB_HOME if not already set
[ -z "$MYCOLLAB_HOME" ] && MYCOLLAB_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
if [ -z "$MYCOLLAB_OUT" ] ; then
MYCOLLAB_OUT="$MYCOLLAB_HOME"/logs/mycollab.out
fi
echo $MYCOLLAB_HOME
echo Log $MYCOLLAB_OUT
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$MYCOLLAB_HOME" ] && MYCOLLAB_HOME=`cygpath --unix "$MYCOLLAB_HOME"`
fi
# For OS400
if $os400; then
# Set job priority to standard for interactive (interactive - 6) by using
# the interactive priority - 6, the helper threads that respond to requests
# will be running at the same priority as interactive jobs.
COMMAND='chgjob job('$JOBNAME') runpty(6)'
system $COMMAND
# Enable multi threading
export QIBM_MULTI_THREADED=Y
fi
# Bugzilla 37848: When no TTY is available, don't output to console
have_tty=0
if [ "`tty`" != "not a tty" ]; then
have_tty=1
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
MYCOLLAB_HOME=`cygpath --absolute --windows "$MYCOLLAB_HOME"`
fi
# Set standard commands for invoking Java.
if [ -z "$JAVA_HOME" ] ; then
_RUNJAVA=java
else
_RUNJAVA="$JAVA_HOME"/bin/java
fi
# ----- Execute The Requested Command -----------------------------------------
# Bugzilla 37848: only output this if we have a TTY
if [ $have_tty -eq 1 ]; then
echo "Using MYCOLLAB_HOME: $MYCOLLAB_HOME"
if [ "$1" = "debug" ] ; then
echo "Using JAVA_HOME: $JAVA_HOME"
fi
if [ ! -z "$MYCOLLAB_PID" ]; then
echo "Using MYCOLLAB_PID: $MYCOLLAB_PID"
fi
fi
echo Param "$1"
if [ "$1" = "--start" ] ; then
if [ ! -z "$MYCOLLAB_PID" ]; then
if [ -f "$MYCOLLAB_PID" ]; then
if [ -s "$MYCOLLAB_PID" ]; then
echo "Existing PID file found during start."
if [ -r "$MYCOLLAB_PID" ]; then
PID=`cat "$MYCOLLAB_PID"`
ps -p $PID >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "MyCollab appears to still be running with PID $PID. Start aborted."
exit 1
else
echo "Removing/clearing stale PID file."
rm -f "$MYCOLLAB_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ -w "$MYCOLLAB_PID" ]; then
cat /dev/null > "$MYCOLLAB_PID"
else
echo "Unable to remove or clear stale PID file. Start aborted."
exit 1
fi
fi
fi
else
echo "Unable to read PID file. Start aborted."
exit 1
fi
else
rm -f "$MYCOLLAB_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ ! -w "$MYCOLLAB_PID" ]; then
echo "Unable to remove or write to empty PID file. Start aborted."
exit 1
fi
fi
fi
fi
fi
shift
touch "$MYCOLLAB_OUT"
cd ..
eval \"$_RUNJAVA\" -jar $MYCOLLAB_HOME/executor.jar $MYCOLLAB_OPTS -Dserver.port=$MYCOLLAB_PORT &
if [ ! -z "$MYCOLLAB_PID" ]; then
echo $! > "$MYCOLLAB_PID"
fi
elif [ "$1" = "--stop" ] ; then
shift
SLEEP=5
if [ ! -z "$1" ]; then
echo $1 | grep "[^0-9]" >/dev/null 2>&1
if [ $? -gt 0 ]; then
SLEEP=$1
shift
fi
fi
FORCE=0
if [ "$1" = "-force" ]; then
shift
FORCE=1
fi
if [ ! -z "$MYCOLLAB_PID" ]; then
if [ -f "$MYCOLLAB_PID" ]; then
if [ -s "$MYCOLLAB_PID" ]; then
kill -0 `cat "$MYCOLLAB_PID"` >/dev/null 2>&1
if [ $? -gt 0 ]; then
echo "PID file found but no matching process was found. Stop aborted."
exit 1
fi
else
echo "PID file is empty and has been ignored."
fi
else
echo "\$MYCOLLAB_PID was set but the specified file does not exist. Is MyCollab running? Stop aborted."
exit 1
fi
fi
cd ..
eval \"$_RUNJAVA\" -jar $MYCOLLAB_HOME/executor.jar --stop $MYCOLLAB_OPTS
if [ ! -z "$MYCOLLAB_PID" ]; then
if [ -f "$MYCOLLAB_PID" ]; then
while [ $SLEEP -ge 0 ]; do
kill -0 `cat "$MYCOLLAB_PID"` >/dev/null 2>&1
if [ $? -gt 0 ]; then
rm -f "$MYCOLLAB_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ -w "$MYCOLLAB_PID" ]; then
cat /dev/null > "$MYCOLLAB_PID"
else
echo "MyCollab stopped but the PID file could not be removed or cleared."
fi
fi
break
fi
if [ $SLEEP -gt 0 ]; then
sleep 1
fi
if [ $SLEEP -eq 0 ]; then
if [ $FORCE -eq 0 ]; then
echo "MyCollab did not stop in time. PID file was not removed."
fi
fi
SLEEP=`expr $SLEEP - 1 `
done
fi
fi
KILL_SLEEP_INTERVAL=5
if [ $FORCE -eq 1 ]; then
if [ -z "$MYCOLLAB_PID" ]; then
echo "Kill failed: \$MYCOLLAB_PID not set"
else
if [ -f "$MYCOLLAB_PID" ]; then
PID=`cat "$MYCOLLAB_PID"`
echo "Killing MyCollab with the PID: $PID"
kill -9 $PID
while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do
kill -0 `cat "$MYCOLLAB_PID"` >/dev/null 2>&1
if [ $? -gt 0 ]; then
rm -f "$MYCOLLAB_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
echo "MyCollab was killed but the PID file could not be removed."
fi
break
fi
if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then
sleep 1
fi
KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 `
done
if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then
echo "MyCollab has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."
fi
fi
fi
fi
else
echo "Usage: mycollab.sh ( commands ... )"
echo "commands:"
echo " start Start MyCollab in a separate window"
echo " stop Stop MyCollab, waiting up to 5 seconds for the process to end"
echo " stop -force Stop MyCollab, wait up to 5 seconds and then use kill -KILL if still running"
echo "Note: Waiting for the process to end and use of the -force option require that \$MYCOLLAB_PID is defined"
exit 1
fi