LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-09-2010, 04:40 AM   #1
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Rep: Reputation: 0
Jboss as a service


Thank you for viewing my question,

How can I make Jboss 5.1 as a service? Whereby, I don't have to run it from ssh/command line to have it started. i want it to be like, for instance:

service jboss start
service jboss stop
service jboss status

etc.

It should always be running!

Thanks once again
 
Old 11-09-2010, 05:52 AM   #2
Steviepower
Member
 
Registered: May 2010
Location: Eindhoven
Distribution: ubuntu/debian
Posts: 152

Rep: Reputation: 25
depends on how you want to use it, I'm using screen to do this. I just do screen [program] and then ctrl+a => d to detach the screen and screen -r to resume. Works fine for me.
Other option would be to run a script that deamonizes it.
#!/bin/bash
echo "[program] started"
[program]&
echo "[program] crashes"

and then other scripts to do other things?
 
Old 11-09-2010, 06:41 AM   #3
crazy_bytes
LQ Newbie
 
Registered: Feb 2009
Location: Germany
Distribution: CentOS 5.3
Posts: 15

Rep: Reputation: 8
Create a script under /etc/init.d/ named jboss.

Then insert your scripting there I don't know how well it will work with 5.1 since I am using 4.2.3.GA, but the base parameters should be the same:

Code:
#!/bin/bash

#
# JBoss Control Script
#
# chkconfig: 3 80 20
# description: JBoss EJB Container
# 
# To use this script
# run it as root - it will switch to the specified user
# It loses all console output - use the log.
#
# Here is a little (and extremely primitive) 
# startup/shutdown script for RedHat systems. It assumes 
# that JBoss lives in /opt/jboss, it's run by user 
# 'jboss' and JDK binaries are set in JAVA_HOME. All 
# this can be changed in the script itself. 
#
# Make sure JAVA_HOME points to a JDK (recommended) or JRE and
# JAVA_HOME/bin is in included in the PATH var.
# 
# Either amend this script for your requirements
# or just ensure that the following variables are set correctly 
# before calling the script

# [ #420297 ] JBoss startup/shutdown for RedHat

# The JBoss root directory
JBOSS_HOME="/opt/jboss"
# The configuration JBoss will run with
JBOSS_CONFIG="default"
# JBoss hostname / IP address
JBOSS_IP="192.168.1.20"
# The file that recieves log messages.
JBOSS_CONSOLE="/var/log/jboss.log"
# Only used for clustering multiple JBoss server
JBOSS_PARTITION="DefaultPartition"
# The user JBoss will be run as
JBOSSUS="jboss"

# The start command for starting up jboss.
JBOSSSH="$JBOSS_HOME/bin/run.sh -c $JBOSS_CONFIG --host=$JBOSS_IP -Djboss.partition.name=$JBOSS_PARTITION"

# Define where jboss is - this is the directory containing directories log, bin, conf etc. If not set default to /usr/local/jboss
JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss"}

# Make java is on your path
JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}

# Define the classpath for the shutdown class
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

# Define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c default"}

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  # Ensure the file exists
  touch $JBOSS_CONSOLE
fi

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  echo "WARNING: ignoring it and using /dev/null"
  JBOSS_CONSOLE="/dev/null"
fi

# Define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}

# Define the user under which jboss will run, or use RUNASIS to run as the current user
JBOSSUS=${JBOSSUS:-"jboss"}

CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH" 

CMD_STOP=${CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown -s jnp://$JBOSS_IP:1099 --shutdown"}

if [ "$JBOSSUS" = "RUNASIS" ]; then
  SUBIT=""
else
  SUBIT="su - $JBOSSUS -c "
fi

if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  export PATH=$PATH:$JAVAPTH
fi

if [ ! -d "$JBOSS_HOME" ]; then
  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  exit 1
fi


echo CMD_START = $CMD_START
TIME=`date +%F-%T`	#%F     full date; same as %Y-%m-%d
			#%T     time; same as %H:%M:%S

case "$1" in
start)
    cd $JBOSS_HOME/server/$JBOSS_CONFIG/log
    cp -i server.log 	server.log-$TIME
    chown jboss.jboss 	server.log-$TIME
    cd $JBOSS_HOME/bin
    if [ -z "$SUBIT" ]; then
        eval $CMD_START >${JBOSS_CONSOLE} 2>&1 &
    else
        $SUBIT "$CMD_START >${JBOSS_CONSOLE} 2>&1 &" 
    fi
    ;;
