bash 脚本编程二十 GlassFishV3自动部署

我的手动安装版本请参考:http://blog.csdn.net/sheismylife/article/details/7649571


1.先下载最新版本的glassfish, 网址:http://glassfish.java.net/downloads/3.1.2.2-final.html

解压后放到工程目录下。

然后根据自己的需要修改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




你可能感兴趣的:(编程,脚本,user,bash,domain,Glassfish)