linux下實現glassfish自動啟動

來源:互聯網
上載者:User

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自動啟動的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.