2014年1月30日星期四

Linux_010:CentOS6.5下开机自启动GlassFish4

首先要安装好GlassFish,请参考《在CentOS6.5上安装GlassFish4.0》。

以下操作均是在root用户下执行

1. 在/etc/init.d/目录下创建脚本:glassfish4

#! /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

export AS_JAVA=/usr/java/jdk1.7.0_45
#export CLASSPATH=.;$AS_JAVA/lib/dt.jar;$AS_JAVA/lib/tools.jar

GLASSFISHPATH=/home/glassfish/glassfish4/bin/
export PASSWD=/home/glassfish/glassfish4/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

2. 设置成可执行文件:chmod +x /etc/init.d/glassfish4

3. 在/home/glassfish/glassfish4/bin/目录下创建.passwd文件
内容如下:
AS_ADMIN_PASSWORD=administration-password
把administration-password 替换成你的GlassFish的管理密码。

4. 检查GlassFish状态:chkconfig --list glassfish4
输出如下:
glassfish4 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add glassfish4”)

5. 开启GlassFish状态:chkconfig glassfish4 on

6. 再次检查GlassFish状态:chkconfig --list glassfish4
输出如下:
glassfish4     0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

7. 重启

8. 登入后,直接访问:http://localhost:4848/common/index.jsf

参考文献:
1. http://yhjhoo.iteye.com/blog/1154010
2. http://os.51cto.com/art/201301/377515.htm

没有评论: