/
jboss.init.erb
140 lines (117 loc) · 3.45 KB
/
jboss.init.erb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
# File Managed by Puppet
# Based on init script samples provided in Jboss source
# define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"<%= scope.lookupvar('jboss::params::jboss_dir') %>"}
# define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"<%= user %>"}
# make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}
# configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"<%= name %>"}
# if JBOSS_HOST specified, use -b to bind jboss services to that address
#JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b <%= bindaddr %>"}
JBOSS_BIND_ADDR=${JBOSS_HOST:-"-b <%= bindaddr %>"}
# define the classpath for the shutdown class
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}
# define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
# Lock and Pid files
LOCKFILE=/var/lock/subsys/jboss-<%= name %>
PIDFILE=/var/run/jboss-<%= name %>.pid
if [ "$JBOSS_USER" = "RUNASIS" ]; then
SUBIT=""
else
SUBIT="su - $JBOSS_USER -c "
fi
if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
# ensure the file exists
touch $JBOSS_CONSOLE
if [ ! -z "$SUBIT" ]; then
chown $JBOSS_USER $JBOSS_CONSOLE
fi
fi
if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
echo "WARNING: ignoring it and using /dev/null"
JBOSS_CONSOLE="/dev/null"
fi
#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
# Jboss Start command
<% if scope.lookupvar('run_conf') != "" -%>
# Custom, per instance, run.conf configured via Puppet
JBOSS_CMD_START="cd $JBOSS_HOME/bin; export RUN_CONF=<%= scope.lookupvar('jboss::params::jboss_dir') %>/server/<%= name %>/run.conf ; $JBOSSSH"
<% else -%>
JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
<% end -%>
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}
if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
export PATH=$PATH:$JAVAPTH
fi
if [ ! -d "$JBOSS_HOME" ]; then
echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
exit 1
fi
status () {
pslist=$( ps -ef | grep java | grep $JBOSS_USER | awk '{print $2}' | tr '\n' ' ' | sed -e s/\ $// )
if [ -n "$pslist" ]; then
echo "jboss (pid $pslist) is running result: 0"
return 0
fi
if [ -f $PIDFILE ]; then
echo "jboss dead but pid file exists result: 1"
return 1
fi
if [ -f $LOCKFILE ]; then
echo "jboss dead but subsys locked result: 2"
return 2
fi
echo "jboss is stopped result: 3"
return 3
}
start () {
if [ -f $LOCKFILE ]; then
status
exit
fi
cd $JBOSS_HOME/bin
echo JBOSS_CMD_START = $JBOSS_CMD_START
if [ -z "$SUBIT" ]; then
eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
if [ "$?" -eq 0 ]; then
touch $LOCKFILE
fi
else
$SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
if [ "$?" -eq 0 ]; then
touch $LOCKFILE
fi
fi
}
stop () {
echo JBOSS_CMD_STOP = $JBOSS_CMD_STOP
if [ -z "$SUBIT" ]; then
$JBOSS_CMD_STOP && rm -f $LOCKFILE
else
$SUBIT "$JBOSS_CMD_STOP" && rm -f $LOCKFILE
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 15
start
;;
status)
status
;;
*)
echo "usage: $0 (start|stop|restart|status|help)"
esac