summaryrefslogtreecommitdiff
path: root/www/glassfish/files/glassfish.in
blob: 981cfdae67432fbf22f9948ab8be965f531c1f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh

# PROVIDE: glassfish
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# glassfish_enable (bool):
#   Set to NO by default.
#   Set it to YES to enable glassfish. 
#
# glassfish_java_home (string):
#   Used to set JAVA_HOME (optional).
#
# glassfish_java_opts (string):
#   Used to set JAVA_OPTS (optional).
#
# glassfish_domain_name (string):
#   Set the name of the Glassfish domain to start (default: domain1).

. /etc/rc.subr

name=glassfish
rcvar=glassfish_enable

load_rc_config $name

: ${glassfish_enable:=NO}
: ${glassfish_java_home=""}
: ${glassfish_java_opts=""}
: ${glassfish_domain_name="domain1"}
: ${glassfish_home="%%DATADIR%%/glassfish"}

procname="${glassfish_java_home}/bin/java"

# Since we receive the JAVA_HOME variable by default from the Java package
# we depend on, we override JAVA_HOME only if the user overrid it.
if [ ! -z ${glassfish_java_home} ] ; then
  export JAVA_HOME=${glassfish_java_home}
else
  export JAVA_HOME=%%JAVA_HOME%%
fi

export PATH=${JAVA_HOME}/bin:${PATH}
export JAVA_OPTS=${glassfish_java_opts}

start_precmd="glassfish_prestart"
start_cmd="${glassfish_home}/bin/asadmin start-domain ${glassfish_domain_name}"
stop_cmd="${glassfish_home}/bin/asadmin stop-domain ${glassfish_domain_name}"
status_cmd="glassfish_status"

glassfish_prestart()
{
  if [ -z ${glassfish_domain_name} ] ; then
    warn "Glassfish domain name cannot be empty, Glassfish will NOT start."
    return 1
  fi
}

glassfish_status()
{
  # The output of list-domains -l in glassfish 4.1 is the following:
  # 
  # DOMAIN   ADMIN_HOST  ADMIN_PORT  RUNNING  RESTART_REQUIRED
  # domain1  localhost   4848        true     false
  IS_DOMAIN_RUNNING=$(${glassfish_home}/bin/asadmin list-domains -l | grep "^${glassfish_domain_name}" | awk '{ print $4; }')
  if checkyesno IS_DOMAIN_RUNNING ; then
    echo Glassfish is running.
    return 0
  else
    echo Glassfish is not running.
    return 1
  fi
}

run_rc_command "$1"