source: nutchez-0.1/bin/nutch @ 66

Last change on this file since 66 was 66, checked in by waue, 16 years ago

NutchEz - an easy way to nutch

  • Property svn:executable set to *
File size: 7.8 KB
Line 
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#
14cygwin=false
15case "`uname`" in
16CYGWIN*) cygwin=true;;
17esac
18
19# resolve links - $0 may be a softlink
20THIS="$0"
21while [ -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
29done
30
31# if no args specified, show usage
32if [ $# = 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
65fi
66
67IS_CORE=0
68#check for -core option
69if [ "$1" == "-core" ] ; then
70  IS_CORE=1
71  shift
72fi
73
74# get arguments
75COMMAND=$1
76shift
77
78# some directories
79THIS_DIR=`dirname "$THIS"`
80NUTCH_HOME=`cd "$THIS_DIR/.." ; pwd`
81
82# some Java parameters
83if [ "$NUTCH_JAVA_HOME" != "" ]; then
84  #echo "run java in $NUTCH_JAVA_HOME"
85  JAVA_HOME=$NUTCH_JAVA_HOME
86fi
87 
88if [ "$JAVA_HOME" = "" ]; then
89  echo "Error: JAVA_HOME is not set."
90  exit 1
91fi
92
93JAVA=$JAVA_HOME/bin/java
94JAVA_HEAP_MAX=-Xmx1000m
95
96# check envvars which might override default args
97if [ "$NUTCH_HEAPSIZE" != "" ]; then
98  #echo "run with heapsize $NUTCH_HEAPSIZE"
99  JAVA_HEAP_MAX="-Xmx""$NUTCH_HEAPSIZE""m"
100  #echo $JAVA_HEAP_MAX
101fi
102
103# CLASSPATH initially contains $NUTCH_CONF_DIR, or defaults to $NUTCH_HOME/conf
104CLASSPATH=${NUTCH_CONF_DIR:=$NUTCH_HOME/conf}
105CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
106
107# so that filenames w/ spaces are handled correctly in loops below
108IFS=
109
110# for developers, add plugins, job & test code to CLASSPATH
111if [ -d "$NUTCH_HOME/build/plugins" ]; then
112  CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build
113fi
114if [ -d "$NUTCH_HOME/build/test/classes" ]; then
115  CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/test/classes
116fi
117
118if [ $IS_CORE == 0 ] 
119then
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
128else
129  CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/classes
130fi
131
132# add plugins to classpath
133if [ -d "$NUTCH_HOME/plugins" ]; then
134  CLASSPATH=${NUTCH_HOME}:${CLASSPATH}
135fi
136
137# add libs to CLASSPATH
138for f in $NUTCH_HOME/lib/*.jar; do
139  CLASSPATH=${CLASSPATH}:$f;
140done
141
142for f in $NUTCH_HOME/lib/jetty-ext/*.jar; do
143  CLASSPATH=${CLASSPATH}:$f;
144done
145
146# cygwin path translation
147if $cygwin; then
148  CLASSPATH=`cygpath -p -w "$CLASSPATH"`
149fi
150
151# setup 'java.library.path' for native-hadoop code if necessary
152JAVA_LIBRARY_PATH=''
153if [ -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
167fi
168
169if [ $cygwin = true -a "X${JAVA_LIBRARY_PATH}" != "X" ]; then
170  JAVA_LIBRARY_PATH=`cygpath -p -w "$JAVA_LIBRARY_PATH"`
171fi
172
173# restore ordinary behaviour
174unset IFS
175
176# default log directory & file
177if [ "$NUTCH_LOG_DIR" = "" ]; then
178  NUTCH_LOG_DIR="$NUTCH_HOME/logs"
179fi
180if [ "$NUTCH_LOGFILE" = "" ]; then
181  NUTCH_LOGFILE='hadoop.log'
182fi
183
184#Fix log path under cygwin
185if $cygwin; then
186  NUTCH_LOG_DIR=`cygpath -p -w "$NUTCH_LOG_DIR"`
187fi
188
189NUTCH_OPTS="$NUTCH_OPTS -Dhadoop.log.dir=$NUTCH_LOG_DIR"
190NUTCH_OPTS="$NUTCH_OPTS -Dhadoop.log.file=$NUTCH_LOGFILE"
191
192if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
193  NUTCH_OPTS="$NUTCH_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
194fi
195
196# figure out which class to run
197if [ "$COMMAND" = "crawl" ] ; then
198  CLASS=org.apache.nutch.crawl.Crawl
199elif [ "$COMMAND" = "inject" ] ; then
200  CLASS=org.apache.nutch.crawl.Injector
201elif [ "$COMMAND" = "generate" ] ; then
202  CLASS=org.apache.nutch.crawl.Generator
203elif [ "$COMMAND" = "freegen" ] ; then
204  CLASS=org.apache.nutch.tools.FreeGenerator
205elif [ "$COMMAND" = "fetch" ] ; then
206  CLASS=org.apache.nutch.fetcher.Fetcher
207elif [ "$COMMAND" = "fetch2" ] ; then
208  CLASS=org.apache.nutch.fetcher.Fetcher2
209elif [ "$COMMAND" = "parse" ] ; then
210  CLASS=org.apache.nutch.parse.ParseSegment
211elif [ "$COMMAND" = "readdb" ] ; then
212  CLASS=org.apache.nutch.crawl.CrawlDbReader
213elif [ "$COMMAND" = "convdb" ] ; then
214  CLASS=org.apache.nutch.tools.compat.CrawlDbConverter
215elif [ "$COMMAND" = "mergedb" ] ; then
216  CLASS=org.apache.nutch.crawl.CrawlDbMerger
217elif [ "$COMMAND" = "readlinkdb" ] ; then
218  CLASS=org.apache.nutch.crawl.LinkDbReader
219elif [ "$COMMAND" = "readseg" ] ; then
220  CLASS=org.apache.nutch.segment.SegmentReader
221elif [ "$COMMAND" = "segread" ] ; then
222  echo "[DEPRECATED] Command 'segread' is deprecated, use 'readseg' instead."
223  CLASS=org.apache.nutch.segment.SegmentReader
224elif [ "$COMMAND" = "mergesegs" ] ; then
225  CLASS=org.apache.nutch.segment.SegmentMerger
226elif [ "$COMMAND" = "updatedb" ] ; then
227  CLASS=org.apache.nutch.crawl.CrawlDb
228elif [ "$COMMAND" = "invertlinks" ] ; then
229  CLASS=org.apache.nutch.crawl.LinkDb
230elif [ "$COMMAND" = "mergelinkdb" ] ; then
231  CLASS=org.apache.nutch.crawl.LinkDbMerger
232elif [ "$COMMAND" = "index" ] ; then
233  CLASS=org.apache.nutch.indexer.Indexer
234elif [ "$COMMAND" = "solrindex" ] ; then
235  CLASS=org.apache.nutch.indexer.solr.SolrIndexer
236elif [ "$COMMAND" = "dedup" ] ; then
237  CLASS=org.apache.nutch.indexer.DeleteDuplicates
238elif [ "$COMMAND" = "solrdedup" ] ; then
239  CLASS=org.apache.nutch.indexer.solr.SolrDeleteDuplicates
240elif [ "$COMMAND" = "merge" ] ; then
241  CLASS=org.apache.nutch.indexer.IndexMerger
242elif [ "$COMMAND" = "plugin" ] ; then
243  CLASS=org.apache.nutch.plugin.PluginRepository
244elif [ "$COMMAND" = "server" ] ; then
245  CLASS='org.apache.nutch.searcher.DistributedSearch$Server'
246else
247  CLASS=$COMMAND
248fi
249
250# run it
251exec "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@"
252
Note: See TracBrowser for help on using the repository browser.