wiki:waue/2011/0830

Version 1 (modified by waue, 13 years ago) (diff)

--

將 tomcat port 開在 80

以 crawlzilla 為例

  • 先安裝 jsvc
sudo apt-get install jsvc
  • 修改 server.xml 讓 tomcat 運行於 80 port

vim /opt/crawlzilla/tomcat/conf/server.xml

   <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"
               useBodyEncodingForURI="true" />
  • 修改 sudoers 讓 crawler 可以執行 jsvc

sudo vim /etc/sudoers

crawler  ALL=NOPASSWD: /opt/crawlzilla/tomcat/bin/startup.sh /opt/crawlzilla/tomcat/bin/shutdown.sh
  • 註解掉原本的呼叫方式(最後一行),並再最後面加入兩行用jsvc 驅動的方式

sudo vim /opt/crawlzilla/tomcat/bin/startup.sh

#exec "$PRGDIR"/"$EXECUTABLE" start "$@"

cd /opt/crawlzilla/tomcat

sudo /usr/bin/jsvc -home /usr/lib/jvm/java-6-sun -user crawler -pidfile /var/log/crawlzilla/jsvc.pid -cp /opt/crawlzilla/tomcat/bin/bootstrap.jar -outfile /var/log/crawlzilla/jsvc.tomcat.out -errfile /var/log/crawlzilla/jsvc.tomcat.err org.apache.catalina.startup.Bootstrap

因此,之後呼叫 /opt/crawlzilla/tomcat/bin/startup.sh 前面都要加 sudo

  • 關閉 tomcat

sudo vim /opt/crawlzilla/tomcat/bin/shutdown.sh

if [ -e /var/log/crawlzilla/jsvc.pid ];then
    PID=$(cat /var/log/crawlzilla/jsvc.pid)
    kill $PID
fi
  • vim /opt/crawlzilla/main/tomcat_restart.sh
if [ $command == "start" ];then
        sudo /opt/crawlzilla/tomcat/bin/startup.sh
        debug_info "/opt/crawlzilla/tomcat/bin/startup.sh"
elif [ $command == "stop" ];then
        sudo /opt/crawlzilla/tomcat/bin/shutdown.sh
        debug_info "/opt/crawlzilla/tomcat/bin/shutdown.sh"
        kill $tom_pids
        debug_info "kill $tom_pids"
else
        sudo /opt/crawlzilla/tomcat/bin/shutdown.sh
        debug_info "/opt/crawlzilla/tomcat/bin/shutdown.sh"
        kill $tom_pids
        debug_info "kill $tom_pids"
        sudo /opt/crawlzilla/tomcat/bin/startup.sh
        debug_info "/opt/crawlzilla/tomcat/bin/startup.sh"
fi