1.先點擊這裡下載最新版本的glassfish。
解壓後放到工程目錄下。
然後根據自己的需要修改glassfish/domains/domain1/config/domain.xml文件的配置。
注意config/asenv.conf文件中添加jdk路徑,防止JSP報錯。
AS_JAVA=/usr/jdk1.6
2.現在需要幾個函數幫助檢查用戶和組,並能夠創建系統用戶及其目錄,創建用戶組,
因此在tool.sh中添加了四個函數:
- #$1 user name
- #return 1 if exists
- #return 0 if doesn't exist
- function haSUSEr {
- h=`grep "$1" /etc/passwd`
- echo "h: $h"
- if [ -n "$h" ]
- then
- return 1
- else
- return 0
- fi
- }
-
- #$1 user group name
- #return 1 if exists
- #return 0 if doesn't exist
- function hasUserGroup {
- h=`grep "$1" /etc/group`
- echo "h: $h"
- if [ -n "$h" ]
- then
- return 1
- else
- return 0
- fi
- }
- #remove user and home folder
- #then create then again
- function recreateSystemUserAndFolder {
- hasUser $1
- r=$?
-
- if [ $r -eq 1 ]
- then
- echo "$1 exits already,remove it..."
- userdel -r $1
- else
- echo "$1 doesn't exist,create it..."
- fi
- adduser --home /home/$1 --system --shell /bin/bash $1
- }
-
- #remove user group
- #then create it again
- function recreateUserGroup {
- hasUserGroup $1
- r=$?
- if [ $r -eq 1 ]
- then
- echo "$1 exists already, remove it..."
- delgroup $1
- else
- echo "$1 doesn't exist, create it..."
- fi
- groupadd $1
- }
3.現在創建系統服務吧。
准備好glassfish腳本:
- export AS_JAVA=/usr/jdk1.6
-
- GLASSFISHPATH=/home/glassfish/bin
-
- case "$1" in
- start)
- echo "starting glassfish from $GLASSFISHPATH"
- sudo -u glassfish $GLASSFISHPATH/asadmin start-domain domain1
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- stop)
- echo "stopping glassfish from $GLASSFISHPATH"
- sudo -u glassfish $GLASSFISHPATH/asadmin stop-domain domain1
- ;;
- *)
- echo $"usage: $0 {start|stop|restart}"
- exit 3
- ;;
- esac
- :
最後看一下install.sh
- #!/bin/bash
-
- source ../common/tool.sh
-
- glassfishUser="glassfish"
- glassfishGroup="glassfishadm"
-
-
- recreateSystemUserAndFolder $glassfishUser
-
- recreateUserGroup $glassfishGroup
-
- usermod -a -G $glassfishGroup $glassfishUser
-
- chgrp -R $glassfishGroup /home/$glassfishUser
-
- cp -r ./glassfish3/* /home/$glassfishUser/
- cp -r ./glassfish3/.org.opensolaris,pkg /home/$glassfishUser/.org.opensolaris,pkg
-
- chown -R $glassfishUser /home/$glassfishUser
- chmod -R ug+rwx /home/$glassfishUser/bin/
- chmod -R ug+rwx /home/$glassfishUser/glassfish/bin/
- chmod -R o-rwx /home/$glassfishUser/bin/
- chmod -R o-rwx /home/$glassfishUser/glassfish/bin/
-
- cp ./glassfish /etc/init.d/
- update-rc.d glassfish defaults
-
- service glassfish start
每次都會先刪除已存在的用戶和組,以及目錄。
最後給出目錄結構:
$ tree -L 1
.
├── glassfish
├── glassfish3
└── install.sh
1 directory, 2 files
chenshu@sloop2:~/work/1