Single Startup script for Apache/jboss

Hi,

I have apache ,jboss and jon instances on various linux boxes.I need to create a generic startup script to restart those instances on server reboot.The script requirement is :
It should take the name of instances from one text file named active-servers and recycle those instances.

  1. start-mws-servers (generic script for /etc/rc.d but just create it in ~/bin dir for current testing)

It simply searches ~/bin/active-servers for active server recycle scripts
It executes each recycle script and passes it the 'start' command
It logs results to /tmp/start-mws-servers.log so we can review it after a machine recycle
Please help.

Regards,
Saurau

Can you supply an active-servers text file for a server running apache, jboss and jon?

Hi,

My active server text file will look like :

apache-instance1
apache-instance2
apache-instance3
ews-instance1
ews-instance2
ews-instance3
eap-instance1
eap-instance2
eap-instance3
rhq-agent
jon-123

It means apache instances will start from apache-,tomcat from ews-,jboss from eap- etc.

Regards,
Saurau

How about something like this:

#!/bin/sh
LOGFILE=/tmp/start-mws-servers.log
SCRIPT_DIR=~/bin
 
logmsg () {
  echo $(date): $1 >> $LOGFILE
}
 
while read instance
do
    if [ -x  "${SCRIPT_DIR}/$instance" ] ; then
        logmsg "Recycle $instance..."
        "${SCRIPT_DIR}/$instance" start >> $LOGFILE 2>&1
    else
        logmsg "Cannot find recycle script for $instance - not starting"
    fi
done < "${SCRIPT_DIR}/active-servers"
logmsg "Start script execution complete"
1 Like

Thanks a lot for your help.It's really good. I will try and you know, if any complication arises.

Regards,
Saurau.

Hi,

Thanks it worked, however my active instances are installed on different path and also only start command wont work for all the instances.The script provided by you will work only when i make startup-scripts separately on the name of instances and then run the provided script.

Is there any way , to merge all the startup scripts in one , so that there will be single start up script.

Regards,
Saurabh Kumar.

I'd assume that each instance would need to have some sort of configuration parameters (eg apache would have it's own httpd.conf to setup a different listen port, server root, etc).

One way to deal with this is enhance the details stored in your active-servers.txt eg:

[apache-instance1]
AUTOSTART=1
CMD=/usr/local/apache/bin/httpd -f /usr/local/apache/conf/instance1.conf
STARTDIR=/usr/local/bin/apache-instance1
 
[apache-instance2]
AUTOSTART=1
CMD=/usr/local/apache/bin/httpd -f /usr/local/apache/conf/instance2.conf
STARTDIR=/usr/local/bin/apache-instance2

Nice thing about this is you have a one-stop-shop for setting up all these servers, the down side is the start (and stop) scripts will need to be more complex to parse and validate this file.