1. 首先在 建立檔案/etc/init.d/glassfish3, 檔案內容如下. 注意修改下列內容的紅色部分(不好意思,全部用英文寫的)
Sh代碼
#! /bin/sh
# This shell script takes care of starting and stopping
# the glassfish DAS and glassfish instance.
#
# chkconfig: - 64 36
# description: glassfish management
# processname: glassfish
#if you face any problems add the path to your Java
#this way (see Jeffrey's comments below)
export AS_JAVA=<span style="color: #ff0000;">/usr/java/jdk1.6.0_17</span>
#export CLASSPATH=.;$AS_JAVA/lib/dt.jar;$AS_JAVA/lib/tools.jar
GLASSFISHPATH=<span style="color: #ff0000;">/opt/glassfish3/bin</span>
export PASSWD=<span style="color: #ff0000;">/opt/glassfish3/bin/.passwd</span>
case "$1" in
start)
echo "starting glassfish from $GLASSFISHPATH"
su - root $GLASSFISHPATH/asadmin start-domain
#start your instance at start time, if you do not have instance, comment these two lines
<span style="color: #ff0000;">echo "starting instance st_server"
$GLASSFISHPATH/asadmin --user admin --passwordfile $PASSWD start-instance st_server
</span>
#we need to use this later when we enable https
#sudo -u glassfish $GLASSFISHPATH/asadmin --secure start-domain domain1
;;
status)
$0 start
;;
restart)
$0 stop
$0 start
;;
stop)
<span style="color: #ff0000;">echo "stopping instance st_server"
$GLASSFISHPATH/asadmin --user admin --passwordfile $PASSWD stop-instance st_server
</span>
echo "stopping glassfish from $GLASSFISHPATH"
su - root $GLASSFISHPATH/asadmin stop-domain
#we need to use this later when we enable https
#sudo -u root $GLASSFISHPATH/asadmin --secure stop-domain domain1
;;
*)
echo $"usage: $0 {start|stop|restart|status}"
exit 3
;;
esac
設定成可執行檔,
Java代碼
$ sudo chmod +x /etc/init.d/glassfish3
其中的password檔案如下
.passwd代碼
AS_ADMIN_PASSWORD=administration-password
請將 administration-password修改成你自己的密碼
2. 查看剛剛添加的服務
Java代碼
chkconfig --list glassfish3
你應該看到
Java代碼
glassfish3 0:off 1:off 2:off 3:off 4:off 5:off 6:off
所有的系統啟動層級glassfish都是不自動啟動的
3. 修改成自動啟動
Java代碼
chkconfig glassfish3 on
它會自動幫你添加系統的啟動層級,這時再重複一下第二步檢查一下啟動層級。
你應該會看到
Java代碼
glassfish 0:off 1:off 2:on 3:on 4:on 5:on 6:off
一般linux的系統層級都是在3或者5上,你可以用命令 who -r 查看你系統的啟動層級。
好了,現在你可以重啟一下系統來檢查一下你的glassfish是否自動啟動了。呵呵,其實這個你稍微改一下就可以讓你的tomcat, jboss自動啟動的