source: nutchez-0.1/bin/nutch @ 95

Last change on this file since 95 was 75, checked in by waue, 15 years ago

promote

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