How do I Start JBoss on boot with Linux?
Overview
Linux uses System V init scripts.
Although there can be some differences between distributions, generally it looks like this:
- /etc/rc.d/init.d/ - contains the start and stop scripts (other distributions: /etc/init.d/)
- /etc/rc.(x)/ - contains links to the start and stop scripts prefixed with S or K (start or kill respectively)
There are various run levels for various stages of system use.
- rc1.d - Single User Mode
- rc2.d - Single User Mode with Networking
- rc3.d - Multi-User Mode - boot up in text mode
- rc4.d - Undefined
- rc5.d - Multi-User Mode - boot up in X Windows
- rc6.d - Shutdown
Most
Linux systems used as Application Servers boot
into run level 3
(if
not, your system admin needs to be questioned on why your server needs
to boot into X-Windows and needlessly waste system resources :-).
Your task is to:
- create a user for JBoss (recommended) so that JBoss can be restricted to accessing only the files and system resources that it has permission to access via the "jboss" user.
- create a script called /etc/rc.d/init.d/jboss or use the distro specific one (JBoss 4 or up)
- create a link called /etc/rc3.d/S84jboss - we're interested in bootup text mode runlevel
- create a link called /etc/rc6.d/K15jboss - we're interested in shutdown service at the shutdown of the machine
(obviously choose the proper runlevel you prefer)
#! /bin/sh
start(){
echo "Starting jboss.."
su -l jboss -c '/home/jboss/jboss-4.2.2.GA/bin/run.sh > /home/jboss/startup-jboss-service.log &'
}
stop(){
echo "Stopping jboss.."
su -l jboss -c '/home/jboss/jboss-4.2.2.GA/bin/shutdown.sh -S &'
}
restart(){
stop
# give stuff some time to stop before we restart
sleep 60
# protect against any services that can't stop before we restart (warning this kills all Java instances running as 'jboss' user)
su -l jboss -c 'killall java'
# if the 'su -l ...' command fails try:
# sudo -u jboss killall java
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: jboss {start|stop|restart}"
exit 1
esac
exit 0
Using the included init Scripts (JBoss 4.0.1 and higher)
Alternatively,
JBoss 4.0.1 (and higher) comes with prebaked init scripts in the bin
directory, jboss_init_redhat.sh and jboss_init_suse.sh. You can copy
one of these scripts to /etc/rc.d/init.d/jboss, then make the links
below, or create a symbolic link from /etc/rc.d/init.d/jboss to one of
them. These scripts don't pipe logging to /dev/null, but to a real
file.
create links
The
links will be used to identify at which run levels JBoss should be
started and stopped. In general this is probably what you want (do as
root):
ln -s /etc/rc.d/init.d/jboss /etc/rc3.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc5.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc4.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc6.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc0.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc1.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc2.d/K15jboss
RedHat has a chkconfig command to manage these links, which may or may
not work (it uses comments in the top of the script to determine which
run-levels it should be started/stopped in) giving something like:
[root@vmce31 bin]# chkconfig --listNetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off
anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
apmd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
avahi-daemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[...]
we should have also
jboss at various runlevel conf.

Nessun commento:
Posta un commento