-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparade
186 lines (171 loc) · 5.62 KB
/
parade
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
#! /bin/sh
#
# parade Initscript for parade
#
# Author: Heinrich Moser <[email protected]>
#
# Version: initial 1.0 03-Jan-2006 [email protected]
# added reload option 1.1 03-Jan-2006 [email protected]
# increased restart sleep time 1.2 10-Apr-2007 [email protected]
# made script modifications to use parade2 1.3 24-Dec-2007 [email protected]
# added check for inotify value, so that JNotify works well 1.4 29-Jan-2008 [email protected]
# increased sleeping time before parade restart 1.5 29-Mar-2008 [email protected]
# added function that cleans the database cache 1.6 29-Mar-2008 [email protected]
# added function that cleans the tomcat work and conf dirs 1.7 10-Jun-2008 [email protected]
# added feature to do a frech checkout that keeps the configuration 1.8 [email protected]
# fixed path to catalina.out (now date dependent) 1.9 18-09-2008 [email protected]
# added crawl target to crawl row relations 2.0 2-11-2008 [email protected]
#
set -e
DESC="BEST Parade"
SCRIPTNAME=/etc/init.d/parade
D_USER=parade
D_PATH=~parade/server/parade2
eval D_HOME=~$D_USER
#
# Function that starts the daemon/service.
#
d_start() {
if [ `cat /proc/sys/fs/inotify/max_user_watches` -lt 64000 ]; then
echo "Error launching ParaDe: you have to increase the number of inode watches to 64000 by running 'echo 64000 > /proc/sys/fs/inotify/max_user_watches' as root"
exit 1
fi
su -c "cd $D_PATH; nohup ant tomcat &" - "$D_USER"
}
#
# Function that stops the daemon/service.
#
d_stop() {
su -c "cd $D_PATH; ant tomcat-stop" - "$D_USER"
echo "Initiated stopping, sleeping 15 seconds"
sleep 15
echo "Tomcat logs (check if tomcat really stopped, look for a line like 'Tomcat terminated at ... '):"
tail -n 15 $D_PATH/tomcat/logs/catalina.`date +%Y-%m-%d`.log
}
#
# Function that takes the stacktrace logs to a file.
#
d_stacktrace() {
TOMCATID=`pgrep -u parade -f 'org.apache.catalina.startup.Bootstrap start$'`
LOGFILE=$D_HOME/server/parade/webapp/stacktraces/parade-crash-stacktrace_`date +%Y%m%d_%H%M`.txt
echo ". Kill -QUIT process ID '$TOMCATID'"
su -c "kill -QUIT $TOMCATID" - "$D_USER"
echo "Initiated strack traces, sleeping 5 seconds"
sleep 5
echo "Writing last 1500 lines of the logs to file '$LOGFILE'."
echo "If this is not enough lines, please run manually 'tail -n1500 $D_PATH/tomcat/logs/catalina.`date +%Y-%m-%d`.log > $LOGFILE' with a higher value!"
tail -n1500 $D_PATH/tomcat/logs/catalina.`date +%Y-%m-%d`.log > $LOGFILE
}
#
# Function that kills the process.
#
d_kill() {
TOMCATID=`pgrep -u parade -f 'org.apache.catalina.startup.Bootstrap start$'`
echo ". Killing Tomcat with process ID '$TOMCATID'"
su -c "kill -9 $TOMCATID" - "$D_USER"
}
#
# Function that cleans the database cache after dumping it.
#
d_clean() {
echo Dumping ParaDe database...
mysqldump -u root parade -h localhost > $D_PATH/parade.sql
echo Finished dumping parade database
echo Cleaning ParaDe cache...
mysql parade -h localhost -u root < $D_PATH/cleanParadeCache.sql
echo Finished cleaning ParaDe cache
}
#
# Function that cleans tomcat's work and conf directories
#
d_cleanTomcat() {
echo Cleaning tomcat...
su -c "cd $D_PATH; ant cleanTomcat" - "$D_USER"
echo Finished cleaning tomcat
}
#
# Function that crawls all the rows and extracts relations
#
d_crawl() {
echo Crawling rows...
su -c "cd $D_PATH; ant crawlRows" - "$D_USER"
echo Finished crawling rows
}
#
# Function that does the whole process.
#
d_all() {
d_stacktrace
d_kill
d_start
}
d_checkout() {
echo "Backing up the ParaDe configuration"
su -c "cd $D_PATH; sh backupConfig.sh" - "$D_USER"
echo "Checking out from CVS - password for user parade is 'paradeaether'"
su -c "cd $D_PATH/..; cvs -d:extssh:[email protected]:/cvsroot/parade co parade2" - "$D_USER"
echo "Restoring the ParaDe configuration"
su -c "cd $D_PATH; sh restoreConfig.sh" - "$D_USER"
echo "Copying 64 bit version of native Jnotify library (backup is libjnotify32.so)"
su -c "cd $D_PATH; cp libjnotify.so libjnotify32.so; cp libjnotify64.so libjnotify.so" - "$D_USER"
}
case "$1" in
start)
echo -n "Starting $DESC"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC"
d_stop
echo "."
;;
restart)
echo -n "Restarting $DESC"
d_stop
echo "Sleeping 15 seconds to give $DESC time to shut down."
sleep 15
d_start
echo "."
;;
stacktrace)
echo -n "Taking $DESC logs"
d_stacktrace
echo "."
;;
kill)
echo -n "Killing $DESC"
d_kill
echo "."
;;
clean)
echo -n "Cleaning the database"
d_clean
echo "."
;;
cleanTomcat)
echo -n "Cleaning tomcat"
d_cleanTomcat
echo "."
;;
crawl)
echo -n "Crawling rows"
d_crawl
echo "."
;;
checkout)
echo -n "Checking out fresh ParaDe copy"
d_checkout
echo "."
;;
all)
echo -n "Full service $DESC"
d_all
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|kill|stacktrace|clean|cleanTomcat|crawl|checkout|all}" >&2
exit 1
;;
esac
exit 0