stop)
    if [ -z "$SUBIT" ]; then
        $CMD_STOP
    else
        $SUBIT "$CMD_STOP"
    fi 
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"
esac
Save the file. Then run the follwing commands:

Code:
$> chkconfig --add jboss
$> chkconfig jboss off
$> chkconfig --level 35 jboss on
The last command will cause jboss to start on run level 3 and 5. So if you your system boots to run level 3 or 5 it will be automatically started.

Now Jboss should be available in the service command:
Code:
$> service jboss start
$> service jboss restart
$> service jboss stop
All commands work in Red Hat / Fedora / CentOS (well at least for me).

Hope that helps - Best regards,
CB
 
Old 11-09-2010, 07:52 AM   #4
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you for your response; I got the following when I run :

service jboss start


env: /etc/init.d/jboss: Permission denied

am on fedora 12, what am i doing wrong?

Note: I saved the script your provided and executed

$> chkconfig --add jboss
$> chkconfig jboss off
$> chkconfig --level 35 jboss on
 
Old 11-09-2010, 08:06 AM   #5
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
with the permission error, i did chmod -R 755 /etc

and I run service jboss start. I believe it was running fine. I was able to access it via the web interface using:

http://1p-of-my-server:8085

If I run service jboss stop:

I got the following exceptions -

Code:
root@serverA01 [~]# service jboss stop
JBOSS_CMD_START = cd /opt/java/jboss/bin; /opt/java/jboss/bin/run.sh -c default -b 188.20.190.186
Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused]]]
        at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at org.jboss.Shutdown.main(Shutdown.java:219)
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused]]
        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:335)
        at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734)
        ... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused]
        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:305)
        ... 5 more
Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:97)
        at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:82)
        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:301)
        ... 5 more
 
Old 11-09-2010, 09:02 AM   #6
crazy_bytes
LQ Newbie
 
Registered: Feb 2009
Location: Germany
Distribution: CentOS 5.3
Posts: 15

Rep: Reputation: 8
You did not have to change the permissions for all in /etc/ and lower. A plain chmod 755 /etc/init.d/jboss would have been sufficient. I hope you won't get problems from this.

The problem with the stop command could be version dependend. Maybe the shutdown command line has been changed.

Looking at the shutdown.sh provided in Jboss 5.1 change the line beginning with JBOSSCP=... to the following:

Code:
JBOSSCP="$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jbossall-client.jar"
Change the line beginning with CMD_STOP=... to this line below:

Code:
CMD_STOP="java -classpath $JBOSSCP org.jboss.Shutdown"
Best regards,
CB
 
Old 11-09-2010, 09:05 AM   #7
crazy_bytes
LQ Newbie
 
Registered: Feb 2009
Location: Germany
Distribution: CentOS 5.3
Posts: 15

Rep: Reputation: 8
if you want to see console output just issue the follwing command:

Code:
$> tail -f /var/log/jboss.log
You can quit the console watching with Ctrl+C.

When I am testing im usually do the following commands:

Code:
$> service jboss start && tail -f /var/log/jboss.log
$> service jboss stop && tail -f /var/log/jboss.log
 
Old 11-09-2010, 01:59 PM   #8
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
I got a problem already. Cant access my server for hours. I think the problem is with the chmod that i made on etc. Server is running, but I can't login. Don't know what to do. I have tried putty, WinSCP, etc. Network error is being outputted. I guess am ...
 
Old 11-10-2010, 01:10 AM   #9
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
I can't access my server after i chmod -R /etc folder. What can I do now?
 
Old 11-10-2010, 02:20 AM   #10
crazy_bytes
LQ Newbie
 
Registered: Feb 2009
Location: Germany
Distribution: CentOS 5.3
Posts: 15

Rep: Reputation: 8
I hope you have a backup. Since you have ovewritten the permissions,
there is no way (at least none I know off), to restore the permission
to the previous state. I hope you are able to restore your original
configuration.

Yesterday I took the time to look into the JBoss 5.1. I found out that
under JBOSS_HOME/bin exists a file named jboss_init_redhat.sh. It's
similar to the one I posted. you could copy this into /etc/init.d/ and
modify it to your liking.

Make sure you only chmod the script file and not the entiry directory
/etc/ and lower.

Assuming JBoss was unzipped into /opt/java/jboss, you would need to
take the following steps:

Code:
$> cp /opt/java/jboss/bin/jboss_init_redhat.sh /etc/init.d/jboss
# Then modify /etc/init.d/jboss to your liking using vi or another editor
$> chmod 755 /etc/init.d/jboss
$> chkconfig --add jboss
$> chkconfig jboss off
$> chkconfig --level 35 on
Best regards,
CB
 
Old 11-10-2010, 02:43 AM   #11
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you for your comment, but my question is how do I restore my original configuration if I don't have access to the box. Am running an Ubuntu VPS hosted by another company. can i do the restore myself or they have to be contacted? Am so ...
 
Old 11-10-2010, 04:57 AM   #12
crazy_bytes
LQ Newbie
 
Registered: Feb 2009
Location: Germany
Distribution: CentOS 5.3
Posts: 15

Rep: Reputation: 8
I don't know your setup, but I know that most hosters have web portals where you can see your contract data and stuff. There should also be an option to restore your system.

I have a private server myself hosted by server4you.de. They have a web portal where I can order a backup or a restore. They do a backup every month and I can do order a backup myself if I need one. There is even an option to preinstall my server with different linux distros.

If you don't have that option like me there will be no other way than conacting your hoster.

Best regards,
CB
 
Old 11-11-2010, 02:34 AM   #13
Steviepower
Member
 
Registered: May 2010
Location: Eindhoven
Distribution: ubuntu/debian
Posts: 152

Rep: Reputation: 25
maybe I'm a little too late... but don't chmod -R any folders in the root directory directly unless you know what you're doing!
it can seriously mess stuff up.
 
Old 11-11-2010, 04:08 AM   #14
nitation
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
thank you for that hint. i managed to fix the box though, following your previous comment and I quote:

Quote:
Yesterday I took the time to look into the JBoss 5.1. I found out that
under JBOSS_HOME/bin exists a file named jboss_init_redhat.sh. It's
similar to the one I posted. you could copy this into /etc/init.d/ and
modify it to your liking.

Make sure you only chmod the script file and not the entiry directory
/etc/ and lower.

Assuming JBoss was unzipped into /opt/java/jboss, you would need to
take the following steps:

Code:
$> cp /opt/java/jboss/bin/jboss_init_redhat.sh /etc/init.d/jboss
# Then modify /etc/init.d/jboss to your liking using vi or another editor
$> chmod 755 /etc/init.d/jboss
$> chkconfig --add jboss
$> chkconfig jboss off
$> chkconfig --level 35 on
Best regards,
CB
I got this while trying to use chkconfig:

Quote:
service jboss does not support chkconfig
.

Thanks
 
Old 11-12-2010, 02:17 AM   #15
crazy_bytes
LQ Newbie
 
Registered: Feb 2009
Location: Germany
Distribution: CentOS 5.3
Posts: 15

Rep: Reputation: 8
There are missing 2 comment lines at the top, that are required by chkconfig. Just replace the first line in the jboss file "#!/bin/sh" with:

Code:
#!/bin/bash

#
# JBoss Control Script
#
# chkconfig: 3 80 20
# description: JBoss EJB Container
That should do the trick

Best regards,
CB
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run JBoss 5 as a Service / Daemon on Fedora 8? socal_javaguy Linux - Software 1 07-31-2009 11:30 AM
Run JBoss App as a service at a given time netjack Linux - Server 3 12-05-2007 12:02 PM
How to make TCP server a daemon / service much like a dhcpd service? rajat Linux - Networking 1 05-22-2007 01:29 AM
how to add service in service list akamol Linux - Software 2 07-20-2006 01:37 AM
/sbin/service is empty every weekend and changed to service.1 LineS Linux - General 0 05-24-2004 02:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration