forked from symfony-cmf/cmf-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jack
executable file
·195 lines (165 loc) · 5.04 KB
/
jack
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
#!/bin/bash
cd $(dirname $0)
VERSION=2.6.0
JAR=jackrabbit-standalone-$VERSION.jar
# one per line
MIRRORS="http://mirror.switch.ch/mirror/apache/dist/jackrabbit/"
action="$1"; shift
args="$*"
pidfile=${TMPDIR:-/tmp}/jack.pid
JAR=
usage() {
echo "usage: $(basename $0) <action> [args]"
echo
echo "actions:"
echo -e " start\t\tStarts jackrabbit in the background with the given arguments"
echo -e " stop\t\tStops jackrabbit"
echo -e " restart\tRestarts jackrabbit"
echo -e " status\tPrint current status of jackrabbit (running, stopped)"
echo -e " log\t\tTails the logfile"
echo -e " clear\t\tResets index"
echo -e " flush\t\tWipes the db"
echo -e " flush:article\tRemoves today's articles (alternatively, use 'all' for removing all articles or pass the subpath to delete, e.g., '2011/04/26')"
}
if [ -z "$action" ]; then
usage
exit 1
fi
# kills jackrabbit and sleeps till process dies
# prints the id of the process previously active process (or empty if it wasn't running)
stop_jackrabbit() {
local id=$(cat $pidfile 2>/dev/null)
if [ -n "$id" ]; then
kill $id 2>/dev/null
# wait till process dies
kill -0 $id
while [[ $? -eq 0 ]]; do
sleep 1
kill -0 $id 2>/dev/null
done
fi
rm -f $pidfile
echo $id
}
verify_jackrabbit() {
local name="jackrabbit-standalone-$VERSION.jar"
JAR="$(ls -1 $name 2>/dev/null | tail -n 1)"
if [ -z "$JAR" ]; then
if [ "$VERSION" = "*" ]; then
echo "No file found matching $name"
echo "Get it at http://mirror.switch.ch/mirror/apache/dist/jackrabbit/"
exit 1
fi
read -p "$name not found. Download? [y/N] "
echo
if [[ ! $REPLY =~ [Yy] ]]; then
exit
fi
JAR="$name"
echo "Be patient, this might take a minute..."
for m in $MIRRORS; do
url="${m%/}/$VERSION/$name"
echo -n "Downloading from $url"
code=$(curl -w %{http_code} -s $url -o jackrabbit.jar.tmp)
if [ $code != "200" ]; then
echo " [FAILED: $code]"
continue
fi
echo " [OKAY]"
mv jackrabbit.jar.tmp $name
done
rm -f jackrabbit.jar.tmp
fi
}
# starts jackrabbit in the background
start_jackrabbit() {
verify_jackrabbit
if [ -e "$JAR" ]; then
# already running?
if [ -e $pidfile ]; then
echo "jackrabbit seems to be running ($pidfile)"
echo "Use \`jack restart\` or \`jack stop\`"
exit 1
fi
echo "Starting in the background using: $JAR"
java -Xmx1024m -Xms512m -jar $JAR $args &
echo $! > $pidfile
else
echo "File not found: $JAR"
exit 1
fi
}
status_jackrabbit() {
if [ ! -e $pidfile ]; then
echo "Not running ($pidfile not found)"
else
echo "Running ($pidfile says $(cat $pidfile))"
fi
}
case "$action" in
clear)
wasrunning=$(stop_jackrabbit)
rm -rf jackrabbit/repository/index
rm -rf jackrabbit/workspaces/nzz/index
rm -rf jackrabbit/workspaces/nzz_test/index
echo 'Cleared repository and workspace.'
[ $wasrunning ] && start_jackrabbit
;;
flush:article)
[ -z $args ] && args=$(date +%Y/%m/%d)
[ $args = "all" ] && args=""
curl -X DELETE http://admin:admin@localhost:8080/server/nzz/jcr:root/article/$args
;;
flush)
read -p "This will truncate the DB. Continue? [y/N]"
if [[ ! $REPLY =~ [Yy] ]]; then
exit
fi
wasrunning=$(stop_jackrabbit)
rm -rf jackrabbit/repository/datastore
rm -rf jackrabbit/repository/index
rm -rf jackrabbit/workspaces/nzz/index
rm -rf jackrabbit/workspaces/nzz/db
rm -rf jackrabbit/version
echo 'Flushed repository and workspace.'
[ $wasrunning ] && start_jackrabbit
;;
flush:test)
read -p "This will truncate the test DB. Continue? [y/N]"
if [[ ! $REPLY =~ [Yy] ]]; then
exit
fi
wasrunning=$(stop_jackrabbit)
# rm -rf jackrabbit/repository/datastore
# rm -rf jackrabbit/repository/index
rm -rf jackrabbit/workspaces/nzz_test/index
rm -rf jackrabbit/workspaces/nzz_test/db
rm -rf jackrabbit/version
echo 'Flushed repository and workspace.'
[ $wasrunning ] && start_jackrabbit
;;
register)
app/console doctrine:phpcr:register-system-node-types
app/console doctrine:phpcr:register-node-types ./script/nzz_unstructure.cnd --allow-update
;;
log)
tail -f jackrabbit/log/jackrabbit.log
;;
stop)
stop_jackrabbit >/dev/null
;;
restart)
stop_jackrabbit >/dev/null
start_jackrabbit
;;
start)
start_jackrabbit
;;
status)
status_jackrabbit
;;
*)
echo "Unknown action: $action"
usage
exit 1
esac