- Does not support systemd out of the box
- Application server must run under root account
So, this is the script I wrote (you need to place it on /etc/rc.d/init.d/glassfish and give it proper execution permission):
#!/bin/sh -
# Script to start/stop/restart GlassFish
# description: glassfish
#
if [ -z ${GLASSFISH_HOME+x} ]; then
GLASSFISH_HOME=/opt/glassfish4;
fi
if [ -z ${GLASSFISH_USER+x} ]; then
GLASSFISH_USER=glassfish;
fi
if [ -z ${GLASSFISH_DOMAIN+x} ]; then
GLASSFISH_DOMAIN=domain1;
fi
GH=$GLASSFISH_HOME
GU=$GLASSFISH_USER
GD=$GLASSFISH_DOMAIN
case "$1" in
start)
su - $GU ${GH}/bin/asadmin start-database
su - $GU ${GH}/bin/asadmin start-domain
;;
stop)
su - $GU ${GH}/bin/asadmin stop-database
su - $GU ${GH}/bin/asadmin stop-domain $GLASSFISH_DOMAIN
;;
restart)
su - $GU ${GH}/bin/asadmin stop-domain $GLASSFISH_DOMAIN
su - $GU ${GH}/bin/asadmin start-domain $GLASSFISH_DOMAIN
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
Then you need to do:
# systemctl --system daemon-reload
# systemctl enable glassfish
# systemctl start glassfish
And you are done.
Of course, make sure you have the right values on the environment variables. For that purpose I place a glassfish.sh file under /etc/profile.d/ with the following content:
GLASSFISH_HOME=/opt/glassfish4
GLASSFISH_USER=glassfish
GLASSFISH_DOMAIN=domain1
export GLASSFISH_HOME GLASSFISH_USER GLASSFISH_DOMAIN
the only way I managed to get glassfish 3 running automatically after centOS7 boot is to run the command line :
ReplyDelete/usr/local/glassfish3/glassfish/bin/asadmin create-service
Yes! I tried to create a exec for systemd, but was impossible. So, I agree
Delete