Created
November 6, 2011 00:32
-
-
Save arlukin/1342253 to your computer and use it in GitHub Desktop.
Startup (/etc/init.d/glassfish) script for Glassfish 3.1 on Centos 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Startup script for Glassfish. | |
# | |
# chkconfig: 2345 95 05 | |
# description: Start the java application server, glassfish. | |
# pidfile: /var/run/glassfish.pid | |
# | |
# Used and tested on centos 6 | |
# | |
# Author: [email protected] | |
# | |
GLASSFISH_PATH=/usr/local/glassfish-3.1.1/glassfish; | |
export GLASSFISH_PATH | |
OWNER=glassfish; | |
export OWNER | |
wait_for_mysql_to_start() { | |
echo -n "Wait for server $1 port 3306 to start." | |
while [ TRUE ]; do | |
if nc -w 3 $1 3306 <<< Ó &> /dev/null | |
then | |
echo "." | |
break | |
else | |
echo -n "." | |
sleep 10 | |
fi | |
done | |
} | |
start() { | |
echo -n "Starting Glassfish ($1): " | |
COMMAND1="echo \"Starting Secure Glassfish at `date`\" >> $GLASSFISH_PATH/domains/$1/logs/startup.log" | |
COMMAND2="$GLASSFISH_PATH/bin/asadmin start-domain $1 >> $GLASSFISH_PATH/domains/$1/logs/startup.log" | |
if [ `whoami` = "glassfish" ]; then | |
$COMMAND1 | |
$COMMAND2 | |
else | |
su $OWNER -c "$COMMAND1" | |
su $OWNER -c "$COMMAND2" | |
fi | |
echo "done" | |
} | |
stop() { | |
echo -n "Stopping Glassfish ($1): " | |
COMMAND1="echo \"Stopping Secure Glassfish at `date`\" >> $GLASSFISH_PATH/domains/$1/logs/startup.log" | |
COMMAND2="$GLASSFISH_PATH/bin/asadmin stop-domain $1 >> $GLASSFISH_PATH/domains/$1/logs/startup.log" | |
if [ `whoami` = "glassfish" ]; then | |
$COMMAND1 | |
$COMMAND2 | |
else | |
su $OWNER -c "$COMMAND1" | |
su $OWNER -c "$COMMAND2" | |
fi | |
echo "done" | |
} | |
restart() { | |
echo -n "Restarting Glassfish ($1): " | |
COMMAND1="echo \"Restarting Secure Glassfish at `date`\" >> $GLASSFISH_PATH/domains/$1/logs/startup.log" | |
COMMAND2="$GLASSFISH_PATH/bin/asadmin restart-domain $1 >> $GLASSFISH_PATH/domains/$1/logs/startup.log" | |
if [ `whoami` = "glassfish" ]; then | |
$COMMAND1 | |
$COMMAND2 | |
else | |
su $OWNER -c "$COMMAND1" | |
su $OWNER -c "$COMMAND2" | |
fi | |
echo "done" | |
} | |
# Handle commandline arguments | |
case "$1" in | |
start) | |
wait_for_mysql_to_start "${MYSQL_PRIMARY}" | |
wait_for_mysql_to_start "${MYSQL_SECONDARY}" | |
start "domain1" | |
if [ "all" == "$2" ] | |
then | |
start "domain2" | |
fi | |
;; | |
stop) | |
stop "domain1" | |
if [ "all" == "$2" ] | |
then | |
stop "domain2" | |
fi | |
;; | |
reload|restart|force-reload) | |
wait_for_mysql_to_start "${MYSQL_PRIMARY}" | |
wait_for_mysql_to_start "${MYSQL_SECONDARY}" | |
restart "domain1" | |
if [ "all" == "$2" ] | |
then | |
restart "domain2" | |
fi | |
;; | |
*) | |
echo "Usage: glassfish {start|stop|reload|restart|force-reload} [all]" | |
echo "all - All commands will affect both domain1 and domain2." | |
exit | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment