blob: 07b51fb7d81a470810ad62c778e9f81cd860098b (
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
79
|
#!/bin/sh
#
# %%APP_SHORTNAME%% startup script.
#
# $FreeBSD$
#
# PROVIDE: %%APP_SHORTNAME%%
# REQUIRE: NETWORKING SERVERS
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable %%APP_SHORTNAME%%:
# %%APP_SHORTNAME%%_enable (bool): Set to "YES" to enable %%APP_SHORTNAME%%
# %%APP_SHORTNAME%%_args (str): Optional arguments to JBoss
# %%APP_SHORTNAME%%_log_stdout (str) JBoss log output stdout, filename.
# %%APP_SHORTNAME%%_log_stderr (str) JBoss log output stderr, filename.
#
. /etc/rc.subr
name="%%APP_SHORTNAME%%"
rcvar=%%APP_SHORTNAME%%_enable
load_rc_config $name
%%APP_SHORTNAME%%_enable="${%%APP_SHORTNAME%%_enable:-"NO"}"
%%APP_SHORTNAME%%_log_stdout="${%%APP_SHORTNAME%%_log_stdout:-"${%%APP_SHORTNAME%%_logdir}/stdout.log"}"
%%APP_SHORTNAME%%_log_stderr="${%%APP_SHORTNAME%%_log_stderr:-"${%%APP_SHORTNAME%%_logdir}/stderr.log"}"
%%APP_SHORTNAME%%_args="${%%APP_SHORTNAME%%_args:-""}"
%%APP_SHORTNAME%%_sleep="${%%APP_SHORTNAME%%_sleep:-"5"}"
%%APP_SHORTNAME%%_kill9="${%%APP_SHORTNAME%%_kill9:-""}"
%%APP_SHORTNAME%%_additional_killall="${%%APP_SHORTNAME%%_additional_killall:-""}"
%%APP_SHORTNAME%%_user="%%USER%%"
%%APP_SHORTNAME%%_logdir="%%LOG_DIR%%"
start_cmd="%%APP_SHORTNAME%%_start"
stop_cmd="%%APP_SHORTNAME%%_stop"
pidfile="%%PID_FILE%%"
JBOSS_HOME="%%APP_HOME%%"
%%APP_SHORTNAME%%_start ()
{
if [ ! -d "${%%APP_SHORTNAME%%_logdir}" ]
then
install -d -o ${%%APP_SHORTNAME%%_user} ${%%APP_SHORTNAME%%_logdir}
fi
echo "Starting %%APP_SHORTNAME%%."
daemon -u ${%%APP_SHORTNAME%%_user} ${JBOSS_HOME}/bin/standalone.sh ${%%APP_SHORTNAME%%_args} >> ${%%APP_SHORTNAME%%_log_stdout} 2>> ${%%APP_SHORTNAME%%_log_stderr} >> ${%%APP_SHORTNAME%%_logdir}/boot.log 2>> ${%%APP_SHORTNAME%%_logdir}/boot.log
sleep ${%%APP_SHORTNAME%%_sleep} # let daemon(8) and sh(1) finish before executing pgrep(1)
pgrep -U ${%%APP_SHORTNAME%%_user} -f ${JBOSS_HOME}/modules > ${pidfile}
chown ${%%APP_SHORTNAME%%_user} $pidfile
}
%%APP_SHORTNAME%%_stop ()
{
# Subvert the check_pid_file procname check.
if [ -f ${pidfile} ]
then
kill `cat ${pidfile}`
# Only if we aware that our setup can hangs, and only after trying simple kill, we can kill it hard way.
if [ ! -z "${%%APP_SHORTNAME%%_kill9}" ]
then
sleep ${%%APP_SHORTNAME%%_sleep}
kill -9 `cat ${pidfile}`
fi
# In some setups, JBoss can spawn some child processess, which could prevent it from stopping, and freeing net ports.
# Let's blindly kill them all, since we are really know what we are doing.
if [ ! -z "${%%APP_SHORTNAME%%_additional_killall}" ]
then
sleep ${%%APP_SHORTNAME%%_sleep}
killall ${%%APP_SHORTNAME%%_additional_killall}
fi
fi
}
run_rc_command "$1"
|