安裝Hudson
- 到http://tomcat.apache.org下載tomcat 6.x版,例如apache-tomcat-6.0.24.zip
- 將apache-tomcat-6.0.24.zip解壓縮到$$your_profile$$/Library, $$your_profile$$為你在Mac OS X中的使用者家目錄, 例如/Users/admin
- 執行 chmod a+x $$your_profile$$/Library/apache-tomcat-6.0.24/bin/*.sh
-
設定管理者的帳號與密碼:
編輯 $$your_profile$$/Library/apache-tomcat-6.0.24/conf/tomcat-users.xml , 加入
< role rolename ="manager" />
< user username ="tomcat" password ="xxxx" roles ="manager" />
設定好後執行$your_profile$$/Library/apache-tomcat-6.0.24/bin/startup.sh , 再使用browser連到http://localhost:8080, 如果可以看到以下畫面, Tomcat Server的安裝算是初步完成
使用Launchd來啟動Tomcat Server
設定Launchd主要讓Mac OS X server啟動時, 也順便啟動Tomcat Server, Launchd有點類似Windows的NT Service
1.到$$your_profile$$/Library/apache-tomcat-6.0.24/bin/目錄下新增一個檔案 launchd_wrapper.sh, 內容如下
1 # !/bin/bash
2
3 function shutdown ()
4
5 {
6
7 date
8
9 echo " Shutting down Tomcat "
10
11 $CATALINA_HOME / bin / catalina . sh stop
12
13 }
14
15 date
16
17 echo " Starting Tomcat Server "
18
19 export CATALINA_PID =/ tmp / $$
20
21 # Uncomment to increase Tomcat's maximum heap allocation
22
23 # export JAVA_OPTS=-Xmx512M $JAVA_OPTS
24
25 export JAVA_OPTS = " -Xms256m -Xmx512m -XX:MaxPermSize=256m "
26
27 export CATALINA_OPTS = " -DHUDSON_HOME=/Users/admin/hudson "
28
29 . $CATALINA_HOME / bin / catalina . sh start
30
31 # Allow any signal which would kill a process to stop Tomcat
32
33 trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
請注意, /Users/admin, 請改成你的$$your_profile$$位置, launchd_wrapper.sh要使用chmod a+x launchd_wrapper.sh使其具有執行權限
2. 加入tomcat for Launchd屬性檔案, 到/Library/LaunchDaemons這個目錄底下使用 sudo touch tomcat.plist 新增tomcat.plist, 這個指令會要求輸入管理者密碼
3. 使用sudo vi tomcat.plist , 編輯tomcat.plist, 檔案內容如下, 要注意的是/Users/admin為筆者的安裝目錄, 請改成你的$$your_profile$$目錄
<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
< plist version ="1.0" >
< dict >
< key > Disabled </ key >
< false />
< key > EnvironmentVariables </ key >
< dict >
< key > CATALINA_HOME </ key >
< string > /Users/admin/Library/apache-tomcat-6.0.24 </ string >
< key > JAVA_HOME </ key >
< string > /Library/Java/Home </ string >
</ dict >
< key > Label </ key >
< string > com.apache.tomcat </ string >
< key > OnDemand </ key >
< false />
< key > ProgramArguments </ key >
< array >
< string > /Users/admin/Library/apache-tomcat-6.0.24/bin/launchd_wrapper.sh </ string >
</ array >
< key > RunAtLoad </ key >
< true />
< key > ServiceDescription </ key >
< string > Tomcat </ string >
< key > StandardErrorPath </ key >
< string > /Users/admin/apache-tomcat-6.0.24/logs/launchd.stderr </ string >
< key > StandardOutPath </ key >
< string > /Users/admin/apache-tomcat-6.0.24/logs/launchd.stdout </ string >
< key > UserName </ key >
< string > root </ string >
</ dict >
</ plist >
4.手動測試Launchd , 啟動指令為
sudo launchctl load - w / Library / LauhchDaemons / tomcat . plist
停止指令為
sudo launchctl unload - w / Library / LaunchDaemons / tomcat . plist
測試OK後, 下次重新開機Tomcat Server就會自己執行了.