summaryrefslogtreecommitdiffstats
path: root/network/jboss-as/rc.jboss-as
blob: 1ea83476cb805c54562af47d62ca8a78b20aa417 (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
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
140
141
142
143
144
145
#!/bin/sh

# Start/stop/restart jboss-as.

# Copyright 2011 Giorgio Peron, Campodarsego, PD, Italy giorgio.peron@gmail.com
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/usr/share/jboss-as"}

# make java is on your path
JAVAPTH=${JAVAPTH:-"$JAVA_HOME/bin"}

# define the user under which jboss will run, or use RUNASIS to run as the current user
JBOSSUS=${JBOSSUS:-"jboss"}

export LAUNCH_JBOSS_IN_BACKGROUND=yes

# define the script to use to start standalone jboss
JBOSS_START_STANDALONE=${JBOSS_START_STANDALONE:-"$JBOSS_HOME/bin/standalone.sh "}

# define the script to use to shutdown jboss
# change host and port as need
JBOSS_STOP_STANDALONE=${JBOSS_STOP_STANDALONE:-"$JBOSS_HOME/bin/jboss-admin.sh --connect controller=127.0.0.1:9999 command=:shutdown"}

# define log file
JBOSS_CONSOLE="/var/log/jboss-as/jboss.log"
JBOSS_DOMAIN_CONSOLE="/var/log/jboss-as/jboss_domain.log"

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  # ensure the file exists
  touch $JBOSS_CONSOLE
  if [ "$JBOSSUS" != "RUNASIS" ]; then
    chown -R $JBOSSUS.$JBOSSUS $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"}

if [ -n "$JBOSS_DOMAIN_CONSOLE" -a ! -d "$JBOSS_DOMAIN_CONSOLE" ]; then
  # ensure the file exists
  touch $JBOSS_DOMAIN_CONSOLE
  if [ "$JBOSSUS" != "RUNASIS" ]; then
    chown -R $JBOSSUS.$JBOSSUS $JBOSS_DOMAIN_CONSOLE
  fi
fi

if [ -n "$JBOSS_DOMAIN_CONSOLE" -a ! -f "$JBOSS_DOMAIN_CONSOLE" ]; then
  echo "WARNING: location for saving console log invalid: $JBOSS_DOMAIN_CONSOLE"
  echo "WARNING: ignoring it and using /dev/null"
  JBOSS_DOMAIN_CONSOLE="/dev/null"
fi

# define what will be done with the console log
JBOSS_DOMAIN_CONSOLE=${JBOSS_DOMAIN_CONSOLE:-"/dev/null"}

CMD_START_STANDALONE="cd $JBOSS_HOME/bin; $JBOSS_START_STANDALONE" 
CMD_STOP_STANDALONE="cd $JBOSS_HOME/bin; $JBOSS_STOP_STANDALONE"

if [ "$JBOSSUS" = "RUNASIS" ]; then
  SUBIT=""
else
  SUBIT="su $JBOSSUS -c "
fi

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

case "$1" in
start)
	echo "Starting JBoss Application Server"
    cd $JBOSS_HOME/bin
    if [ -z "$SUBIT" ]; then
        eval $CMD_START_STANDALONE >${JBOSS_CONSOLE} 2>&1 &
    else
        $SUBIT "$CMD_START_STANDALONE >${JBOSS_CONSOLE} 2>&1 &" 
    fi
    ;;
stop)
	echo "Stopping JBoss Application Server"
    if [ -z "$SUBIT" ]; then
        $CMD_STOP_STANDALONE >/dev/null 2>&1
    else
        $SUBIT "$CMD_STOP_STANDALONE >/dev/null 2>&1"
    fi 
    ;;
restart)
    $0 stop
    $0 start
    ;;
domain-start)
	echo "Starting Domain JBoss Application Server"
    cd $JBOSS_HOME/bin
    if [ -z "$SUBIT" ]; then
        eval $CMD_START_DOMAIN >${JBOSS_DOMAIN_CONSOLE} 2>&1 &
    else
        $SUBIT "$CMD_START_DOMAIN >${JBOSS_DOMAIN_CONSOLE} 2>&1 &" 
    fi
    ;;
domain-stop)
	echo "Stopping Domain JBoss Application Server"
    if [ -z "$SUBIT" ]; then
        $CMD_STOP_DOMAIN >/dev/null 2>&1
    else
        $SUBIT "$CMD_STOP_DOMAIN >/dev/null 2>&1"
    fi 
    ;;
domain-restart)
    $0 domain-stop
    $0 domain-start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help|domain-start|domain-stop|domain-restart)"
esac