1 |
#!/bin/sh |
2 |
# |
3 |
# jetty This shell script takes care of starting and stopping jetty |
4 |
# |
5 |
# chkconfig: - 80 20 |
6 |
# description: The Jetty Webserver and Servlet Container |
7 |
# processname: jetty |
8 |
# pidfile: /var/run/jetty/jetty.pid |
9 |
# config: /etc/jetty/jetty.conf |
10 |
# |
11 |
# |
12 |
# Portions from tomcat4.init by: |
13 |
# |
14 |
# Gomez Henri <hgomez@users.sourceforge.net> |
15 |
# Keith Irwin <keith_irwin@non.hp.com> |
16 |
# Nicolas Mailhot <nicolas.mailhot@one2team.com> |
17 |
# |
18 |
### BEGIN INIT INFO |
19 |
# Provides: jetty |
20 |
# Required-Start: $network |
21 |
# Required-Stop: $network |
22 |
# Default-Start: 3 4 5 |
23 |
# Short-Description: The Jetty Webserver and Servlet Container |
24 |
# Description: The Jetty Webserver and Servlet Container |
25 |
### END INIT INFO |
26 |
|
27 |
# Source function library. |
28 |
. /etc/init.d/functions |
29 |
|
30 |
[ -r /etc/java/java.conf ] && . /etc/java/java.conf |
31 |
export JAVA_HOME |
32 |
|
33 |
# Get Jetty's config |
34 |
|
35 |
JETTY_CFG="/etc/jetty/jetty.conf" |
36 |
|
37 |
[ -r "$JETTY_CFG" ] && . "${JETTY_CFG}" |
38 |
|
39 |
# Path to the jetty launch script (direct don't use the wrapper) |
40 |
JETTY_SCRIPT=/usr/bin/djetty |
41 |
|
42 |
# if JETTY_USER is not set, use jetty |
43 |
if [ -z "$JETTY_USER" ]; then |
44 |
JETTY_USER="jetty" |
45 |
fi |
46 |
|
47 |
# if JETTY_HOME is not set, use /usr/share/jetty |
48 |
if [ -z "$JETTY_HOME" ]; then |
49 |
JETTY_HOME="/usr/share/jetty" |
50 |
fi |
51 |
|
52 |
if [ -z "$SHUTDOWN_WAIT" ]; then |
53 |
SHUTDOWN_WAIT=10 |
54 |
fi |
55 |
|
56 |
if [ -z "$JETTY_PID" ]; then |
57 |
JETTY_PID=/var/run/jetty/jetty.pid |
58 |
fi |
59 |
|
60 |
|
61 |
prog=jetty |
62 |
RETVAL=0 |
63 |
|
64 |
start() { |
65 |
|
66 |
if [ -f /var/lock/subsys/jetty ] ; then |
67 |
if [ -f $JETTY_PID ]; then |
68 |
read kpid < $JETTY_PID |
69 |
if checkpid $kpid 2>&1; then |
70 |
echo "process already running" |
71 |
return -1 |
72 |
else |
73 |
echo "lock file found but no process running for pid $kpid, continuing" |
74 |
fi |
75 |
fi |
76 |
fi |
77 |
|
78 |
echo -n $"Starting $prog: " |
79 |
# [ -x ${JETTY_HOME}/ext ] && |
80 |
# rebuild-jar-repository -s ${JETTY_HOME}/ext |
81 |
|
82 |
if [ -x /etc/rc.d/init.d/functions ]; then |
83 |
daemon --user $JETTY_USER JETTY_PID=$JETTY_PID $JETTY_SCRIPT |
84 |
else |
85 |
su - $JETTY_USER -c "JETTY_PID=$JETTY_PID $JETTY_SCRIPT" |
86 |
fi |
87 |
|
88 |
RETVAL=$? |
89 |
[ $RETVAL = 0 ] && touch /var/lock/subsys/jetty && success || failure |
90 |
echo |
91 |
return $RETVAL |
92 |
} |
93 |
|
94 |
|
95 |
stop() { |
96 |
|
97 |
if [ -f /var/lock/subsys/jetty ] ; then |
98 |
echo -n $"Stopping $prog: " |
99 |
count=0; |
100 |
|
101 |
if [ -f $JETTY_PID ]; then |
102 |
|
103 |
read kpid < $JETTY_PID |
104 |
let kwait=$SHUTDOWN_WAIT |
105 |
|
106 |
# Try issuing SIGTERM |
107 |
|
108 |
kill -15 $kpid |
109 |
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ] |
110 |
do |
111 |
# echo "waiting for processes to exit"; |
112 |
sleep 1 |
113 |
let count=$count+1; |
114 |
done |
115 |
|
116 |
if [ $count -gt $kwait ]; then |
117 |
# echo "killing processes which didn't stop after $SHUTDOWN_WAIT seconds" |
118 |
kill -9 $kpid |
119 |
fi |
120 |
fi |
121 |
rm -f /var/lock/subsys/jetty $JETTY_PID |
122 |
success |
123 |
echo |
124 |
fi |
125 |
} |
126 |
|
127 |
|
128 |
|
129 |
# See how we were called. |
130 |
case "$1" in |
131 |
start) |
132 |
start |
133 |
;; |
134 |
stop) |
135 |
stop |
136 |
;; |
137 |
status) |
138 |
status -p $JETTY_PID jetty |
139 |
;; |
140 |
restart|reload) |
141 |
stop |
142 |
sleep 2 |
143 |
start |
144 |
;; |
145 |
condrestart) |
146 |
if [ -f $JETTY_PID ] ; then |
147 |
stop |
148 |
start |
149 |
fi |
150 |
;; |
151 |
*) |
152 |
echo "Usage: $0 {start|stop|status|restart|reload|condrestart}" |
153 |
exit 1 |
154 |
esac |
155 |
|
156 |
exit $RETVAL |
157 |
|
158 |
# |
159 |
# |
160 |
# end |