Tomcat stops after restarting it from jenkins execution shell - java

I have configured jenkins to deleted tomcat existing workspace, copy the existing build to tomcat workspace and then restart tomcat. I use execute shell from jenkins. The script is the following:
#!/bin/sh
version=1.0.0-BUILD-SNAPSHOT
build_no=${BUILD_NUMBER}
if [ $build_no ]
then
cd ~
TOMCAT_WEBAPPS=`locate apache-tomcat | grep apache-tomcat | grep webapps | head -n 1 | awk '{ print $1 }'`
rm $TOMCAT_WEBAPPS/app-api.war
rm -rf $TOMCAT_WEBAPPS/app-api/*
rmdir $TOMCAT_WEBAPPS/app-api/
wget http://jenkins/job/project/ws/api/build/api-$version-$build_no-bin.zip
unzip -j connectedcare-api-$version-$build_no-bin.zip
rm api-$version-$build_no-bin.zip
cp api-$version.war $TOMCAT_WEBAPPS/app-api.war
rm api-$version.war
else
echo "Please specify the jenkins build number as an argument: "$0" <build_number>"
exit
fi
echo "Restarting tomcat ..."
TOMCAT_PID=`ps -ef | grep tomcat | grep java | awk ' { print $2 } '`
if [ $TOMCAT_PID ]
then
echo "Tomcat is running with PID" $TOMCAT_PID
echo "Forced tomcat stop with PID" $TOMCAT_PID
kill -9 $TOMCAT_PID
echo "Tomcat was stoped"
fi
echo "Starting tomcat"
TOMCAT_STARTUP_FILE=`locate apache-tomcat | grep apache-tomcat | grep startup.sh | awk ' { print $1 } '`
$TOMCAT_STARTUP_FILE
TOMCAT_PID=`ps -ef | grep tomcat | grep java | awk ' { print $2 } '`
if [ $TOMCAT_PID ]
then
echo "Tomcat is running with PID" $TOMCAT_PID
else
echo "Failed to start tomcat."
fi
When running the build, the result is as follows:
Restarting tomcat ...
Tomcat PID 10152
Tomcat is running with PID 10152
Forced tomcat stop with PID 10152
Tomcat was stoped
Starting tomcat
Tomcat started.
Tomcat is running with PID 14781
The problem is then when I am looking at the linux machine tomcat is no running, and the is nothing in the logs, so I can't figure it out what I am doing wrong. Can you please give me some suggestions?
Thank you

I managed to find a solution for this. Jenkins manipulate the environment variable called BUILD_ID. so before restarting tomcat the following line of code is needed.
export BUILD_ID=dontKillMe

Related

Spring microservice on docker jdk alpine 8 with BusyBox message

I tried to run Spring Cloud microservice on jdk alpine image of docker, but during run of two containers I received the following message:
licensingservice_1 | BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.
licensingservice_1 |
licensingservice_1 | Usage: basename FILE [SUFFIX]
licensingservice_1 |
licensingservice_1 | Strip directory path and .SUFFIX from FILE
licensingservice_1 | usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-O length]
licensingservice_1 | [-P proxy_username] [-p source_port] [-q seconds] [-s source]
licensingservice_1 | [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]
licensingservice_1 | [-x proxy_address[:port]] [destination] [port]
Here is a docker file and run.sh file that are used to build image.
DockerFile
FROM openjdk:8-jdk-alpine
RUN apk update && apk upgrade && apk add netcat-openbsd
RUN mkdir -p /usr/local/licensingservice
ADD #project.build.finalName#.jar /usr/local/licensingservice/
ADD run.sh run.sh
RUN chmod +x run.sh
CMD ./run.sh
run.sh
#!/bin/sh
getPort() {
echo $1 | cut -d : -f 3 | xargs basename
}
echo "********************************************************"
echo "Waiting for the eureka server to start on port $(getPort $EUREKASERVER_PORT)"
echo "********************************************************"
while ! `nc -z eurekaserver $(getPort $EUREKASERVER_PORT)`; do sleep 3; done
echo "******* Eureka Server has started"
echo "********************************************************"
echo "Waiting for the configuration server to start on port $(getPort $CONFIGSERVER_PORT)"
echo "********************************************************"
while ! `nc -z configserver $(getPort $CONFIGSERVER_PORT)`; do sleep 3; done
echo "******* Configuration Server has started"
echo "********************************************************"
echo "Waiting for the kafka server to start on port $(getPort $KAFKASERVER_PORT)"
echo "********************************************************"
while ! `nc -z kafkaserver $(getPort $KAFKASERVER_PORT)`; do sleep 10; done
echo "******* Kafka Server has started"
echo "********************************************************"
echo "Starting License Server with Configuration Service via Eureka : $EUREKASERVER_URI:$SERVER_PORT"
echo "Using Kafka Server: $KAFKASERVER_URI"
echo "Using ZK Server: $ZKSERVER_URI"
echo "USing Profile: $PROFILE"
echo "********************************************************"
java -Djava.security.egd=file:/dev/./urandom -Dserver.port=$SERVER_PORT \
-Deureka.client.serviceUrl.defaultZone=$EUREKASERVER_URI \
-Dspring.cloud.config.uri=$CONFIGSERVER_URI \
-Dspring.cloud.stream.kafka.binder.zkNodes=$KAFKASERVER_URI \
-Dspring.cloud.stream.kafka.binder.brokers=$ZKSERVER_URI \
-Dsecurity.oauth2.resource.userInfoUri=$AUTHSERVER_URI \
-Dspring.profiles.active=$PROFILE -jar /usr/local/licensingservice/#project.build.finalName#.jar
I've built the image with mvn clean package docker:build command with spotify docker plugin 1.2.0

Java network application run as service losing network connection

Well as in title. I have Java network application which is running on raspberry pi 3. When i run application from console like java -jar myApp.java or sudo nohup java -jar myApp.java and then i leave this it works fine for many hours.
Then I tried run this application as a service. After configure wlan auto, and run systmd script and all stuff. Application is starting properly, but after few seconds it's losing network connection. I can add that there is wifi connection. I was wandering whats the difference between application run manually and run as service and i did't find anything specific. Is there something i should know about? As far i did't find solution.
I've tired many combinations of systemd scripts but nothing solves my problem. And I also tried to run this app from another on raspberry, but it works like running from this service.
Now i can add that, when i hit from console systemctl stop myService and then systemctl start myService it also works fine.
systemd script below:
[Unit]
Description = Java Service
After network.target = MyService.service
[Service]
Type = forking
ExecStart = /usr/local/bin/MyService.sh start
ExecStop = /usr/local/bin/MyService.sh stop
ExecReload = /usr/local/bin/MyService.sh reload
[Install]
WantedBy=multi-user.target
Bash script to run the service:
#!/bin/bash
SERVICE_NAME=app
PATH_TO_JAR=/home/user/app.jar
RE='^[0-9]+$'
APP_PID=\`ps -ef | grep -v grep | grep "app.jar" | awk '{print $2}'\`
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if ! [[ $APP_PID =~ $RE ]]; then
nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null &
APP_PID=`ps -ef | grep -v grep | grep "app.jar" | awk '{print $2}'`
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
;;
stop)
if [[ $APP_PID =~ $RE ]]; then
echo "$SERVICE_NAME stoping ..." &
kill $APP_PID &
APP_PID="" &
echo "$SERVICE_NAME stopped ..."
else
echo "$SERVICE_NAME is not running ..."
fi
;;
restart)
if [[ $APP_PID =~ $RE ]]; then
echo "$SERVICE_NAME stopping ...";
kill $APP_PID;
echo "$SERVICE_NAME stopped ...";
echo "$SERVICE_NAME starting ..."
nohup java -jar $PATH_TO_JAR /tmp 2>> >> /dev/null &
echo "$SERVICE_NAME started ..."
else
echo "$SE`enter code here`RVICE_NAME is not running ..."
fi
;;
esac
I found solution. I don't know exactly what is the reason, but when i give sleep before run this application it works properly. When I start application after this this time, after which it was losing connetion it work fine.

Check and run/restart processes, bash [duplicate]

This question already has answers here:
Linux Script to check if process is running and act on the result
(8 answers)
Closed 5 years ago.
I wrote a bash-script to check if a process is running. It doesn't work since the ps command always returns exit code 1. When I run the ps command from the command-line, the $? is correctly set, but within the script it is always 1. Any idea?
#!/bin/bash
SERVICE=$1
ps -a | grep -v grep | grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
echo "`date`: $SERVICE service running, everything is fine"
else
echo "`date`: $SERVICE is not running"
fi
Bash version: GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
There are a few really simple methods:
pgrep procname && echo Running
pgrep procname || echo Not running
killall -q -0 procname && echo Running
pidof procname && echo Running
This trick works for me. Hope this could help you. Let's save the followings as checkRunningProcess.sh
#!/bin/bash
ps_out=`ps -ef | grep $1 | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" != "" ]];then
echo "Running"
else
echo "Not Running"
fi
Make the checkRunningProcess.sh executable.And then use it.
Example to use.
20:10 $ checkRunningProcess.sh proxy.py
Running
20:12 $ checkRunningProcess.sh abcdef
Not Running
I tried your version on BASH version 3.2.29, worked fine. However, you could do something like the above suggested, an example here:
#!/bin/sh
SERVICE="$1"
RESULT=`ps -ef | grep $1 | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" != "" ]];then
echo "Running"
else
echo "Not Running"
fi
I use this one to check every 10 seconds process is running and start if not and allows multiple arguments:
#!/bin/sh
PROCESS="$1"
PROCANDARGS=$*
while :
do
RESULT=`pgrep ${PROCESS}`
if [ "${RESULT:-null}" = null ]; then
echo "${PROCESS} not running, starting "$PROCANDARGS
$PROCANDARGS &
else
echo "running"
fi
sleep 10
done
Check if your scripts name doesn't contain $SERVICE. If it does, it will be shown in ps results, causing script to always think that service is running. You can grep it against current filename like this:
#!/bin/sh
SERVICE=$1
if ps ax | grep -v grep | grep -v $0 | grep $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
echo "$SERVICE is not running"
fi
Working one.
!/bin/bash
CHECK=$0
SERVICE=$1
DATE=`date`
OUTPUT=$(ps aux | grep -v grep | grep -v $CHECK |grep $1)
echo $OUTPUT
if [ "${#OUTPUT}" -gt 0 ] ;
then echo "$DATE: $SERVICE service running, everything is fine"
else echo "$DATE: $SERVICE is not running"
fi
Despite some success with the /dev/null approach in bash. When I pushed the solution to cron it failed. Checking the size of a returned command worked perfectly though. The ampersrand allows bash to exit.
#!/bin/bash
SERVICE=/path/to/my/service
result=$(ps ax|grep -v grep|grep $SERVICE)
echo ${#result}
if ${#result}> 0
then
echo " Working!"
else
echo "Not Working.....Restarting"
/usr/bin/xvfb-run -a /opt/python27/bin/python2.7 SERVICE &
fi
#!/bin/bash
ps axho comm| grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
echo "`date`: $SERVICE service running, everything is fine"
else
echo "`date`: $SERVICE is not running"
/etc/init.d/$1 restart
fi
Something like this
Those are helpful hints. I just needed to know if a service was running when I started the script, so I could leave the service in the same state when I left. I ended up using this:
HTTPDSERVICE=$(ps -A | grep httpd | head -1)
[ -z "$HTTPDSERVICE" ] && echo "No apache service running."
I found the problem. ps -ae instead ps -a works.
I guess it has to do with my rights in the shared hosting environment. There's apparently a difference between executing "ps -a" from the command line and executing it from within a bash-script.
A simple script version of one of Andor's above suggestions:
!/bin/bash
pgrep $1 && echo Running
If the above script is called test.sh then, in order to test, type:
test.sh NameOfProcessToCheck
e.g.
test.sh php
I was wondering if it would be a good idea to have progressive attempts at a process, so you pass this func a process name func_terminate_process "firefox" and it tires things more nicely first, then moves on to kill.
# -- NICE: try to use killall to stop process(s)
killall ${1} > /dev/null 2>&1 ;sleep 10
# -- if we do not see the process, just end the function
pgrep ${1} > /dev/null 2>&1 || return
# -- UGLY: Step trough every pid and use kill -9 on them individually
for PID in $(pidof ${1}) ;do
echo "Terminating Process: [${1}], PID [${PID}]"
kill -9 ${PID} ;sleep 10
# -- NASTY: If kill -9 fails, try SIGTERM on PID
if ps -p ${PID} > /dev/null ;then
echo "${PID} is still running, forcefully terminating with SIGTERM"
kill -SIGTERM ${PID} ;sleep 10
fi
done
# -- If after all that, we still see the process, report that to the screen.
pgrep ${1} > /dev/null 2>&1 && echo "Error, unable to terminate all or any of [${1}]" || echo "Terminate process [${1}] : SUCCESSFUL"
I need to do this from time to time and end up hacking the command line until it works.
For example, here I want to see if I have any SSH connections, (the 8th column returned by "ps" is the running "path-to-procname" and is filtered by "awk":
ps | awk -e '{ print $8 }' | grep ssh | sed -e 's/.*\///g'
Then I put it in a shell-script, ("eval"-ing the command line inside of backticks), like this:
#!/bin/bash
VNC_STRING=`ps | awk -e '{ print $8 }' | grep vnc | sed -e 's/.*\///g'`
if [ ! -z "$VNC_STRING" ]; then
echo "The VNC STRING is not empty, therefore your process is running."
fi
The "sed" part trims the path to the exact token and might not be necessary for your needs.
Here's my example I used to get your answer. I wrote it to automatically create 2 SSH tunnels and launch a VNC client for each.
I run it from my Cygwin shell to do admin to my backend from my windows workstation, so I can jump to UNIX/LINUX-land with one command, (this also assumes the client rsa keys have already been "ssh-copy-id"-ed and are known to the remote host).
It's idempotent in that each proc/command only fires when their $VAR eval's to an empty string.
It appends " | wc -l" to store the number of running procs that match, (i.e., number of lines found), instead of proc-name for each $VAR to suit my needs. I keep the "echo" statements so I can re-run and diagnose the state of both connections.
#!/bin/bash
SSH_COUNT=`eval ps | awk -e '{ print $8 }' | grep ssh | sed -e 's/.*\///g' | wc -l`
VNC_COUNT=`eval ps | awk -e '{ print $8 }' | grep vnc | sed -e 's/.*\///g' | wc -l`
if [ $SSH_COUNT = "2" ]; then
echo "There are already 2 SSH tunnels."
elif [ $SSH_COUNT = "1" ]; then
echo "There is only 1 SSH tunnel."
elif [ $SSH_COUNT = "0" ]; then
echo "connecting 2 SSH tunnels."
ssh -L 5901:localhost:5901 -f -l USER1 HOST1 sleep 10;
ssh -L 5904:localhost:5904 -f -l USER2 HOST2 sleep 10;
fi
if [ $VNC_COUNT = "2" ]; then
echo "There are already 2 VNC sessions."
elif [ $VNC_COUNT = "1" ]; then
echo "There is only 1 VNC session."
elif [ $VNC_COUNT = "0" ]; then
echo "launching 2 vnc sessions."
vncviewer.exe localhost:1 &
vncviewer.exe localhost:4 &
fi
This is very perl-like to me and possibly more unix utils than true shell scripting. I know there are lots of "MAGIC" numbers and cheezy hard-coded values but it works, (I think I'm also in poor taste for using so much UPPERCASE too). Flexibility can be added with some cmd-line args to make this more versatile but I wanted to share what worked for me. Please improve and share. Cheers.
A solution with service and awk that takes in a comma-delimited list of service names.
First it's probably a good bet you'll need root privileges to do what you want. If you don't need to check then you can remove that part.
#!/usr/bin/env bash
# First parameter is a comma-delimited string of service names i.e. service1,service2,service3
SERVICES=$1
ALL_SERVICES_STARTED=true
if [ $EUID -ne 0 ]; then
if [ "$(id -u)" != "0" ]; then
echo "root privileges are required" 1>&2
exit 1
fi
exit 1
fi
for service in ${SERVICES//,/ }
do
STATUS=$(service ${service} status | awk '{print $2}')
if [ "${STATUS}" != "started" ]; then
echo "${service} not started"
ALL_SERVICES_STARTED=false
fi
done
if ${ALL_SERVICES_STARTED} ; then
echo "All services started"
exit 0
else
echo "Check Failed"
exit 1
fi
The most simple check by process name :
bash -c 'checkproc ssh.exe ; while [ $? -eq 0 ] ; do echo "proc running";sleep 10; checkproc ssh.exe; done'

Check if jar running from shell

I have a java jar program that I am trying to run on startup of my machine. Ideally, the shells script will check every 60 seconds to assure that the jar is running. How do I check if the jar is running on centos, this does not appear to be working?
My current .sh file:
#!/bin/bash
while [ true ]
do
cnt=`ps -eaflc --sort stime | grep /home/Portal.jar |grep -v grep | wc -l`
if(test $cnt -eq 3);
then
echo "Service already running..."
else
echo "Starting Service"
java -jar /home/Portal.jar >> /dev/null &
fi
sleep 1m
done
I used this for referencing so far.
Depending on what your program does, there may be more or less intelligent ways to check it. For example, if you have some server, it will listen on a port.
Then something like
netstat -an | fgrep tcp | fgrep LISTEN | fgrep :87654 # or whatever your port is
could do the job.
Then there is lsof, which could also detect listening ports.
Finally, you could connect and issue a pseudo request. For example, for a http server, you could use lynx or curl. For a server with a non-stamdard protocol, you can write a small client program whose sole purpose is to connect to the server just to see if it is there.
Store your process id in file and check for this process.
#!/bin/bash
while [ true ]
do
pid=$(cat /tmp/portal.pid)
if [[ -n "$pid" && $(ps -p $pid | wc -l) -eq 2 ]]
then
echo "Service already running..."
else
echo "Starting Service"
java -jar /home/Portal.jar >> /dev/null &
echo $! > /tmp/portal.pid
fi
sleep 1m
done
/tmp will be cleared on restart, all right in this case.
I did the very same scenario a couple of months ago. My task was to ensure a jar distributed java program to run 24/7 on a Linux server.
My program was console-based, started, did something then stopped.
I did a shell script that started, waited to end and then re-started the app in an infinite loop.
I installed runit, created a service and supplied this script as the run script. Works very well.
In general, the shell script ensures that the java program is running and runit ensures that the start script (which is our script) is running.
You find valuable info here: http://smarden.org/runit/faq.html
Rather than putting the process to sleep , I'd rather have it exit and use crontab to run the process every 1 min;which will check if its running or else just stop the script.
#!/bin/sh
declare -a devId=( "/Path/To/TestJar.jar Test1" "/Path/To/TestJar.jar Test2" ) #jarfile with pathname and Test as argument
# get length of an array
arraylength=${#devId[#]}
# use for loop to read all values and indexes
for (( i=1; i<${arraylength}+1; i++ ));
do
y=${devId[$i-1]}
cnt=`ps -eaflc --sort stime | grep "$y" |grep -v grep | wc -l`
if [ $cnt = 0 ]
then
java -jar $y& > /dev/null
b=$(basename $y)
echo $b
#DO SOME OPERATION LIKE SEND AN EMAIL OR ADD TO LOG FILE
continue
elif [ $cnt != 0 ]
then
echo 'do nothing'
fi
done
Why do you think $cnt should be equal to 3? Shouldn't it be equal to 1 if the process is already running?
You could use the jps command. It return the JVMs running in the system.
I created following script to monitor my application jar is running or not.
In this case My application jar is running on port 8080
#!/bin/bash
check=$(netstat -an | grep 8080 | wc -l)
if [[ $check -eq 0 ]];then
echo "jar is not running..."
/usr/bin/java -jar /path/to/target/application.jar >> /dev/null &
else
echo "it is running"
fi
I am using cronjob to monitor jar app by executing shell script on every minute.
$ crontab -e
in the end of file
* * * * * /bin/bash monitor-jar.sh /dev/null 2>&1

Jboss 7.1.1 start/stop script

Could someone tell how to start/stop the Jboss-7.1.1 server in MAC using Shell Script.
stop_viewer(){
echo "********* Stopping JBoss Server by killing the process **********";
ps | grep domain.sh | grep -v grep | awk '{print $1}' | xargs kill
ps | grep java | grep -v grep | awk '{print $1}' | xargs kill
ps -ef | grep superuser | grep java | grep -v grep | awk '{print $2}'| xargs kill
echo "********* Stopped JBoss Server by killing the process **********";
}
The above script is working fine in Jboss-7.0.2 to stop the server. But in Jboss-7.1.1, it doesn't stop the server. Please someone help to solve this.
1) First you need to have JBoss downloaded. (I assume you already have valid Java version installed).
2) Once it is downloaded, unzip the folder:
cd /Users/eugene/Downloads
mkdir JBOSS-7
cp /Users/eugene/Downloads/jboss-as-7.1.1.Final.zip /Users/eugene/Downloads/JBOSS-7
cd /Users/eugene/Downloads/JBOSS-7
unzip /Users/eugene/Downloads/jboss-as-7.1.1.Final.zip
3)
cd Users/eugene/Downloads/JBOSS-7/jboss-as-7.1.1.Final/bin
./standalone.sh
If you want to stop it:
ctrl + c
of course your path may be different. If you want to run it in background, then just do:
./standalone.sh &
Stopping it :
ps -ef | grep jboss
You will get an output close to this one:
eugene#eugenes-MacBook-Pro ~/D/J/j/bin> ps -ef | grep jboss
501 1471 1446 0 1:32AM ttys000 0:03.31 /usr/....
And then issue:
kill -9 1471
Finally with JBoss CLI you can execute:
./jboss-cli.sh --connect ":shutdown"
EDIT
The Script seems to do it's job, all you have to do is edit it a bit:
#!/bin/sh
echo "********* Stopping JBoss Server by killing the process **********";
ps -e | grep jboss | grep -v grep | awk '{print $1}' | xargs kill
echo "********* Stopped JBoss Server by killing the process **********";
Notice that I removed a few lines and changed java with jboss
Put this in a file called stopJboss.sh
Then :
sudo chmod +x stopJBoss.sh
Then invoke it when needed:
./stopJBoss.sh
This will work only if you have a single instance of JBoss running, for more you will need a different script.
P.S. I am not a guru in scripting but here is what this line does:
ps -e | grep jboss | grep -v grep | awk '{print $1}' | xargs kill
It is going to look for every process that contains the jboss keyword. But it also going to output the grep command itself, thus you will get an output of two commands, but you need only the first one.
You could run ps -e | grep jboss and see that the output contains two lines and not one.
That is why you invoke grep -v grep - which means : in those two lines found grep for "grep" but invert the result, in this way you omit the second unneeded result.
Then awk '{print $1}' splits the string into tokens and takes the first one, which is the PID that you need and then you pass this PID to the kill command using the xargs command.
To shutdown the server via command line
sh ./bin/jboss-cli.sh --connect command=:shutdown
assuming you are running on localhost and using the default native management port i.e. 9999
if not you need to specify the IP (jboss.bind.address) and the native management port(jboss.management.native.port) configured in standalone.xml
sh ./bin/jboss-cli.sh --connect controller=<IP>:<native-mgmt-port> command=:shutdown
This is how I do it:
ps -ef | grep jboss | grep -v grep | awk '{print $2}' | xargs kill -9
I have this in a bash file that i call killjboss and it works well with me.
After dive on the Google, i managed to put this work:
#!/bin/sh
### BEGIN INIT INFO
# Provides: jboss
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop JBoss AS v7.1.1
### END INIT INFO
#
#source some script files in order to set and export environmental variables
#as well as add the appropriate executables to $PATH
export JAVA_HOME=/usr/lib/jvm/java-7-oracle
export PATH=$JAVA_HOME/bin:$PATH
export JBOSS_HOME=/home/gaspar/jboss-as-7.1.1.Final
export PATH=$JBOSS_HOME/bin:$PATH
case "$1" in
start)
echo "Starting JBoss AS 7.1.1"
#original:
#sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh
#updated:
start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh
;;
stop)
echo "Stopping JBoss AS 7.1.1"
#original:
#sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown
#updated:
sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown
;;
*)
echo "Usage: /etc/init.d/jboss {start|stop}"
exit 1
;;
esac
exit 0
:)

Categories

Resources