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 | |
---|
106 | CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar |
---|
107 | |
---|
108 | # so that filenames w/ spaces are handled correctly in loops below |
---|
109 | IFS= |
---|
110 | |
---|
111 | # for developers, add plugins, job & test code to CLASSPATH |
---|
112 | if [ -d "$NUTCH_HOME/build/plugins" ]; then |
---|
113 | CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build |
---|
114 | fi |
---|
115 | if [ -d "$NUTCH_HOME/build/test/classes" ]; then |
---|
116 | CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/test/classes |
---|
117 | fi |
---|
118 | |
---|
119 | if [ $IS_CORE == 0 ] |
---|
120 | then |
---|
121 | for f in $NUTCH_HOME/build/nutch-*.job; do |
---|
122 | CLASSPATH=${CLASSPATH}:$f; |
---|
123 | done |
---|
124 | |
---|
125 | # for releases, add Nutch job to CLASSPATH |
---|
126 | for f in $NUTCH_HOME/nutch-*.job; do |
---|
127 | CLASSPATH=${CLASSPATH}:$f; |
---|
128 | done |
---|
129 | else |
---|
130 | CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/classes |
---|
131 | fi |
---|
132 | |
---|
133 | # add plugins to classpath |
---|
134 | if [ -d "$NUTCH_HOME/plugins" ]; then |
---|
135 | CLASSPATH=${NUTCH_HOME}:${CLASSPATH} |
---|
136 | fi |
---|
137 | |
---|
138 | # add libs to CLASSPATH |
---|
139 | for f in $NUTCH_HOME/lib/*.jar; do |
---|
140 | CLASSPATH=${CLASSPATH}:$f; |
---|
141 | done |
---|
142 | |
---|
143 | for f in $NUTCH_HOME/lib/jetty-ext/*.jar; do |
---|
144 | CLASSPATH=${CLASSPATH}:$f; |
---|
145 | done |
---|
146 | |
---|
147 | # cygwin path translation |
---|
148 | if $cygwin; then |
---|
149 | CLASSPATH=`cygpath -p -w "$CLASSPATH"` |
---|
150 | fi |
---|
151 | |
---|
152 | # setup 'java.library.path' for native-hadoop code if necessary |
---|
153 | JAVA_LIBRARY_PATH='' |
---|
154 | if [ -d "${NUTCH_HOME}/build/native" -o -d "${NUTCH_HOME}/lib/native" ]; then |
---|
155 | JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} org.apache.hadoop.util.PlatformName | sed -e 's/ /_/g'` |
---|
156 | |
---|
157 | if [ -d "$NUTCH_HOME/build/native" ]; then |
---|
158 | JAVA_LIBRARY_PATH=${HADOOP_HOME}/build/native/${JAVA_PLATFORM}/lib |
---|
159 | fi |
---|
160 | |
---|
161 | if [ -d "${NUTCH_HOME}/lib/native" ]; then |
---|
162 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
---|
163 | JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${NUTCH_HOME}/lib/native/${JAVA_PLATFORM} |
---|
164 | else |
---|
165 | JAVA_LIBRARY_PATH=${NUTCH_HOME}/lib/native/${JAVA_PLATFORM} |
---|
166 | fi |
---|
167 | fi |
---|
168 | fi |
---|
169 | |
---|
170 | if [ $cygwin = true -a "X${JAVA_LIBRARY_PATH}" != "X" ]; then |
---|
171 | JAVA_LIBRARY_PATH=`cygpath -p -w "$JAVA_LIBRARY_PATH"` |
---|
172 | fi |
---|
173 | |
---|
174 | # restore ordinary behaviour |
---|
175 | unset IFS |
---|
176 | |
---|
177 | # default log directory & file |
---|
178 | if [ "$NUTCH_LOG_DIR" = "" ]; then |
---|
179 | NUTCH_LOG_DIR="$NUTCH_HOME/logs" |
---|
180 | fi |
---|
181 | if [ "$NUTCH_LOGFILE" = "" ]; then |
---|
182 | NUTCH_LOGFILE='hadoop.log' |
---|
183 | fi |
---|
184 | |
---|
185 | #Fix log path under cygwin |
---|
186 | if $cygwin; then |
---|
187 | NUTCH_LOG_DIR=`cygpath -p -w "$NUTCH_LOG_DIR"` |
---|
188 | fi |
---|
189 | |
---|
190 | NUTCH_OPTS="$NUTCH_OPTS -Dhadoop.log.dir=$NUTCH_LOG_DIR" |
---|
191 | NUTCH_OPTS="$NUTCH_OPTS -Dhadoop.log.file=$NUTCH_LOGFILE" |
---|
192 | |
---|
193 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
---|
194 | NUTCH_OPTS="$NUTCH_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" |
---|
195 | fi |
---|
196 | |
---|
197 | # figure out which class to run |
---|
198 | if [ "$COMMAND" = "crawl" ] ; then |
---|
199 | CLASS=org.apache.nutch.crawl.Crawl |
---|
200 | elif [ "$COMMAND" = "inject" ] ; then |
---|
201 | CLASS=org.apache.nutch.crawl.Injector |
---|
202 | elif [ "$COMMAND" = "generate" ] ; then |
---|
203 | CLASS=org.apache.nutch.crawl.Generator |
---|
204 | elif [ "$COMMAND" = "freegen" ] ; then |
---|
205 | CLASS=org.apache.nutch.tools.FreeGenerator |
---|
206 | elif [ "$COMMAND" = "fetch" ] ; then |
---|
207 | CLASS=org.apache.nutch.fetcher.Fetcher |
---|
208 | elif [ "$COMMAND" = "fetch2" ] ; then |
---|
209 | CLASS=org.apache.nutch.fetcher.Fetcher2 |
---|
210 | elif [ "$COMMAND" = "parse" ] ; then |
---|
211 | CLASS=org.apache.nutch.parse.ParseSegment |
---|
212 | elif [ "$COMMAND" = "readdb" ] ; then |
---|
213 | CLASS=org.apache.nutch.crawl.CrawlDbReader |
---|
214 | elif [ "$COMMAND" = "convdb" ] ; then |
---|
215 | CLASS=org.apache.nutch.tools.compat.CrawlDbConverter |
---|
216 | elif [ "$COMMAND" = "mergedb" ] ; then |
---|
217 | CLASS=org.apache.nutch.crawl.CrawlDbMerger |
---|
218 | elif [ "$COMMAND" = "readlinkdb" ] ; then |
---|
219 | CLASS=org.apache.nutch.crawl.LinkDbReader |
---|
220 | elif [ "$COMMAND" = "readseg" ] ; then |
---|
221 | CLASS=org.apache.nutch.segment.SegmentReader |
---|
222 | elif [ "$COMMAND" = "segread" ] ; then |
---|
223 | echo "[DEPRECATED] Command 'segread' is deprecated, use 'readseg' instead." |
---|
224 | CLASS=org.apache.nutch.segment.SegmentReader |
---|
225 | elif [ "$COMMAND" = "mergesegs" ] ; then |
---|
226 | CLASS=org.apache.nutch.segment.SegmentMerger |
---|
227 | elif [ "$COMMAND" = "updatedb" ] ; then |
---|
228 | CLASS=org.apache.nutch.crawl.CrawlDb |
---|
229 | elif [ "$COMMAND" = "invertlinks" ] ; then |
---|
230 | CLASS=org.apache.nutch.crawl.LinkDb |
---|
231 | elif [ "$COMMAND" = "mergelinkdb" ] ; then |
---|
232 | CLASS=org.apache.nutch.crawl.LinkDbMerger |
---|
233 | elif [ "$COMMAND" = "index" ] ; then |
---|
234 | CLASS=org.apache.nutch.indexer.Indexer |
---|
235 | elif [ "$COMMAND" = "solrindex" ] ; then |
---|
236 | CLASS=org.apache.nutch.indexer.solr.SolrIndexer |
---|
237 | elif [ "$COMMAND" = "dedup" ] ; then |
---|
238 | CLASS=org.apache.nutch.indexer.DeleteDuplicates |
---|
239 | elif [ "$COMMAND" = "solrdedup" ] ; then |
---|
240 | CLASS=org.apache.nutch.indexer.solr.SolrDeleteDuplicates |
---|
241 | elif [ "$COMMAND" = "merge" ] ; then |
---|
242 | CLASS=org.apache.nutch.indexer.IndexMerger |
---|
243 | elif [ "$COMMAND" = "plugin" ] ; then |
---|
244 | CLASS=org.apache.nutch.plugin.PluginRepository |
---|
245 | elif [ "$COMMAND" = "server" ] ; then |
---|
246 | CLASS='org.apache.nutch.searcher.DistributedSearch$Server' |
---|
247 | else |
---|
248 | CLASS=$COMMAND |
---|
249 | fi |
---|
250 | |
---|
251 | # run it |
---|
252 | exec "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@" |
---|
253 | |
---|