Skip to content

Instantly share code, notes, and snippets.

@uphy
Last active February 14, 2023 18:29
Show Gist options
  • Save uphy/8518429 to your computer and use it in GitHub Desktop.
Save uphy/8518429 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# glassfish: Startup script for Glassfish Application Server.
#
# chkconfig: 3 80 05
# description: Startup script for domain1 of Glassfish Application Server.
export GLASSFISH_HOME=/usr/local/glassfish/glassfish
export GLASSFISH_OWNER=glassfish
export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$PATH
DOMAIN=domain1
NODE=localhost-domain1
DBPORT=1527
ASADMIN=$GLASSFISH_HOME/bin/asadmin
SERVER_INSTANCE_DIR=$GLASSFISH_HOME/nodes/$NODE
LOGFILE="$GLASSFISH_HOME/domains/$DOMAIN/logs/startup.log"
start_instance(){
instanceName=$1
echo -n "Starting GlassFish Server Instance '$instanceName': "
su $GLASSFISH_OWNER -c "$ASADMIN start-local-instance $instanceName" >> $LOGFILE
echo "done"
}
start_instances(){
for serverInstance in `ls $SERVER_INSTANCE_DIR`
do
if [ 'agent' != $serverInstance ];then
start_instance $serverInstance
fi
done
}
start_domain(){
echo -n "Starting GlassFish DAS: "
su $GLASSFISH_OWNER -c "$ASADMIN start-domain $DOMAIN" >> $LOGFILE
echo "done"
}
stop_instance(){
instanceName=$1
echo -n "Stopping GlassFish Server Instance '$instanceName': "
su $GLASSFISH_OWNER -c "$ASADMIN stop-local-instance $instanceName" >> $LOGFILE
echo "done"
}
stop_instances(){
for serverInstance in `ls $SERVER_INSTANCE_DIR`
do
if [ 'agent' != $serverInstance ];then
stop_instance $serverInstance
fi
done
}
start_database(){
echo -n "Starting Derby: "
su $GLASSFISH_OWNER -c "$ASADMIN start-database --dbport $DBPORT" >> $LOGFILE
echo "done"
}
stop_database(){
echo -n "Stopping Derby: "
su $GLASSFISH_OWNER -c "$ASADMIN stop-database --dbport $DBPORT" >> $LOGFILE
echo "done"
}
stop_domain(){
echo -n "Stopping GlassFish DAS: "
su $GLASSFISH_OWNER -c "$ASADMIN stop-domain $DOMAIN" >> $LOGFILE
echo "done"
}
start() {
start_domain
sleep 2
start_database
start_instances
}
stop() {
stop_database
stop_instances
stop_domain
}
status(){
echo "GlassFish Domain Status: "
su $GLASSFISH_OWNER -c "$ASADMIN list-domains"
RETVAL=$?
echo "done"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
RETVAL=$?
;;
*)
echo $"Usage: glassfish {start|stop|restart|status}"
exit
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment