-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrenchpress.sh
executable file
·240 lines (211 loc) · 7.7 KB
/
frenchpress.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
#!/bin/bash
SERVER=glassfish
SERVER_DIR=glassfish4
DB_VENDOR=pgsql
DB_USER=frenchpress
DB_NAME=frenchpress
DB_HOST=localhost
DB_PASS=fp
if [ -e frenchpress.properties ] ; then
source frenchpress.properties
fi
function startServer() {
if [ "$SERVER" == "glassfish" ] ; then
$SERVER_DIR/bin/asadmin start-domain --debug
elif [ "$SERVER" == "tomee" ] ; then
export JPDA_ADDRESS=9009
$SERVER_DIR/bin/catalina.sh jpda start
fi
}
function stopServer() {
if [ "$SERVER" == "glassfish" ] ; then
$SERVER_DIR/bin/asadmin stop-domain
elif [ "$SERVER" == "tomee" ] ; then
$SERVER_DIR/bin/catalina.sh stop
fi
}
function dropTables() {
SQL="drop table if exists attachments cascade; \
drop table if exists comments cascade; \
drop table if exists mediaitems cascade; \
drop table if exists pages cascade; \
drop table if exists posts cascade; \
drop table if exists sequence cascade; \
drop table if exists settings cascade; \
drop table if exists users cascade;"
if [ "$DB_VENDOR" == "pgsql" ] ; then
psql -U $DB_USER -h $DB_HOST $DB_NAME -c "$SQL"
elif [ "$DB_VENDOR" == "mysql" ] ; then
echo mysql
#mysql -u frenchpress -p frenchpress << EOL
fi
}
function deploy() {
#mvn -Dmaven.test.skip=true $CLEAN package
gradle --daemon $CLEAN assemble
if [ $? -eq 0 ] ; then
if [ "$SERVER" == "glassfish" ] ; then
$SERVER_DIR/bin/asadmin deploy --force build/exploded
elif [ "$SERVER" == "tomee" ] ; then
cp target/frenchpress*war $SERVER_DIR/webapps/frenchpress.war
fi
fi
}
function uninstall() {
if [ "$SERVER" == "glassfish" ] ; then
$SERVER_DIR/bin/asadmin undeploy `$SERVER_DIR/bin/asadmin list-applications | grep frenchpress | cut -f 1 -d " "`
elif [ "$SERVER" == "tomee" ] ; then
rm $SERVER_DIR/webapps/frenchpress.war
fi
}
function configureJdbc() {
if [ "$SERVER" == "glassfish" ] ; then
$SERVER_DIR/glassfish/bin/asadmin delete-jdbc-resource jdbc/frenchpress &> /dev/null
$SERVER_DIR/glassfish/bin/asadmin delete-jdbc-connection-pool FrenchPressPool &> /dev/null
#if [ "$DB_VENDOR" == "pgsql" ] ; then
# RES_TYPE=javax.sql.XADataSource
# DS_CLASS_NAME=org.postgresql.xa.PGXADataSource
# PROPERTIES=user=$DB_USER:password=$DB_PASS:serverName=$DB_HOST:databaseName=$DB_NAME
#elif [ "$DB_VENDOR" == "mysql" ] ; then
# RES_TYPE=javax.sql.DataSource
# DS_CLASS_NAME=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
# PROPERTIES=User=$DB_USER:Password=$DB_PASS:Host=$DB_HOST:DatabaseName=$DB_NAME
#fi
echo Creating connection pool
$SERVER_DIR/glassfish/bin/asadmin create-jdbc-connection-pool --restype=java.sql.Driver \
--driverclassname=org.hsqldb.jdbcDriver --property=User=sa:Password=\(\):PortNumber=9001:serverName=localhost:URL=jdbc\\:hsqldb\\:mem\\:`pwd`/fp FrenchPressPool > /dev/null
#$SERVER_DIR/glassfish/bin/asadmin create-jdbc-connection-pool --restype=$RES_TYPE \
# --datasourceclassname=$DS_CLASS_NAME --property=$PROPERTIES FrenchPressPool > /dev/null
echo Creating JDBC resource
#$SERVER_DIR/glassfish/bin/asadmin create-jdbc-resource --connectionpoolid=HsqlPool \
# jdbc/frenchpress_test > /dev/null
$SERVER_DIR/glassfish/bin/asadmin create-jdbc-resource --connectionpoolid=FrenchPressPool \
jdbc/frenchpress > /dev/null
echo Pinging connection pool
$SERVER_DIR/glassfish/bin/asadmin ping-connection-pool FrenchPressPool
if [ $? -ne 0 ] ; then
echo Ping the database server failed. Please correct the error and try again.
exit -1
fi
elif [ "$SERVER" == "tomee" ] ; then
if [ "$DB_VENDOR" == "pgsql" ] ; then
echo -e "<tomee><Resource id=\"frenchpress\" type=\"DataSource\">\nJdbcDriver org.postgresql.Driver\nJdbcUrl jdbc:postgresql://$DB_HOST/$DB_NAME\nUserName $DB_USER\nPassword $DB_PASS\n</Resource></tomee>" > $SERVER_DIR/conf/tomee.xml
fi
fi
}
function sqlShell() {
if [ "$DB_VENDOR" == "pgsql" ] ; then
psql -U $DB_USER -h $DB_HOST $DB_NAME
elif [ "$DB_VENDOR" == "mysql" ] ; then
mysql -u $DB_USER -h $DB_HOST -p $DB_NAME
fi
}
function setVendor() {
if [ "$1" != "pgsql" -a "$1" != "mysql" ] ; then
echo "Unsupported DB vendor ($1). Support vendors are 'pgsql' and 'mysql'."
exit -1
fi
DB_VENDOR=$1
echo Database vendor set to $DB_VENDOR
}
function installServer() {
if [ "$SERVER" == "glassfish" ] ; then
installGlassFish
elif [ "$SERVER" == "tomee" ] ; then
installTomee
fi
}
function reinstallServer() {
if [ "$SERVER" == "glassfish" ] ; then
reinstallGlassFish
elif [ "$SERVER" == "tomee" ] ; then
reinstallTomee
fi
}
function installGlassFish() {
# This function needs to take into account $SERVER_DIR during extraction
FILE=glassfish-4.0.zip
if [ ! -e $FILE ] ; then
wget http://download.java.net/glassfish/4.0/release/glassfish-4.0.zip
fi
echo Extracting GlassFish
unzip $FILE > /dev/null
sed -i -e "s/9009\"/9009\" debug-enabled=\"true\"/" glassfish4/glassfish/domains/domain1/config/domain.xml
installJars $SERVER_DIR/glassfish/lib
}
function installTomee() {
if [ ! -e tomee.tar.gz ] ; then
wget http://www.globalish.com/am/tomee/tomee-1.5.2/apache-tomee-1.5.2-jaxrs.tar.gz -O tomee.tar.gz
fi
echo Extracting Tomee
tar xf tomee.tar.gz
mv apache-tomee-jaxrs* tomee
installJars $SERVER_DIR/lib
}
function installJars() {
cd $1
wget -N http://search.maven.org/remotecontent?filepath=org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar -O jackson-mapper-asl-1.9.13.jar
wget -N http://hivelocity.dl.sourceforge.net/project/hsqldb/hsqldb/hsqldb_2_3/hsqldb-2.3.0.zip
unzip -j hsqldb-2.3.0.zip hsqldb-2.3.0/hsqldb/lib/hsqldb.jar
cd -
#for JAR in $JAR_DIR/*.jar ; do
# FILE=`basename $JAR`
# if [ ! -e $1/$FILE ] ; then
# cp $JAR $1
# fi
#done
}
function reinstallGlassFish() {
stopServer &> /dev/null
rm -rf $SERVER_DIR
installGlassFish
}
function reinstallTomee() {
stopServer &> /dev/null
rm -rf $SERVER_DIR
installTomee
}
function tailLog() {
if [ "$SERVER" == "glassfish" ] ; then
tail -f $SERVER_DIR/glassfish/domains/domain1/logs/server.log
elif [ "$SERVER" == "tomee" ] ; then
tail -f $SERVER_DIR/logs/catalina.out
fi
}
function usage() {
echo "The arguments to use are:"
echo " -c : Clean the project"
echo " -C : Open SQL shell"
echo " -d : Install Frenchpress"
echo " -D : Drop the existing tables"
echo " -i : Install the server, downloading if necessary"
echo " -I : Reinstall the server"
echo " -j : Configure the JDBC resources on the server"
echo " -l : Load sample media data and exit"
echo " -r : Restart the server"
echo " -s : Start the server"
echo " -S : Stop the server"
echo " -t : Tail the server log"
echo " -u : Uninstall FrenchPress"
echo " -v : Set database vendor"
}
while getopts cCDdiIjlrsStuv: opt
do
case "$opt" in
c) CLEAN=clean ;;
C) sqlShell ;;
D) dropTables ;;
d) deploy ;;
i) installServer ;;
I) reinstallServer ;;
j) configureJdbc ;;
l) loadSampleData ;;
r) stopServer ; startServer ;;
s) startServer ;;
S) stopServer ;;
t) tailLog ;;
u) uninstall ;;
v) setVendor $OPTARG ;;
*) usage ; exit -1 ;;
esac
done