Skip to content

Instantly share code, notes, and snippets.

@maji-KY
Created December 5, 2012 13:48
Show Gist options
  • Save maji-KY/4215640 to your computer and use it in GitHub Desktop.
Save maji-KY/4215640 to your computer and use it in GitHub Desktop.
GlassFish Init Script
#!/bin/sh
#
# glassfish Startup script for glassfish
#
# chkconfig: - 99 01
# processname: glassfish
# config: /etc/glassfish/glassfish.conf
# config: /etc/sysconfig/glassfish
# pidfile: /var/run/glassfish.pid
# description: glassfish is a JavaEE Application Server
#
### BEGIN INIT INFO
# Provides: glassfish
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start:3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: start and stop glassfish
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/glassfish ]; then
. /etc/sysconfig/glassfish
fi
prog=glassfish
domain=domain1
ASADMIN="/usr/local/glassfish/glassfish/bin/asadmin"
START_OP="start-domain"
STOP_OP="stop-domain"
RESTART_OP="restart-domain"
DOMAIN_DIR="/usr/local/glassfish/glassfish/domains"
DOMAIN_ARGS="--domaindir ${DOMAIN_DIR} ${domain}"
lockfile=${LOCKFILE-/var/lock/subsys/glassfish}
pidfile=${PIDFILE-/var/run/glassfish.pid}
SLEEPMSEC=100000
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon --user glassfish --pidfile=${pidfile} ${ASADMIN} ${START_OP} ${DOMAIN_ARGS}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile} && cp ${DOMAIN_DIR}/${domain}/config/pid ${pidfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
${ASADMIN} ${STOP_OP} ${DOMAIN_ARGS}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
restart() {
echo -n $"Restarting $prog: "
${ASADMIN} ${RESTART_OP} ${DOMAIN_ARGS}
RETVAL=$?
echo
}
rh_status() {
status -p ${pidfile} ${prog}
}
# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
status)
rh_status
RETVAL=$?
;;
restart)
restart
;;
*)
echo $"Usage: $prog {start|stop|restart|status|help}"
RETVAL=2
esac
exit $RETVAL
@dazed19
Copy link

dazed19 commented Nov 26, 2015

Hi - great script - I'm replacing my original one with this - as this uses proper pid files which I need to allow a monitoring script to find the glassfish process.

I have created a fork (https://gist.github.com/dazed19/7fd0d5259b9daf9b755a) as I had an issue with restart (no pid/lock files) and made an addition to allow use for multiple glassfish domains - happy for you to apply (gist doesn't support pull request).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment