-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshrine
103 lines (93 loc) · 1.99 KB
/
shrine
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
#!/bin/bash
#
# Based on a script by valotas: https://gist.github.com/valotas/1000094#file-tomcat-sh
#
# This shell script takes care of starting and stopping Tomcat for SHRINE
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: tomcat8
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Release implementation for Servlet 2.5 and JSP 2.1
# Short-Description: start and stop tomcat
### END INIT INFO
## Source function library.
#. /etc/rc.d/init.d/functions
RETVAL=$?
SHRINE_TOMCAT_HOME="/opt/shrine/tomcat"
SHUTDOWN_WAIT=10
tomcat_pid() {
echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep '/opt/shrine/' | awk '{ print $2 }'`
}
start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "SHRINE is already running (pid: $pid)"
else
# Start tomcat
echo "Starting SHRINE..."
ulimit -n 100000
umask 007
/bin/su -l shrine $SHRINE_TOMCAT_HOME/bin/startup.sh
pid=$(tomcat_pid)
echo "$pid" > /var/run/shrine.pid
echo "SHRINE is running (pid: $pid)"
fi
return 0
}
stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Stopping SHRINE..."
/bin/su -l shrine $SHRINE_TOMCAT_HOME/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\nwaiting for processes to exit";
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo -n -e "\nKilling $pid which didn't stop after $SHUTDOWN_WAIT seconds..."
kill -9 $pid
fi
echo -n -e "\n"
rm /var/run/shrine.pid
else
echo "SHRINE is not running"
fi
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "SHRINE is running with pid: $pid"
else
echo "SHRINE is not running"
fi
;;
*)
echo $"Usage: [sudo] $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL