Weblog entry #3 for andershedstrom
Start JBoss on boot with Debian 3.1
This is a short and easy HOW-TO guide. It describes in a few steps how to start JBoss on boot with Debian 3.1. This is not the only way to accomplish this task, but this is the way I take. I do not issue any guarantee that this will work for you and your system (but it should with some tweaking).
System Details
The system used in this how-to guide has the following installed:
Operating System: Debian Sarge (3.1) – the base system.
JDK: Sun JDK 5 (see: Install Sun JDK 5)
JBoss: JBoss 4.0.3SP1 (see: Install JBoss)
HOW-TO GUIDE
- Change to /etc/init.d and switch to root user.
> cd /etc/init.d > su Password:
- Create a file named jboss
> touch jboss
- Open the newly created file, add the following
#! /bin/sh # /etc/init.d/jboss: Start and stop JBoss AS ECHO=/bin/echo TEST=/usr/bin/test JBOSS_START_SCRIPT=/usr/local/jboss-4.0.3SP1/bin/run.sh JBOSS_STOP_SCRIPT=/usr/local/jboss-4.0.3SP1/bin/shutdown.sh $TEST –x $JBOSS_START_SCRIPT || exit 0 $TEST –x $JBOSS_STOP_SCRIPT || exit 0 start() { $ECHO –n "Starting JBoss" su – jboss –c "$JBOSS_START_SCRIPT > /dev/null 2> /dev/null &" $ECHO "." } stop() { $ECHO –n "Stopping JBoss" su – jboss – c "$JBOSS_STOP_SCRIPT –S > /dev/null &" $ECHO "." } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 30 start ;; *) $ECHO "Usage: jboss {start|stop|restart}" exit 1 esac exit 0Save and close the file - Change the permissions on the file by executing the following command
> chmod 755 jboss
- Test your script by executing the following commands
> ./jboss Usage: jboss {start|stop|restart} > ./jboss start Starting JBoss. - Make sure that JBoss is running by executing the following command
> ps –A|grep java 1164 pts/0 00:00:00 java 1165 pts/0 00:00:00 java 1166 pts/0 00:00:01 java …
You should see a lot of java processes running. - Stop JBoss by executing the following command
> ./jboss stop Stopping JBoss.
- Check that JBoss really was stopped by executing the same command as above for checking that JBoss was running. Now you shouldn’t see any java processes running
> ps –A|grep java >
- Update the run level so this script will be executed at start up by executing the following command
> update-rc.d jboss defaults Adding system startup for /etc/init.d/jboss ... /etc/rc0.d/K20jboss -> ../init.d/jboss /etc/rc1.d/K20jboss -> ../init.d/jboss /etc/rc6.d/K20jboss -> ../init.d/jboss /etc/rc2.d/S20jboss -> ../init.d/jboss /etc/rc3.d/S20jboss -> ../init.d/jboss /etc/rc4.d/S20jboss -> ../init.d/jboss /etc/rc5.d/S20jboss -> ../init.d/jboss
- Restart your system
> /sbin/reboot
- When the system is up again, make sure JBoss was started
> ps –A|grep java 944 pts/0 00:00:00 java 945 pts/0 00:00:00 java 946 pts/0 00:00:01 java …
Comments on this Entry
Just some little remarks that might help moving this forward to full Debian standard compliance, together with some questions as well.
1. JBoss should probably referred to as jboss4 as Debian keeps that scheme, for example with tomcat4, tomcat5 but also in non Java related stuff such as cyrus21.
2. If I follow you instructions by the book I fail because I don't have any jboss user on my system. I am not sure if there is something like a standard uid for jboss, but I found 94 mentioned somewhere, so
useradd -u 94 jboss4
would be something to add in the right place.
3. In case you wonder why you JBoss does not start, make sure that the user jboss4 has sufficient rights to the expanded JBoss tar directory. If you download and extract it as root, it will not be able to run as jboss4 because some files that JBoss creates upon the first start will be owned by root.
This can easily be fixed with
chown -R jboss4 /your/jboss/expanded/tar
4. In case you want to take this further into a full featured Debian packages (as long as nobody has done that already), what comes to mind is:
- most Debian init.d scripts source configuration information from some /etc/... file. This typically contains stuff such as the uid to use and the like.
- it would make sense to not hard-code jboss for the su, i.e. use su - $JBOSS4_USER.
I found this old email:
http://lists.debian.org/debian-java/2001/08/msg00001.html
Has some useful thoughts.
[ Parent | Reply to this comment ]
[ Send Message | View Weblogs ]
#1:
I agree - that's probably a good idea
#2,3:
I create a user named "jboss" when I install JBoss. I refer to anonther weblog I written in the begining of this HOWTO - "Install JBoss". But this should have been more clear in this guide...
#4:
I haven't been able to find any Debian JBoss package. This is maybe something I should put some time in and create (I've never made a debian package before, so it would be pretty fun to dig in to =))
[ Parent | Reply to this comment ]
#4: Sure. I wonder why that has not been done yet. But I volunteer to test it.
You might want to look at http://www.jpackage.org/ for some inspiration and there's a debian-mentors mailing list for just people like you and me who think about their first Debian package. But I won't have time, JBoss is just a side-activitity for me right now.
Regards,
Torsten
[ Parent | Reply to this comment ]
I am working on an in-house project that is using jboss4 on debian. I wrote an similar init.d script as yours, and we have build a custom debian package for jboss. I'm looking into using debconf to configure certain settings that vary from server to server.
Mike --
[ Parent | Reply to this comment ]
http://wiki.debian.org/JBossPackaging?highlight=%28jboss%29
There are already packages available, but it needs more work to put them into Debian proper.
Cheers,
-- Guido
[ Parent | Reply to this comment ]
The solution is the use of a hex editor to change the string "\u2013" that looks like the hyphen on the web page by the hyphen (hexadecimal code 45).
[ Parent | Reply to this comment ]