Hi when you start Jboss 6.1 with run.sh, you have have various informations displayed and it's the same when immediately after you press ctrl-c (i am talking about Linux ), but when i call shutdown.sh i only have this as output:
Shutdown message has been posted to the server.
Server shutdown may take a while - check logfiles for completion.
How can i get the full output ?
Here are the source of the two standard scripts
#!/bin/sh
### ====================================================================== ###
## ##
## JBoss Shutdown Script ##
## ##
### ====================================================================== ###
### $Id: shutdown.sh 109786 2010-12-08 18:26:01Z epbernard $ ###
# Extract the directory and the program name
# takes care of symlinks
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
DIRNAME=`dirname "$PRG"`
PROGNAME=`basename "$PRG"`
GREP="grep"
#
# Helper to complain.
#
die() {
echo "${PROGNAME}: $*"
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false;
case "`uname`" in
CYGWIN*)
cygwin=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$JBOSS_HOME" ] &&
JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Setup JBOSS_HOME
if [ "x$JBOSS_HOME" = "x" ]; then
JBOSS_HOME=`cd $DIRNAME/..; pwd`
fi
export JBOSS_HOME
# Setup the JVM
if [ "x$JAVA" = "x" ]; then
if [ "x$JAVA_HOME" != "x" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi
# Setup the classpath
JBOSS_BOOT_CLASSPATH="$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jbossall-client.jar"
if [ "x$JBOSS_CLASSPATH" = "x" ]; then
JBOSS_CLASSPATH="$JBOSS_BOOT_CLASSPATH"
else
JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_BOOT_CLASSPATH"
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
JBOSS_CLASSPATH=`cygpath --path --windows "$JBOSS_CLASSPATH"`
fi
# Execute the JVM
exec "$JAVA" \
$JAVA_OPTS \
-classpath $JBOSS_CLASSPATH \
org.jboss.Shutdown "$#"
#!/bin/sh
And here is the other one just to compare.
### ====================================================================== ###
## ##
## JBoss Bootstrap Script ##
## ##
### ====================================================================== ###
### $Id: run.sh 111395 2011-05-18 07:45:07Z beve $ ###
# Extract the directory and the program name
# takes care of symlinks
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
DIRNAME=`dirname "$PRG"`
PROGNAME=`basename "$PRG"`
GREP="grep"
# Use the maximum available, or set MAX_FD != -1 to use that
MAX_FD="maximum"
#
# Helper to complain.
#
warn() {
echo "${PROGNAME}: $*"
}
#
# Helper to puke.
#
die() {
warn $*
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
linux=false;
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
Linux)
linux=true
;;
esac
# Read an optional running configuration file
if [ "x$RUN_CONF" = "x" ]; then
RUN_CONF="$DIRNAME/run.conf"
fi
if [ -r "$RUN_CONF" ]; then
. "$RUN_CONF"
fi
# Force IPv4 on Linux systems since IPv6 doesn't work correctly with jdk5 and lower
if [ "$linux" = "true" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$JBOSS_HOME" ] &&
JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$JAVAC_JAR" ] &&
JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
fi
# Setup JBOSS_HOME
if [ "x$JBOSS_HOME" = "x" ]; then
# get the full path (without any relative bits)
JBOSS_HOME=`cd $DIRNAME/..; pwd`
fi
export JBOSS_HOME
# Increase the maximum file descriptors if we can
if [ "$cygwin" = "false" ]; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ "$?" -eq 0 ]; then
# Darwin does not allow RLIMIT_INFINITY on file soft limit
if [ "$darwin" = "true" -a "$MAX_FD_LIMIT" = "unlimited" ]; then
MAX_FD_LIMIT=`/usr/sbin/sysctl -n kern.maxfilesperproc`
fi
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
# use the system max
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ "$?" -ne 0 ]; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# Setup the JVM
if [ "x$JAVA" = "x" ]; then
if [ "x$JAVA_HOME" != "x" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi
# Setup the classpath
JBOSS_BOOT_CLASSPATH="$JBOSS_HOME/bin/run.jar"
if [ ! -f "$JBOSS_BOOT_CLASSPATH" ]; then
die "Missing required file: $JBOSS_BOOT_CLASSPATH"
fi
# Tomcat uses the JDT Compiler
# Only include tools.jar if someone wants to use the JDK instead.
# compatible distribution which JAVA_HOME points to
JAVAC_JAR_FILE="${JAVAC_JAR:-$JAVA_HOME/lib/tools.jar}"
if [ ! -f "$JAVAC_JAR_FILE" ]; then
# MacOSX does not have a seperate tools.jar
if [ "$darwin" != "true" -a "x$JAVAC_JAR" != "x" ]; then
warn "Missing file: JAVAC_JAR=$JAVAC_JAR"
warn "Unexpected results may occur."
fi
JAVAC_JAR_FILE=
fi
# Setup classpath
JBOSS_CLASSPATH="${JBOSS_CLASSPATH:+$JBOSS_CLASSPATH:$JBOSS_BOOT_CLASSPATH}"
JBOSS_CLASSPATH="${JBOSS_CLASSPATH:-$JBOSS_BOOT_CLASSPATH}"
JBOSS_CLASSPATH="$JBOSS_CLASSPATH${JAVAC_JAR_FILE:+:$JAVAC_JAR_FILE}"
# Check for -d32/-d64 in JAVA_OPTS
JVM_OPTVERSION="-version"
JVM_D64_OPTION=`echo $JAVA_OPTS | $GREP "\-d64"`
JVM_D32_OPTION=`echo $JAVA_OPTS | $GREP "\-d32"`
test "x$JVM_D64_OPTION" != "x" && JVM_OPTVERSION="-d64 $JVM_OPTVERSION"
test "x$JVM_D32_OPTION" != "x" && JVM_OPTVERSION="-d32 $JVM_OPTVERSION"
# If -server not set in JAVA_OPTS, set it, if supported
SERVER_SET=`echo $JAVA_OPTS | $GREP "\-server"`
if [ "x$SERVER_SET" = "x" ]; then
# Check for SUN(tm) JVM w/ HotSpot support
if [ "x$HAS_HOTSPOT" = "x" ]; then
HAS_HOTSPOT=`"$JAVA" $JVM_OPTVERSION -version 2>&1 | $GREP -i HotSpot`
fi
# Check for OpenJDK JVM w/server support
if [ "x$HAS_OPENJDK_" = "x" ]; then
HAS_OPENJDK=`"$JAVA" $JVM_OPTVERSION 2>&1 | $GREP -i OpenJDK`
fi
# Enable -server if we have Hotspot or OpenJDK, unless we can't
if [ "x$HAS_HOTSPOT" != "x" -o "x$HAS_OPENJDK" != "x" ]; then
# MacOS does not support -server flag
if [ "$darwin" != "true" ]; then
JAVA_OPTS="-server $JAVA_OPTS"
JVM_OPTVERSION="-server $JVM_OPTVERSION"
fi
fi
else
JVM_OPTVERSION="-server $JVM_OPTVERSION"
fi
# Setup JBoss specific properties
JAVA_OPTS="${JAVA_OPTS:+$JAVA_OPTS -Dprogram.name=$PROGNAME}"
JAVA_OPTS="${JAVA_OPTS:--Dprogram.name=$PROGNAME}"
JAVA_OPTS="${JAVA_OPTS:+$JAVA_OPTS -Dlogging.configuration=file:${DIRNAME}/logging.properties}"
# Setup JBoss Native library path
#
if [ -d "$JBOSS_HOME/../native/lib" ]; then
JBOSS_NATIVE_DIR=`cd "$JBOSS_HOME/../native" && pwd`
elif [ -d "$JBOSS_HOME/native/lib" ]; then
JBOSS_NATIVE_DIR=`cd "$JBOSS_HOME/native" && pwd`
elif [ -d "$JBOSS_HOME/../native/lib64" ]; then
JBOSS_NATIVE_DIR=`cd "$JBOSS_HOME/../native" && pwd`
elif [ -d "$JBOSS_HOME/native/lib64" ]; then
JBOSS_NATIVE_DIR=`cd "$JBOSS_HOME/native" && pwd`
elif [ -d "$JBOSS_HOME/native/bin" ]; then
JBOSS_NATIVE_DIR=`cd "$JBOSS_HOME/native" && pwd`
elif [ -d "$JBOSS_HOME/bin/native" ]; then
JBOSS_NATIVE_DIR=`cd "$JBOSS_HOME/bin/native" && pwd`
fi
if [ -d "$JBOSS_NATIVE_DIR" ]; then
if $cygwin; then
JBOSS_NATIVE_DIR="$JBOSS_NATIVE_DIR/bin"
export PATH="$JBOSS_NATIVE_DIR:$PATH"
JBOSS_NATIVE_LIBPATH=`cygpath --path --windows "$JBOSS_NATIVE_DIR"`
else
IS_64_BIT_JVM=`"$JAVA" $JVM_OPTVERSION 2>&1 | $GREP -i 64-bit`
if [ "x$IS_64_BIT_JVM" != "x" ]; then
JBOSS_NATIVE_DIR="$JBOSS_NATIVE_DIR/lib64"
else
JBOSS_NATIVE_DIR="$JBOSS_NATIVE_DIR/lib"
fi
LD_LIBRARY_PATH="$JBOSS_NATIVE_DIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
JBOSS_NATIVE_LIBPATH=$LD_LIBRARY_PATH
fi
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$JBOSS_NATIVE_LIBPATH"
fi
# Setup the java endorsed dirs
JBOSS_ENDORSED_DIRS="$JBOSS_HOME/lib/endorsed"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
JBOSS_CLASSPATH=`cygpath --path --windows "$JBOSS_CLASSPATH"`
JBOSS_ENDORSED_DIRS=`cygpath --path --windows "$JBOSS_ENDORSED_DIRS"`
fi
# Display our environment
echo "========================================================================="
echo ""
echo " JBoss Bootstrap Environment"
echo ""
echo " JBOSS_HOME: $JBOSS_HOME"
echo ""
echo " JAVA: $JAVA"
echo ""
echo " JAVA_OPTS: $JAVA_OPTS"
echo ""
echo " CLASSPATH: $JBOSS_CLASSPATH"
echo ""
echo "========================================================================="
echo ""
while true; do
if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
# Execute the JVM in the foreground
eval \"$JAVA\" $JAVA_OPTS \
-Djava.endorsed.dirs=\"$JBOSS_ENDORSED_DIRS\" \
-classpath \"$JBOSS_CLASSPATH\" \
org.jboss.Main "$#"
JBOSS_STATUS=$?
else
# Execute the JVM in the background
eval \"$JAVA\" $JAVA_OPTS \
-Djava.endorsed.dirs=\"$JBOSS_ENDORSED_DIRS\" \
-classpath \"$JBOSS_CLASSPATH\" \
org.jboss.Main "$#" "&"
JBOSS_PID=$!
# Trap common signals and relay them to the jboss process
trap "kill -HUP $JBOSS_PID" HUP
trap "kill -TERM $JBOSS_PID" INT
trap "kill -QUIT $JBOSS_PID" QUIT
trap "kill -PIPE $JBOSS_PID" PIPE
trap "kill -TERM $JBOSS_PID" TERM
if [ "x$JBOSS_PIDFILE" != "x" ]; then
echo $JBOSS_PID > $JBOSS_PIDFILE
fi
# Wait until the background process exits
WAIT_STATUS=128
while [ "$WAIT_STATUS" -ge 128 ]; do
wait $JBOSS_PID 2>/dev/null
WAIT_STATUS=$?
if [ "$WAIT_STATUS" -gt 128 ]; then
SIGNAL=`expr $WAIT_STATUS - 128`
SIGNAL_NAME=`kill -l $SIGNAL`
echo "*** JBossAS process ($JBOSS_PID) received $SIGNAL_NAME signal ***" >&2
fi
done
if [ "$WAIT_STATUS" -lt 127 ]; then
JBOSS_STATUS=$WAIT_STATUS
else
JBOSS_STATUS=0
fi
if [ "$JBOSS_STATUS" -ne 10 ]; then
# Wait for a complete shudown
wait $JBOSS_PID 2>/dev/null
fi
fi
# If restart doesn't work, check you are running JBossAS 4.0.4+
# http://jira.jboss.com/jira/browse/JBAS-2483
# or the following if you're running Red Hat 7.0
# http://developer.java.sun.com/developer/bugParade/bugs/4465334.html
if [ "$JBOSS_STATUS" -eq 10 ]; then
echo "Restarting JBoss..."
else
exit $JBOSS_STATUS
fi
done
The JBoss shutdown script just posts a shutdown message to the server. The log that you get when you originally started the server (log file, console etc) will continue to log info while shutting down.
The org.jboss.Shutdown class is designed to not output anything to the console. What you are seeing is all that the program will ever output. If you need more information, check the log files. And if that is not enough, consider adjusting the JBoss logging level.
You can confirm this by looking at the source code.
Note that this program doesn't do the shutdown. What it actually does is to send a request to the server to tell it to shutdown. The server takes care of the rest ... asynchronously.
Related
In jenkins maven project we can use BUILD_ID=DontKillMe to prevent hudson script shutdown the shell calls.
Like: BUILD_ID=DontKillMe java -jar target.jar
But add BUILD_ID is not work in Jenkinsfile.
Jenkinsfile:
#!/usr/bin/env groovy
node {
stage('Build') {
checkout scm
sh '/opt/gradle/gradle-4.1/bin/gradle clean build'
}
stage('Deploy') {
sh 'mkdir -p /opt/www/foobar'
sh 'cp build/libs/*.war /opt/www/foobar/newest.war'
sh 'chmod 755 ./deploy.sh'
sh 'nohup ./deploy.sh &'
sh 'while ! httping -qc1 http://localhost:10000 ; do sleep 1 ; done'
}
}
After hudson script executed, all the shells called by hudson script would be shutdown. Even double nohup still not work.
deploy.sh:
#!/bin/bash
nohup java -jar -Dspring.profiles.active=prod /opt/www/foobar/newest.war /var/log/foobar.log 2>&1 &
You can use BUILD_ID=dontKillMe in sh step the same way
sh 'BUILD_ID=dontKillMe nohup ./deploy.sh &'
I found an another way to execute scripts and cannot be killed.
Linux service
/etc/init.d/www-project
#!/bin/bash
. /etc/init.d/functions
SERVICE_NAME="www-project"
RETVAL=0
PID=-1
PIDFILE=/var/run/${SERVICE_NAME}.PID
start () {
if [ -f ${PIDFILE} ]; then
echo "PID file ${PIDFILE} already exists, please stop the service !"
exit
fi
echo "Starting service ${SERVICE_NAME} ..."
java -jar -Dspring.profiles.active=prod /opt/www/project/newest.war > /var/log/www-project.log 2>&1 &
PID = $!
if [ -z ${PID} ]; then
echo "Failed to get the process id, exit!"
exit
else
echo "Starting successfully, whose pid is ${PID}"
fi
touch $PIDFILE
echo ${PID} > ${PIDFILE}
}
stop () {
if [ -f $PIDFILE ]; then
PID = `cat ${PIDFILE}`
if [ -z $PID ]; then
echo "PIDFILE $PIDFILE is empty!"
exit
fi
if [ -z "`ps axf | grep $PID | grep -v grep`" ]; then
echo "Process dead but pidfile exists!"
exit
else
kill -9 $PID
echo "Stopping service successfully, whose pid is $PID"
rm -f $PIDFILE
fi
else
echo "File $PIDFILE does NOT exist!"
fi
}
restart () {
stop
start
}
status () {
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
if [ -z $PID ] ; then
echo "No effective pid but pidfile exists!"
else
if [ -z "`ps axf | grep $PID | grep -v grep`" ]; then
echo "Process dead but pidfile exist"
else
echo "Running"
fi
fi
else
echo "Service not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: www-project {start|stop|restart|status}"
;;
esac
systemd unit service
/usr/lib/systemd/system/www-project.service
[Unit]
Description=project
After=mysqld.service
Wants=mysqld.service
[Service]
ExecStart=/usr/lib/jvm/java/bin/java -jar -Dspring.profiles.active=prod /opt/www/project/newest.war > /var/log/www-project.log
PIDFile=/var/run/www-project.pid
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -9 $MAINPID
[Install]
WantedBy=multi-user.target
In Jenkinsfile, we can call
service restart www-project
or
systemctl restart www-project
And hudson script will never kill the services.
So I had a tomcat 7.026 smoothly running on a CentOS 6.7 Server on its default port 8080.
Recently it stopped running on its own.
Here are the out put of each:
sudo service easy-tomcat7 start
Failed to start Tomcat
sudo service easy-tomcat7 status
pidof: invalid options on command line!
pidof: invalid options on command line!
jsvc.exec is stopped
ps aux | grep tomcat
root 4293 1.4 2.3 5939868 389996 pts/0 Sl 14:16 0:14
/usr/java/jdk1.7.0_05/bin/java
-Djava.util.logging.config.file=/usr/share/apache-tomcat-7.0.26/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/share/apache-tomcat-7.0.26/endorsed -classpath /usr/share/apache-tomcat-7.0.26/bin/bootstrap.jar:/usr/share/apache-tomcat-7.0.26/bin/tomcat-juli.jar
-Dcatalina.base=/usr/share/apache-tomcat-7.0.26 -Dcatalina.home=/usr/share/apache-tomcat-7.0.26 -Djava.io.tmpdir=/usr/share/apache-tomcat-7.0.26/temp org.apache.catalina.startup.Bootstrap start
root 16821 0.0 0.0 8548 384 ? Ss 14:30 0:00
jsvc.exec -user tomcat -cwd /usr/local/easy/share/easy-tomcat7
-pidfile /var/run/easy-tomcat7.pid -cp /usr/local/easy/bin/bootstrap.jar:/usr/local/easy/bin/tomcat-juli.jar:/usr/local/easy/share/java/commons-daemon.jar
-Djava.endorsed.dirs=/usr/local/easy/share/easy-tomcat7/endorsed -outfile /var/log/easy-tomcat7/catalina.out -errfile /var/log/easy-tomcat7/catalina.err -verbose
org.apache.catalina.startup.Bootstrap start
tomcat 16823 9.4 3.5 6190668 574344 ? Sl 14:30 0:15
jsvc.exec -user tomcat -cwd /usr/local/easy/share/easy-tomcat7
-pidfile /var/run/easy-tomcat7.pid -cp /usr/local/easy/bin/bootstrap.jar:/usr/local/easy/bin/tomcat-juli.jar:/usr/local/easy/share/java/commons-daemon.jar
-Djava.endorsed.dirs=/usr/local/easy/share/easy-tomcat7/endorsed -outfile /var/log/easy-tomcat7/catalina.out -errfile /var/log/easy-tomcat7/catalina.err -verbose
org.apache.catalina.startup.Bootstrap start
Killing those processes aren't helping , as well as service start, restart, force-reload ... etc
Finally here's the script of easy-tomcat7
. /etc/rc.d/init.d/functions
case $1 in
start)
file=/usr/sbin/starttomcat
# no way to start tomcat
if [ ! -x $file ]; then
echo "Missing $file"
ERROR=1
else
# tomcat disabled by whm
if [ -e /etc/tomcatdisable ]; then
echo "Tomcat is disabled by cPanel/WHM"
ERROR=0
else
ERROR=0
status jsvc.exec &>/dev/null
# tomcat already running
if [ $? -eq 0 ]; then
echo "Tomcat already started"
# start tomcat, not running
else
$file &>/dev/null
sleep 1 # just to make sure
status jsvc.exec &>/dev/null
if [ $? -eq 0 ]; then
ERROR=0
else
echo "Failed to start Tomcat"
ERROR=1
fi
fi
fi
fi
;;
stop)
file=/usr/sbin/stoptomcat
if [ ! -x $file ]; then
echo "Missing $file"
ERROR=1
else
$file
ERROR=0
fi
;;
restart)
file=/usr/local/cpanel/scripts/restartsrv_tomcat
if [ ! -x $file ]; then
echo "Missing $file"
ERROR=1
else
$file
fi
;;
status|fullstatus)
status jsvc.exec
;;
*)
echo $"Usage: $0 {start|stop|restart|status|fullstatus}"
ERROR=2 esac
exit $ERROR
I finally resolved the issue.
After running
java -version
It seemed that the Java Installation was somehow corrupted so all I had to do was to uninstall and re-install Java and that made the trick for me.
I'm using the play-plugin (https://wiki.jenkins-ci.org/display/JENKINS/play-plugin) in jenkins to clean, compile and build the application, but when I run the application using a managed script (https://wiki.jenkins-ci.org/display/JENKINS/Managed+Script+Plugin) in jenkins, the app starts and stops immediately without any errors.
Anyone have any clue?
managed script
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========================================================================
#
#
# Check this blog post I wrote with detailed information:
# http://buransky.com/play-framework/init-d-shell-script-for-play-framework-distributed-application/
#
#
# Script to start, stop and check status of a Play framework application. It requires
# the Play application to be packaged using the "dist" command. Before you run the script,
# you have to set values of NAME, PORT and APP_DIR variables.
#
# NAME – name of the application, must be the same as the name of shell script
# generated by Play framework to run the app
# PORT – port number at which the app should run
# APP_DIR – path to directory where you have unzipped the packaged app
#
#
# Usage: control.sh {start|stop|status|restart}
# port - requred for start and restart commands
#
# Example: control.sh restart app-name 9000
#
#
# The script uses RUNNING_PID file generated by Play framework which contains ID of the
# application server process.
#
#
# START YOUR APPLICATION WHEN MACHINE STARTS
# ==========================================
#
# The script uses RUNNING_PID file generated by Play framework which contains ID of
# the application server process.
#
#
# SAFE START
# ==========
#
# After starting the application the script checks whether the RUNNING_PID file has
# been created and whether the process is really running. After that it uses wget
# utility to issue an HTTP GET request for root document to do yet another check
# whether the server is alive. Of course this assumes that your application serves
# this document. If you don’t like (or have) wget I have provided curl version for
# your convenience as well.
#
#
# SAFE STOP
# =========
#
# Stop checks whether the process whose ID is in the RUNNING_PID file really belongs
# to your application. This is an important check so that we don’t kill an innocent
# process by accident. Then it sends termination signals to the process starting
# with the most gentle ones until the process dies.
#
#
# Script arguments (start, stop, restart or status)
COMMAND=$1
# ***********************************************
# ************* Set these variables ***********
NAME=Name
PORT=9001
APP_DIR=PATH
# ***********************************************
# ***********************************************
# Additional arguments to be passed to the Play application
APP_ARGS=-Dhttp.port=${PORT}
# Path to the RUNNING_PID file containing process ID
PID_FILE=$APP_DIR/RUNNING_PID
# Helper functions
echoProgress()
{
setColor 6
printf "%-70s" "$1..."
resetColor
return 0
}
echoError()
{
setColor 6
#printf "ERROR"
if [ ! -z "$1" ]
then
resetColor
#printf " [$1]"
fi
printf "\n"
resetColor
return 0
}
echoOK()
{
setColor 2
printf "OK"
if [ ! -z "$1" ]
then
resetColor
printf " [$1]"
fi
printf "\n"
resetColor
return 0
}
checkResult()
{
if [ "$1" -ne 0 ]
then
echoError "$2"
exit 1
fi
}
setColor()
{
tput setaf $1 2>/dev/null
}
resetColor()
{
tput sgr0 2>/dev/null
}
# Checks if RUNNING_PID file exists and whether the process is really running.
checkPidFile()
{
if [ -f $PID_FILE ]
then
if ps -p `cat $PID_FILE` > /dev/null
then
# The file exists and the process is running
return 1
else
# The file exitsts, but the process is dead
return 2
fi
fi
# The file doesn't exist
return 0
}
# Gently kill the given process
kill_softly()
{
SAFE_CHECK=`ps $# | grep [-]Duser.dir=$APP_DIR`
if [ -z "$SAFE_CHECK" ]
then
# Process ID doesn't belong to expected application! Don't kill it!
return 1
else
# Send termination signals one by one
for sig in TERM HUP INT QUIT PIPE KILL; do
if ! kill -$sig "$#" > /dev/null 2>&1 ;
then
break
fi
sleep 2
done
fi
}
# Get process ID from RUNNING_PID file and print it
printPid()
{
PID=`cat $PID_FILE`
printf "PID=$PID"
}
# Check port input argument
checkPort()
{
if [ -z "$PORT" ]
then
echoError "Port not set!"
return 1
fi
}
# Check input arguments
checkArgs()
{
# Check command
case "$COMMAND" in
start | stop | restart | status) ;;
*)
echoError "Unknown command"
return 1
;;
esac
# Check application name
if [ -z "$NAME" ]
then
echoError "Application name not set!"
return 1
fi
# Check application directory
if [ -z "$APP_DIR" ]
then
echoError "Application installation directory not set!"
return 1
fi
# Check port
case "$COMMAND" in
start | restart)
checkPort
if [ $? != 0 ]
then
return 1
fi
;;
esac
}
checkAppStarted()
{
# Wait a bit
sleep 3
# Check if RUNNING_PID file exists and if process is really running
checkPidFile
if [ $? != 1 ]
then
echoError
cat $TMP_LOG 1>&2
exit 1
fi
local HTTP_RESPONSE_CODE
# Issue HTTP GET request using wget to check if the app is really started. Of course this
# command assumes that your server supports GET for the root URL.
HTTP_RESPONSE_CODE=`wget -SO- "http://localhost:$PORT/" 2>&1 | grep "HTTP/" | awk '{print $2}'`
# The same functionality but using curl. For your convenience.
#HTTP_RESPONSE_CODE=`curl --connect-timeout 20 --retry 3 -o /dev/null --silent --write-out "%{http_code}" http://localhost:$PORT/`
checkResult $? "no response from server, timeout"
if [ $HTTP_RESPONSE_CODE != 200 ]
then
echoError "HTTP GET / = $HTTP_RESPONSE_CODE"
exit 1
fi
}
# Check input arguments
checkArgs
if [ $? != 0 ]
then
echo "Usage: $0 {start|stop|status|restart}"
exit 1
fi
case "${COMMAND}" in
start)
echoProgress "Starting $NAME at port $PORT"
checkPidFile
case $? in
1) echoOK "$(printPid) already started"
exit ;;
2) # Delete the RUNNING_PID FILE
rm $PID_FILE ;;
esac
SCRIPT_TO_RUN=$APP_DIR/bin/$NAME
if [ ! -f $SCRIPT_TO_RUN ]
then
echoError "Play script doesn't exist!"
exit 1
fi
# * * * Run the Play application * * *
TMP_LOG=`mktemp`
PID=`$SCRIPT_TO_RUN $APP_ARGS > /dev/null 2>$TMP_LOG & echo $!`
# Check if successfully started
if [ $? != 0 ]
then
echoError
exit 1
else
checkAppStarted
echoOK "PID=$PID"
fi
;;
status)
echoProgress "Checking $NAME at port $PORT"
checkPidFile
case $? in
0) echoOK "not running" ;;
1) echoOK "$(printPid) running" ;;
2) echoError "process dead but RUNNING_PID file exists" ;;
esac
;;
stop)
echoProgress "Stopping $NAME"
checkPidFile
case $? in
0) echoOK "wasn't running" ;;
1) PRINTED_PID=$(printPid)
kill_softly `cat $PID_FILE`
if [ $? != 0 ]
then
echoError "$PRINTED_PID doesn't belong to $NAME! Human intervention is required."
exit 1
else
echoOK "$PRINTED_PID stopped"
fi ;;
2) echoError "RUNNING_PID exists but process is already dead" ;;
esac
;;
restart)
$0 stop $NAME $PORT
if [ $? == 0 ]
then
$0 start $NAME $PORT
if [ $? == 0 ]
then
# Success
exit
fi
fi
exit 1
;;
esac
Turns out jenkins build process kills ANY child process it creates (https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller).
So to resolve this issue I had to add
export BUILD_ID=dontKillMe
to the process(shell script) that I wanted to continue running.
Not without seeing a setup, command or some log files. This is not a direct answer, but have you considered using Maven to run the app? This works for akka apps:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.yourapp.Hello</mainClass>
</configuration>
</plugin>
Edit to answer further comments: Native packager info
A sample build.sbt could look like this:
import com.typesafe.sbt.packager.archetypes.ServerLoader.SystemV
scalaVersion := "2.11.7"
val timestamp: Long = System.currentTimeMillis / 1000
name := """my-app"""
maintainer := "Me Me <me#me.io>"
packageName := """my-app"""
packageDescription := "My business logic."
packageSummary := "Test app."
version := s"1.0.0"
name in Universal := name.value
name in UniversalDocs <<= name in Universal
name in UniversalSrc <<= name in Universal
packageName in Universal := packageName.value
serverLoading in Debian := SystemV
...blah
fork in run := true
publishArtifact in(Compile, packageDoc) := false
publishArtifact in packageDoc := false
sources in(Compile, doc) := Seq.empty
enablePlugins {
DebianPlugin
JavaServerAppPackaging
}
And this would help you create a native Debian package with sbt debian:packageBin which can be controlled on the machine (once installed) with service <servicename> start|stop|restart
I have a Java application running on JBoss EAP 6 which I can "hit" from mobile app on chrome using urls like: 127.0.0.1:8280/myAwesomeJavaApp/coolService ... so when I package the app I am using urls like this
192.168.1.64:8280/myAwesomeJavaApp/coolService //this is not working
192.168.1.64 // this gets me to my localhost
(connected to WiFi (testing purposes))
I can access all other Apache web apps in my localhost , but can't consume JBoss EAP 6 services.
What am I missing ?
Start Jboss server with -b 0.0.0.0
./standalone.sh -b.0.0.0.0
How to share jboss over network
I am using service script:
JBOSS_HOST_CONFIG=host-master.xml
JBOSS_BIND_IP=0.0.0.0
JBOSS_NODE_NAME=master
JBOSS_USER=root
JBOSS_HOME=/opt/jboss-eap-6.4
#!/bin/sh
#
# JBoss domain control script
#
# chkconfig: - 80 20
# description: JBoss AS Domain
# processname: domain
# pidfile: /var/run/jboss-as/jboss-as-domain.pid
# config: /etc/jboss-as/jboss-as.conf
# Source function library.
#. /etc/init.d/functions
# Load Java configuration.
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME
# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi
[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"
# Set defaults.
if [ -z "$JBOSS_HOME" ]; then
JBOSS_HOME=/usr/share/jboss-as
fi
export JBOSS_HOME
if [ -z "$JBOSS_PIDFILE" ]; then
JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-domain.pid
fi
export JBOSS_PIDFILE
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log
fi
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=60
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
if [ -z "$JBOSS_DOMAIN_CONFIG" ]; then
JBOSS_DOMAIN_CONFIG=domain.xml
fi
if [ -z "$JBOSS_HOST_CONFIG" ]; then
JBOSS_HOST_CONFIG=host.xml
fi
if [ -z "$JBOSS_BIND_IP" ]; then
JBOSS_BIND_IP=
fi
if [ -z "$JBOSS_NODE_NAME" ]; then
JBOSS_NODE_NAME=
fi
JBOSS_SCRIPT=$JBOSS_HOME/bin/domain.sh
prog='jboss-as'
CMD_PREFIX=''
if [ ! -z "$JBOSS_USER" ]; then
if [ -x /etc/rc.d/init.d/functions ]; then
CMD_PREFIX="daemon --user $JBOSS_USER"
else
CMD_PREFIX="su - $JBOSS_USER -c"
fi
fi
start() {
echo -n "Starting $prog: "
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo -n "$prog is already running"
echo 'failure!'
return 1
else
rm -f $JBOSS_PIDFILE
fi
fi
mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
cat /dev/null > $JBOSS_CONSOLE_LOG
mkdir -p $(dirname $JBOSS_PIDFILE)
chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &
if [ ! -z "$JBOSS_USER" ]; then
if [ -r /etc/rc.d/init.d/functions ]; then
daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -b $JBOSS_BIND_IP -Djbos.node.name=$JBOSS_NODE_NAME --domain-config=$JBOSS_DOMAIN_CONFIG --host-config=$JBOSS_HOST_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &
else
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -b $JBOSS_BIND_IP -Djbos.node.name=$JBOSS_NODE_NAME --domain-config=$JBOSS_DOMAIN_CONFIG --host-config=$JBOSS_HOST_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &
fi
fi
count=0
launched=false
until [ $count -gt $STARTUP_WAIT ]
do
grep 'JBAS015874:' $JBOSS_CONSOLE_LOG > /dev/null
if [ $? -eq 0 ] ; then
launched=true
break
fi
sleep 1
count=$(($count+1))
done
if [ "$launched" = "false" ] ; then
echo "$prog failed to startup in the time allotted"
echo 'failure!'
return 7
fi
echo 'successfuly done!'
return 0
}
stop() {
echo -n $"Stopping $prog: "
count=0;
if [ -f $JBOSS_PIDFILE ]; then
read kpid < $JBOSS_PIDFILE
let kwait=$SHUTDOWN_WAIT
# Try issuing SIGTERM
kill -15 $kpid
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
kill -9 $kpid
fi
fi
rm -f $JBOSS_PIDFILE
echo 'successfuly done!'
echo
}
status() {
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo "$prog is running (pid $ppid)"
return 0
else
echo "$prog dead but pid file exists"
return 1
fi
fi
echo "$prog is not running"
return 3
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
status)
status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status|restart|reload}"
exit 1
;;
esac
and start with:
/etc/init.d/jbosseap6 start
I have below shell script to stop/stop the tomcat.
#!/bin/bash
export BASE=/home/programs/jakarta-tomcat-5.0.28/bin
prog=jakarta-tomcat-5.0.28
stat() {
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
echo Tomcat is running.
else
echo Tomcat is not running.
fi
}
case "$1" in
start)
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
echo Tomcat seems to be running. Use the restart option.
else
$BASE/startup.sh 2>&1 > /dev/null
fi
stat
;;
stop)
$BASE/shutdown.sh 2>&1 > /dev/null
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
for pid in `ps auxwww|grep $prog|grep -v grep|tr -s ' '|cut -d ' ' -f2`
do
kill -9 $pid 2>&1 > /dev/null
done
fi
stat
;;
restart)
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
for pid in `ps auxwww|grep $prog|grep -v grep|tr -s ' '|cut -d ' ' -f2`
do
kill -9 $pid 2>&1 > /dev/null
done
fi
$BASE/startup.sh 2>&1 > /dev/null
stat
;;
status)
stat
;;
*)
echo "Usage: tomcat start|stop|restart|status"
esac
Now above script works with local tomcat. Now how can i modify above script to stop/start remote tomcat?
Thanks!
You could use ssh to execute a local script on the remote machine to start/stop Tomcat, so if you are in a linux terminal, you could do something like:
ssh username#remoteMachine /home/username/myScipts/start_tomcat.sh
where start_tomcat.sh would be a script in the remote machine, of course you would need a valid username/password on the remote machine, and also the remote machine would need to have sshd installed and running