1 | #!/bin/bash |
---|
2 | # |
---|
3 | # The Nutch command script |
---|
4 | # |
---|
5 | # Environment Variables |
---|
6 | # |
---|
7 | # NUTCH_JAVA_HOME The java implementation to use. Overrides JAVA_HOME. |
---|
8 | # |
---|
9 | # NUTCH_HEAPSIZE The maximum amount of heap to use, in MB. |
---|
10 | # Default is 1000. |
---|
11 | # |
---|
12 | # NUTCH_OPTS Extra Java runtime options. |
---|
13 | # |
---|
14 | cygwin=false |
---|
15 | case "`uname`" in |
---|
16 | CYGWIN*) cygwin=true;; |
---|
17 | esac |
---|
18 | |
---|
19 | # resolve links - $0 may be a softlink |
---|
20 | THIS="$0" |
---|
21 | while [ -h "$THIS" ]; do |
---|
22 | ls=`ls -ld "$THIS"` |
---|
23 | link=`expr "$ls" : '.*-> \(.*\)$'` |
---|
24 | if expr "$link" : '.*/.*' > /dev/null; then |
---|
25 | THIS="$link" |
---|
26 | else |
---|
27 | THIS=`dirname "$THIS"`/"$link" |
---|
28 | fi |
---|
29 | done |
---|
30 | |
---|
31 | # if no args specified, show usage |
---|
32 | if [ $# = 0 ]; then |
---|
33 | echo "Usage: nutch [-core] COMMAND" |
---|
34 | echo "where COMMAND is one of:" |
---|
35 | echo " crawl one-step crawler for intranets" |
---|
36 | echo " readdb read / dump crawl db" |
---|
37 | echo " convdb convert crawl db from pre-0.9 format" |
---|
38 | echo " mergedb merge crawldb-s, with optional filtering" |
---|
39 | echo " readlinkdb read / dump link db" |
---|
40 | echo " inject inject new urls into the database" |
---|
41 | echo " generate generate new segments to fetch from crawl db" |
---|
42 | echo " freegen generate new segments to fetch from text files" |
---|
43 | echo " fetch fetch a segment's pages" |
---|
44 | echo " parse parse a segment's pages" |
---|
45 | echo " readseg read / dump segment data" |
---|
46 | echo " mergesegs merge several segments, with optional filtering and slicing" |
---|
47 | echo " updatedb update crawl db from segments after fetching" |
---|
48 | echo " invertlinks create a linkdb from parsed segments" |
---|
49 | echo " mergelinkdb merge linkdb-s, with optional filtering" |
---|
50 | echo " index run the indexer on parsed segments and linkdb" |
---|
51 | echo " solrindex run the solr indexer on parsed segments and linkdb" |
---|
52 | echo " merge merge several segment indexes" |
---|
53 | echo " dedup remove duplicates from a set of segment indexes" |
---|
54 | echo " solrdedup remove duplicates from solr" |
---|
55 | echo " plugin load a plugin and run one of its classes main()" |
---|
56 | echo " server run a search server" |
---|
57 | echo " or" |
---|
58 | echo " CLASSNAME run the class named CLASSNAME" |
---|
59 | echo "Most commands print help when invoked w/o parameters." |
---|
60 | echo "" |
---|
61 | echo "Expert: -core option is for developers only. It avoids building the job jar, " |
---|
62 | echo " instead it simply includes classes compiled with ant compile-core. " |
---|
63 | echo " NOTE: this works only for jobs executed in 'local' mode" |
---|
64 | exit 1 |
---|
65 | fi |
---|
66 | |
---|
67 | IS_CORE=0 |
---|
68 | #check for -core option |
---|
69 | if [ "$1" == "-core" ] ; then |
---|
70 | IS_CORE=1 |
---|
71 | shift |
---|
72 | fi |
---|
73 | |
---|
74 | # get arguments |
---|
75 | COMMAND=$1 |
---|
76 | shift |
---|
77 | |
---|
78 | # some directories |
---|
79 | THIS_DIR=`dirname "$THIS"` |
---|
80 | NUTCH_HOME=`cd "$THIS_DIR/.." ; pwd` |
---|
81 | |
---|
82 | # some Java parameters |
---|
83 | if [ "$NUTCH_JAVA_HOME" != "" ]; then |
---|
84 | #echo "run java in $NUTCH_JAVA_HOME" |
---|
85 | JAVA_HOME=$NUTCH_JAVA_HOME |
---|
86 | fi |
---|
87 | |
---|
88 | if [ "$JAVA_HOME" = "" ]; then |
---|
89 | echo "Error: JAVA_HOME is not set." |
---|
90 | exit 1 |
---|
91 | fi |
---|
92 | |
---|
93 | JAVA=$JAVA_HOME/bin/java |
---|
94 | JAVA_HEAP_MAX=-Xmx1000m |
---|
95 | |
---|
96 | # check envvars which might override default args |
---|
97 | if [ "$NUTCH_HEAPSIZE" != "" ]; then |
---|
98 | #echo "run with heapsize $NUTCH_HEAPSIZE" |
---|
99 | JAVA_HEAP_MAX="-Xmx""$NUTCH_HEAPSIZE""m" |
---|
100 | #echo $JAVA_HEAP_MAX |
---|
101 | fi |
---|
102 | |
---|
103 | # CLASSPATH initially contains $NUTCH_CONF_DIR, or defaults to $NUTCH_HOME/conf |
---|
104 | CLASSPATH=${NUTCH_CONF_DIR:=$NUTCH_HOME/conf} |
---|
105 | CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar |
---|
106 | |
---|
107 | # so that filenames w/ spaces are handled correctly in loops below |
---|
108 | IFS= |
---|
109 | |
---|
110 | # for developers, add plugins, job & test code to CLASSPATH |
---|
111 | if [ -d "$NUTCH_HOME/build/plugins" ]; then |
---|
112 | CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build |
---|
113 | fi |
---|
114 | if [ -d "$NUTCH_HOME/build/test/classes" ]; then |
---|
115 | CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/test/classes |
---|
116 | fi |
---|
117 | |
---|
118 | if [ $IS_CORE == 0 ] |
---|
119 | then |
---|
120 | for f in $NUTCH_HOME/build/nutch-*.job; do |
---|
121 | CLASSPATH=${CLASSPATH}:$f; |
---|
122 | done |
---|
123 | |
---|
124 | # for releases, add Nutch job to CLASSPATH |
---|
125 | for f in $NUTCH_HOME/nutch-*.job; do |
---|
126 | CLASSPATH=${CLASSPATH}:$f; |
---|
127 | done |
---|
128 | else |
---|
129 | CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/classes |
---|
130 | fi |
---|
131 | |
---|
132 | # add plugins to classpath |
---|
133 | if [ -d "$NUTCH_HOME/plugins" ]; then |
---|
134 | CLASSPATH=${NUTCH_HOME}:${CLASSPATH} |
---|
135 | fi |
---|
136 | |
---|
137 | # add libs to CLASSPATH |
---|
138 | for f in $NUTCH_HOME/lib/*.jar; do |
---|
139 | CLASSPATH=${CLASSPATH}:$f; |
---|
140 | done |
---|
141 | |
---|
142 | for f in $NUTCH_HOME/lib/jetty-ext/*.jar; do |
---|
143 | CLASSPATH=${CLASSPATH}:$f; |
---|
144 | done |
---|
145 | |
---|
146 | # cygwin path translation |
---|
147 | if $cygwin; then |
---|
148 | CLASSPATH=`cygpath -p -w "$CLASSPATH"` |
---|
149 | fi |
---|
150 | |
---|
151 | # setup 'java.library.path' for native-hadoop code if necessary |
---|
152 | JAVA_LIBRARY_PATH='' |
---|
153 | if [ -d "${NUTCH_HOME}/build/native" -o -d "${NUTCH_HOME}/lib/native" ]; then |
---|
154 | JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} org.apache.hadoop.util.PlatformName | sed -e 's/ /_/g'` |
---|
155 | |
---|
156 | if [ -d "$NUTCH_HOME/build/native" ]; then |
---|
157 | JAVA_LIBRARY_PATH=${HADOOP_HOME}/build/native/${JAVA_PLATFORM}/lib |
---|
158 | fi |
---|
159 | |
---|
160 | if [ -d "${NUTCH_HOME}/lib/native" ]; then |
---|
161 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
---|
162 | JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${NUTCH_HOME}/lib/native/${JAVA_PLATFORM} |
---|
163 | else |
---|
164 | JAVA_LIBRARY_PATH=${NUTCH_HOME}/lib/native/${JAVA_PLATFORM} |
---|
165 | fi |
---|
166 | fi |
---|
167 | fi |
---|
168 | |
---|
169 | if [ $cygwin = true -a "X${JAVA_LIBRARY_PATH}" != "X" ]; then |
---|
170 | JAVA_LIBRARY_PATH=`cygpath -p -w "$JAVA_LIBRARY_PATH"` |
---|
171 | fi |
---|
172 | |
---|
173 | # restore ordinary behaviour |
---|
174 | unset IFS |
---|
175 | |
---|
176 | # default log directory & file |
---|
177 | if [ "$NUTCH_LOG_DIR" = "" ]; then |
---|
178 | NUTCH_LOG_DIR="$NUTCH_HOME/logs" |
---|
179 | fi |
---|
180 | if [ "$NUTCH_LOGFILE" = "" ]; then |
---|
181 | NUTCH_LOGFILE='hadoop.log' |
---|
182 | fi |
---|
183 | |
---|
184 | #Fix log path under cygwin |
---|
185 | if $cygwin; then |
---|
186 | NUTCH_LOG_DIR=`cygpath -p -w "$NUTCH_LOG_DIR"` |
---|
187 | fi |
---|
188 | |
---|
189 | NUTCH_OPTS="$NUTCH_OPTS -Dhadoop.log.dir=$NUTCH_LOG_DIR" |
---|
190 | NUTCH_OPTS="$NUTCH_OPTS -Dhadoop.log.file=$NUTCH_LOGFILE" |
---|
191 | |
---|
192 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
---|
193 | NUTCH_OPTS="$NUTCH_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" |
---|
194 | fi |
---|
195 | |
---|
196 | # figure out which class to run |
---|
197 | if [ "$COMMAND" = "crawl" ] ; then |
---|
198 | CLASS=org.apache.nutch.crawl.Crawl |
---|
199 | elif [ "$COMMAND" = "inject" ] ; then |
---|
200 | CLASS=org.apache.nutch.crawl.Injector |
---|
201 | elif [ "$COMMAND" = "generate" ] ; then |
---|
202 | CLASS=org.apache.nutch.crawl.Generator |
---|
203 | elif [ "$COMMAND" = "freegen" ] ; then |
---|
204 | CLASS=org.apache.nutch.tools.FreeGenerator |
---|
205 | elif [ "$COMMAND" = "fetch" ] ; then |
---|
206 | CLASS=org.apache.nutch.fetcher.Fetcher |
---|
207 | elif [ "$COMMAND" = "fetch2" ] ; then |
---|
208 | CLASS=org.apache.nutch.fetcher.Fetcher2 |
---|
209 | elif [ "$COMMAND" = "parse" ] ; then |
---|
210 | CLASS=org.apache.nutch.parse.ParseSegment |
---|
211 | elif [ "$COMMAND" = "readdb" ] ; then |
---|
212 | CLASS=org.apache.nutch.crawl.CrawlDbReader |
---|
213 | elif [ "$COMMAND" = "convdb" ] ; then |
---|
214 | CLASS=org.apache.nutch.tools.compat.CrawlDbConverter |
---|
215 | elif [ "$COMMAND" = "mergedb" ] ; then |
---|
216 | CLASS=org.apache.nutch.crawl.CrawlDbMerger |
---|
217 | elif [ "$COMMAND" = "readlinkdb" ] ; then |
---|
218 | CLASS=org.apache.nutch.crawl.LinkDbReader |
---|
219 | elif [ "$COMMAND" = "readseg" ] ; then |
---|
220 | CLASS=org.apache.nutch.segment.SegmentReader |
---|
221 | elif [ "$COMMAND" = "segread" ] ; then |
---|
222 | echo "[DEPRECATED] Command 'segread' is deprecated, use 'readseg' instead." |
---|
223 | CLASS=org.apache.nutch.segment.SegmentReader |
---|
224 | elif [ "$COMMAND" = "mergesegs" ] ; then |
---|
225 | CLASS=org.apache.nutch.segment.SegmentMerger |
---|
226 | elif [ "$COMMAND" = "updatedb" ] ; then |
---|
227 | CLASS=org.apache.nutch.crawl.CrawlDb |
---|
228 | elif [ "$COMMAND" = "invertlinks" ] ; then |
---|
229 | CLASS=org.apache.nutch.crawl.LinkDb |
---|
230 | elif [ "$COMMAND" = "mergelinkdb" ] ; then |
---|
231 | CLASS=org.apache.nutch.crawl.LinkDbMerger |
---|
232 | elif [ "$COMMAND" = "index" ] ; then |
---|
233 | CLASS=org.apache.nutch.indexer.Indexer |
---|
234 | elif [ "$COMMAND" = "solrindex" ] ; then |
---|
235 | CLASS=org.apache.nutch.indexer.solr.SolrIndexer |
---|
236 | elif [ "$COMMAND" = "dedup" ] ; then |
---|
237 | CLASS=org.apache.nutch.indexer.DeleteDuplicates |
---|
238 | elif [ "$COMMAND" = "solrdedup" ] ; then |
---|
239 | CLASS=org.apache.nutch.indexer.solr.SolrDeleteDuplicates |
---|
240 | elif [ "$COMMAND" = "merge" ] ; then |
---|
241 | CLASS=org.apache.nutch.indexer.IndexMerger |
---|
242 | elif [ "$COMMAND" = "plugin" ] ; then |
---|
243 | CLASS=org.apache.nutch.plugin.PluginRepository |
---|
244 | elif [ "$COMMAND" = "server" ] ; then |
---|
245 | CLASS='org.apache.nutch.searcher.DistributedSearch$Server' |
---|
246 | else |
---|
247 | CLASS=$COMMAND |
---|
248 | fi |
---|
249 | |
---|
250 | # run it |
---|
251 | exec "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@" |
---|
252 | |
---|