Bash Script Programming 20 Automatic deployment of glassfishv3

Source: Internet
Author: User

For my manual installation version, see: http://blog.csdn.net/sheismylife/article/details/7649571

1. First download the latest version of glassfish, URL: http://glassfish.java.net/downloads/3.1.2.2-final.html

Decompress the package and place it in the project directory.

Modify the configuration of the glassfish/domains/domain1/config/domain. xml file as needed.

Note that the JDK path is added to the config/asenv. conf file to prevent JSP errors.

AS_JAVA=/usr/jdk1.6

2. Now you need several functions to check users and groups, create system users and their directories, and create user groups,

Therefore, four functions are added to tool. sh:

#$1 user name#return 1 if exists#return 0 if doesn't existfunction hasUser {    h=`grep "$1" /etc/passwd`    echo "h: $h"    if [ -n "$h" ]    thenreturn 1    elsereturn 0    fi}#$1 user group name#return 1 if exists#return 0 if doesn't existfunction hasUserGroup {    h=`grep "$1" /etc/group`    echo "h: $h"    if [ -n "$h" ]    thenreturn 1    elsereturn 0    fi}

#remove user and home folder#then create then againfunction recreateSystemUserAndFolder {    hasUser $1    r=$?        if [ $r -eq 1 ]    thenecho "$1 exits already,remove it..."userdel -r $1    elseecho "$1 doesn't exist,create it..."    fi    adduser --home /home/$1 --system --shell /bin/bash $1  }#remove user group #then create it againfunction recreateUserGroup {    hasUserGroup $1    r=$?    if [ $r -eq 1 ]    thenecho "$1 exists already, remove it..."delgroup $1    elseecho "$1 doesn't exist, create it..."    fi    groupadd $1}

3. Now create a system service.

Prepare the glassfish script:

export AS_JAVA=/usr/jdk1.6 GLASSFISHPATH=/home/glassfish/bin case "$1" instart)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:

Finally, let's take a look at install. Sh.

#!/bin/bash source ../common/tool.shglassfishUser="glassfish"glassfishGroup="glassfishadm"recreateSystemUserAndFolder $glassfishUserrecreateUserGroup $glassfishGroupusermod -a -G $glassfishGroup $glassfishUserchgrp -R $glassfishGroup /home/$glassfishUsercp -r ./glassfish3/* /home/$glassfishUser/cp -r ./glassfish3/.org.opensolaris,pkg /home/$glassfishUser/.org.opensolaris,pkgchown -R $glassfishUser /home/$glassfishUserchmod -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 defaultsservice glassfish start

The existing users, groups, and directories are deleted each time.

Finally, the directory structure is given:

$ tree -L 1.├── glassfish├── glassfish3└── install.sh1 directory, 2 fileschenshu@sloop2:~/work/1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.