欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux下实现glassfish自动启动 博客分类: 服务器 javaglassfishglassfish3tomcatlinux

程序员文章站 2024-02-20 17:09:22
...

1. 首先在 创建文件/etc/init.d/glassfish3, 文件内容如下. 注意修改下列内容的红色部分(不好意思,全部用英文写的)

 

#! /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=/usr/java/jdk1.6.0_17
#export CLASSPATH=.;$AS_JAVA/lib/dt.jar;$AS_JAVA/lib/tools.jar

GLASSFISHPATH=/opt/glassfish3/bin
export PASSWD=/opt/glassfish3/bin/.passwd

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
echo "starting instance st_server"
$GLASSFISHPATH/asadmin --user admin --passwordfile $PASSWD start-instance st_server

#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)

echo "stopping instance st_server"
$GLASSFISHPATH/asadmin --user admin --passwordfile $PASSWD stop-instance st_server

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

 

设置成可执行文件, 

 

$ sudo chmod +x /etc/init.d/glassfish3
 

 

 

其中的password文件如下

 

AS_ADMIN_PASSWORD=administration-password

请将 administration-password修改成你自己的密码

 

 

2. 查看刚刚添加的服务

 

chkconfig --list glassfish3

 你应该看到

 

glassfish3                 0:off  1:off  2:off  3:off  4:off  5:off  6:off

 

 所有的系统启动级别glassfish都是不自动启动的

 

3. 修改成自动启动

 

chkconfig  glassfish3 on

 

 它会自动帮你添加系统的启动级别,这时再重复一下第二步检查一下启动级别。

你应该会看到

 

glassfish                 0:off  1:off  2:on   3:on   4:on   5:on   6:off

 

 

一般linux的系统级别都是在3或者5上,你可以用命令 who -r 查看你系统的启动级别。

 

 

好了,现在你可以重启一下系统来检查一下你的glassfish是否自动启动了。呵呵,其实这个你稍微改一下就可以让你的tomcat, jboss自动启动的