Skip to content

Instantly share code, notes, and snippets.

@abregar
Forked from stuart-warren/jboss711.spec
Created January 3, 2017 13:21
Show Gist options
  • Save abregar/559dfa1f4c47b230fa55b59db579324e to your computer and use it in GitHub Desktop.
Save abregar/559dfa1f4c47b230fa55b59db579324e to your computer and use it in GitHub Desktop.
Jboss AS 7.11 RPM spec file (used with OpenShift on CentOS 6.5) - based on http://silverdire.com/2012/05/29/jboss-7-1-1-spec-file-for-rpm-builds/
%define jboss_version_full 7.1.1
Summary: JBoss Application Server
Name: jboss
Version: 7.1.1
Release: 5
License: LGPL
BuildArch: x86_64
Group: Applications/System
Source0: http://download.jboss.org/jbossas/7.1/jboss-as-{version}.Final/jboss-as-{version}.Final.zip
Provides: jboss-as7
Requires: shadow-utils
Requires: coreutils
Requires: java >= 1.6.0
Requires: initscripts
Requires(post): /sbin/chkconfig
Requires(pre): /usr/sbin/useradd, /usr/bin/getent
Requires(postun): /usr/sbin/userdel
BuildRoot: %{_tmppath}/%{name}-as-%{version}-%{release}-root-%(%{__id_u} -n)
%define runuser %{name}
%define __jar_repack %{nil}
%description
The JBoss Application Server
%prep
%setup -n %{name}-as-%{jboss_version_full}.Final
/usr/bin/getent passwd %{name} >/dev/null 2>&1 || useradd -r %{name} -u 600 -d /usr/local/jboss -s /bin/bash >/dev/null 2>&1
%install
cd %{_topdir}/BUILD
install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
install -d -m 755 $RPM_BUILD_ROOT/etc/conf.d
install -d -m 755 $RPM_BUILD_ROOT/usr/local/%{name}
install -d -m 755 $RPM_BUILD_ROOT/usr/local/%{name}/server/default/conf
cp -R %{name}-as-%{jboss_version_full}.Final/* $RPM_BUILD_ROOT/usr/local/%{name}
# it caused adding bad requires for package
/bin/rm -rf $RPM_BUILD_ROOT/usr/local/%{name}/bin/jboss_init_solaris.sh 2>&1
# Remove standalone xml file
# /bin/rm -rf $RPM_BUILD_ROOT/usr/local/%{name}/standalone/configuration/standalone.xml 2>&1
install -d -m 755 $RPM_BUILD_ROOT%{_initrddir}
install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig/%{name}
install -d -m 755 $RPM_BUILD_ROOT/etc/jboss-as
cp -R %{name}-as-%{jboss_version_full}.Final/bin/init.d/jboss-as-standalone.sh $RPM_BUILD_ROOT%{_initrddir}/jboss
cp -R %{name}-as-%{jboss_version_full}.Final/bin/init.d/jboss-as.conf $RPM_BUILD_ROOT/etc/jboss-as/jboss-as.conf
# If jboss is running, kill it
# maxcount in seconds to wait before hitting
# with the big hammer
MAXCOUNT=30
INCREMENT=3
# assert modulus of MAXCOUNT by INCREMENT is 0
if [ ! $(($MAXCOUNT % $INCREMENT)) -eq 0 ];then
echo "the modulus of MAXCOUNT ($MAXCOUNT) and INCREMENT ($INCREMENT) is nonzero"
exit 1;
fi
PID=`ps -e -o pid,args|grep -v grep|grep java|grep run.sh|awk '{print $1}'`
if [ -n "$PID" ];then
kill -15 $PID
fi
PID=`ps -e -o pid,args|grep -v grep|grep java|grep run.sh|awk '{print $1}'`
if [ -n "$PID" ];then
for x in `seq $MAXCOUNT -$INCREMENT 0`;do
PID=`ps -e -o pid,args|grep -v grep|grep java|grep run.sh|awk '{print $1}'`
kill -15 $PID
PID=`ps -e -o pid,args|grep -v grep|grep java|grep run.sh|awk '{print $1}'`
if [ -z "$PID" ];then
break
fi
sleep $INCREMENT
done
fi
# make sure we succeeded
PID=`ps -e -o pid,args|grep -v grep|grep java|grep run.sh|awk '{print $1}'`
if [ -n "$PID" ];then
kill -9 $PID
fi
# Does /var/log/jboss exist? if not, create it and set ownership to jboss
if [ ! -d $RPM_BUILD_ROOT/var/log/jboss ];then
mkdir -p $RPM_BUILD_ROOT/var/log/jboss
chmod -R 600 $RPM_BUILD_ROOT/var/log/jboss
fi
chmod 600 $RPM_BUILD_ROOT/etc/sysconfig/%{name}
cat > "$RPM_BUILD_ROOT%{_initrddir}/jboss" << "EOF"
#!/bin/sh
#
# JBoss standalone control script
#
# chkconfig: - 80 20
# description: JBoss AS Standalone
# processname: standalone
# pidfile: /var/run/jboss/jboss-standalone.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/local/jboss
fi
export JBOSS_HOME
if [ -z "$JBOSS_PIDFILE" ]; then
JBOSS_PIDFILE=/var/run/jboss/jboss-standalone.pid
fi
export JBOSS_PIDFILE
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
JBOSS_CONSOLE_LOG=/var/log/jboss/console.log
fi
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
if [ -z "$JBOSS_CONFIG" ]; then
JBOSS_CONFIG=standalone.xml
fi
JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.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"
failure
echo
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 [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &
else
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &
fi
fi
count=0
launched=false
until [ $count -gt $STARTUP_WAIT ]
do
grep 'JBoss AS.*started in' $JBOSS_CONSOLE_LOG > /dev/null
if [ $? -eq 0 ] ; then
launched=true
break
fi
sleep 1
let count=$count+1;
done
success
echo
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
success
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
EOF
cat > "$RPM_BUILD_ROOT/etc/jboss-as/jboss-as.conf" << "EOF"
# General configuration for the init.d scripts,
# not necessarily for JBoss AS itself.
# The username who should own the process.
#
JBOSS_USER=jboss
# The amount of time to wait for startup
#
# STARTUP_WAIT=30
# The amount of time to wait for shutdown
#
# SHUTDOWN_WAIT=30
# Location to keep the console log
#
JBOSS_CONSOLE_LOG=/var/log/jboss/console.log
EOF
# Reload the profile
for i in /etc/profile.d/*.sh ; do
if [ -x $i ]; then
. $i
fi
done
source /etc/profile
%clean
/bin/rm -Rf $RPM_BUILD_ROOT
%pre
/usr/bin/getent passwd %{name} >/dev/null 2>&1 || userdel %{name} >/dev/null 2>&1
/usr/bin/getent passwd %{name} >/dev/null 2>&1 || useradd -r %{name} -u 600 -d /usr/local/jboss -s /bin/bash >/dev/null 2>&1
%post
/sbin/chkconfig --add %{name}
%postun
userdel %{name} >/dev/null 2>&1
if [ -d /var/log/jboss ]; then
/bin/rm -fr /var/log/jboss >/dev/null 2>&1
fi
if [ -d /usr/local/jboss ]; then
/bin/rm -fr /usr/local/jboss >/dev/null 2>&1
fi
%files
%defattr(-,%{name},%{name})
/
%changelog
* Wed Feb 05 2014 Stutart Warren 7.1.1
- Added Provides line
- Changed Requires to Java
* Wed Apr 06 2012 Mark Austin 7.1.1
- Upgrade to upstream 7.1.1 release
* Wed Feb 15 2012 Mark Austin 6.1
- Upgrade to upstream 6.1 release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment