3
# /etc/init.d/wildfly -- startup script for WildFly
5
# Written by Jorge Solorzano <jorsol@gmail.com>
9
# Required-Start: $remote_fs $network
10
# Required-Stop: $remote_fs $network
11
# Should-Start: $named
13
# Default-Start: 2 3 4 5
15
# Short-Description: WildFly Application Server
16
# Description: Provide WildFly startup/shutdown script
20
DESC="WildFly Application Server"
21
DEFAULT=/etc/default/$NAME
22
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
23
JBOSS_HOME="/opt/wildfly"
25
if [ `id -u` -ne 0 ]; then
26
echo "You need root privileges to run this script"
30
# Make sure wildfly is started with system locale
31
if [ -r /etc/default/locale ]; then
36
. /lib/lsb/init-functions
38
if [ -r /etc/default/rcS ]; then
42
# Overwrite settings from default file
43
if [ -f "$DEFAULT" ]; then
48
if [ -n "$JAVA_HOME" ]; then
49
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
53
if [ "x$JAVA" = "x" ]; then
54
if [ "x$JAVA_HOME" != "x" ]; then
55
JAVA="$JAVA_HOME/bin/java"
62
if [ -z "$JBOSS_HOME" ]; then
63
JBOSS_HOME=/opt/wildfly
67
# Check if wildfly is installed
68
if [ ! -f "$JBOSS_HOME/jboss-modules.jar" ]; then
69
log_failure_msg "$NAME is not installed in $JBOSS_HOME"
74
if [ -z "$JBOSS_USER" ]; then
79
id $JBOSS_USER > /dev/null 2>&1
80
if [ $? -ne 0 -o -z "$JBOSS_USER" ]; then
81
log_failure_msg "User $JBOSS_USER does not exist..."
85
# Startup mode of wildfly
86
if [ -z "$JBOSS_MODE" ]; then
91
if [ "$JBOSS_MODE" = "standalone" ]; then
92
JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh
93
if [ -z "$JBOSS_CONFIG" ]; then
94
JBOSS_CONFIG=standalone.xml
97
JBOSS_SCRIPT=$JBOSS_HOME/bin/domain.sh
98
if [ -z "$JBOSS_DOMAIN_CONFIG" ]; then
99
JBOSS_DOMAIN_CONFIG=domain.xml
101
if [ -z "$JBOSS_HOST_CONFIG" ]; then
102
JBOSS_HOST_CONFIG=host.xml
107
if [ ! -x $JBOSS_SCRIPT ]; then
108
log_failure_msg "$JBOSS_SCRIPT is not an executable!"
113
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
114
if [ ! -x $JBOSS_CLI ]; then
115
log_failure_msg "$JBOSS_CLI is not an executable!"
119
# The amount of time to wait for startup
120
if [ -z "$STARTUP_WAIT" ]; then
124
# The amount of time to wait for shutdown
125
if [ -z "$SHUTDOWN_WAIT" ]; then
129
# Location to keep the console log
130
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
131
JBOSS_CONSOLE_LOG=/var/log/$NAME/console.log
133
export JBOSS_CONSOLE_LOG
135
# Location to set the pid file
136
JBOSS_PIDFILE=/var/run/$NAME/$NAME.pid
139
# Launch wildfly in background
140
LAUNCH_JBOSS_IN_BACKGROUND=1
141
export LAUNCH_JBOSS_IN_BACKGROUND
143
# Helper function to check status of wildfly service
145
pidofproc -p $JBOSS_PIDFILE $JAVA >/dev/null 2>&1
150
log_daemon_msg "Starting $DESC" "$NAME"
153
if [ $status_start -eq 3 ]; then
154
mkdir -p $(dirname $JBOSS_PIDFILE)
155
mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
156
chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
157
cat /dev/null > $JBOSS_CONSOLE_LOG
159
if [ "$JBOSS_MODE" = "standalone" ]; then
160
start-stop-daemon --start --user "$JBOSS_USER" \
161
--chuid "$JBOSS_USER" --chdir "$JBOSS_HOME" --pidfile "$JBOSS_PIDFILE" \
162
--exec "$JBOSS_SCRIPT" -- -c $JBOSS_CONFIG >> $JBOSS_CONSOLE_LOG 2>&1 &
164
start-stop-daemon --start --user "$JBOSS_USER" \
165
--chuid "$JBOSS_USER" --chdir "$JBOSS_HOME" --pidfile "$JBOSS_PIDFILE" \
166
--exec "$JBOSS_SCRIPT" -- --domain-config=$JBOSS_DOMAIN_CONFIG \
167
--host-config=$JBOSS_HOST_CONFIG >> $JBOSS_CONSOLE_LOG 2>&1 &
172
until [ $count -gt $STARTUP_WAIT ]
174
grep 'JBAS015874:' $JBOSS_CONSOLE_LOG > /dev/null
175
if [ $? -eq 0 ] ; then
180
count=$((count + 1));
183
if check_status; then
189
if [ $launched -eq 0 ]; then
190
log_warning_msg "$DESC hasn't started within the timeout allowed"
191
log_warning_msg "please review file $JBOSS_CONSOLE_LOG to see the status of the service"
193
elif [ $status_start -eq 1 ]; then
194
log_failure_msg "$DESC is not running but the pid file exists"
196
elif [ $status_start -eq 0 ]; then
197
log_success_msg "$DESC (already running)"
203
if [ $status_stop -eq 0 ]; then
204
read kpid < $JBOSS_PIDFILE
205
log_daemon_msg "Stopping $DESC" "$NAME"
207
start-stop-daemon --start --chuid "$JBOSS_USER" \
208
--exec "$JBOSS_CLI" -- --connect --command=:shutdown \
211
if [ $? -eq 1 ]; then
216
until [ $count -gt $SHUTDOWN_WAIT ]
219
if [ $? -eq 3 ]; then
223
count=$((count + 1));
226
if [ $count -gt $SHUTDOWN_WAIT ]; then
231
elif [ $status_stop -eq 1 ]; then
232
log_action_msg "$DESC is not running but the pid file exists, cleaning up"
234
elif [ $status_stop -eq 3 ]; then
235
log_action_msg "$DESC is not running"
241
if [ $status_restart -eq 0 ]; then
249
if [ $status_reload -eq 0 ]; then
250
log_daemon_msg "Reloading $DESC config" "$NAME"
252
if [ "$JBOSS_MODE" = "standalone" ]; then
253
RELOAD_CMD=":reload"; else
254
RELOAD_CMD=":reload-servers"; fi
256
start-stop-daemon --start --chuid "$JBOSS_USER" \
257
--exec "$JBOSS_CLI" -- --connect --command=$RELOAD_CMD >/dev/null 2>&1
259
if [ $? -eq 0 ]; then
265
log_failure_msg "$DESC is not running"
271
if [ $status -eq 0 ]; then
272
read pid < $JBOSS_PIDFILE
273
log_action_msg "$DESC is running with pid $pid"
275
elif [ $status -eq 1 ]; then
276
log_action_msg "$DESC is not running and the pid file exists"
278
elif [ $status -eq 3 ]; then
279
log_action_msg "$DESC is not running"
282
log_action_msg "Unable to determine $NAME status"
287
log_action_msg "Usage: $0 {start|stop|restart|reload|force-reload|status}"