Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Login Script

1 view
Skip to first unread message

Peter

unread,
Nov 19, 2003, 3:56:06 PM11/19/03
to
To all,

I need to create a script that would start tomcat, then wait 30
seconds, then start apache.

What command(s) could do that? (Red Hat 9.0)


Thanks,
Peter

hazzmat

unread,
Nov 19, 2003, 4:54:09 PM11/19/03
to

modify /etc/init.d/httpd

kill off JBoss directing stderr and stdout to /dev/null; start JBoss( Or
maybe you want to first detect the presence of running Jboss and leave
it alone if it's already running, or not, I don't know) ; sleep 30
seconds; continue with the rest of the normal httpd startup script.

That'd be the ugly way to go about it. I'll let some show-off detail the
elegant way.

Lookup Bash tutorials. Google can also help you find simple awk commands
for detecting the presence of a given job name in the ps table in case
you wanted to detect JBoss before deciding to start it, rather than kill
it and start it everytime the /etc/init.d/httpd script is run.

penguin-rox

unread,
Nov 19, 2003, 4:55:04 PM11/19/03
to
penguin-rox wrote:

>
> #!/bin/bash
>
> service tomcat start
> sleep 30
> service apache star
>
>
>
>
> ??
>

or

#!/bin/bash
service tomcat start
sleep 30
service httpd start

penguin-rox

unread,
Nov 19, 2003, 4:55:04 PM11/19/03
to

#!/bin/bash

hazzmat

unread,
Nov 19, 2003, 5:26:34 PM11/19/03
to

check and make sure the start up script for JBoss (is there an
/etc/init.d/tomcat or JBoss script ?) exists.

Make sure in /etc/rc3.d and /etc/rc5.d/ that whatever that JBoss start
up script is called, has a runlevel marker that's lower than httpd's

so in /etc/rc3.d (and rc5.d ) if httpd has an entry like S85httpd make
sure whatever starts up Jboss is lower like S83
then alter /etc/init.d/httpd with a line at towards the very top sleep
30 like right before sourcing functions.

doing that would guarantee a 30 second delay between the initialization
of JBoss and apache. The only way that could not happen is if the JBoss
startup script is run in the background and it takes a l o n g t i m e
to start up--more than 30 seconds.

Peter

unread,
Nov 20, 2003, 1:24:21 PM11/20/03
to
hazzmat <haz...@bellsouth.net> wrote in message news:<I2Sub.11855$ow5....@bignews2.bellsouth.net>...


I'm not using JBoss, it's overkill for my needs. All I need is
servlets right now.

As for the httpd service from the RH Service manager; it's hosed. I
upgraded from Apache 1.2 to 2.0.44 and it doesn't point to the apache2
directory, it still looks at the 1.3 dir and starts apache 1.3. Do
you know what file I should change so it will point to apache2 and I
can delete 1.3 altogether?

What I would really like to do it add a 'apatom' service to the RH
Service Manager and link the script file I just created to RH service
manager so it starts on both on bootup and runs some other processes.

Thanks guys!
Peter

hazzmat

unread,
Nov 20, 2003, 4:08:38 PM11/20/03
to
"Do
you know what file I should change so it will point to apache2 and I
can delete 1.3 altogether?"


WHoah ok your situation is more complicated than it seemed at first.
Basically, if you want easy "service" and runlevel control over httpd *I
think* you'd be much better off saving your files and servlets and just
bringing them over, after making a *new upgraded installation* with a
distro version that includes apache 2.0 from the get-go--

Or you could find "contributed" rpms for apache 2.0.47 that will install
on your specific RH system.

Otherwise, if you want to stick with your present server --and have easy
scripting control over httpd startup, stopping, reloading and
restarting-- it will depend a great deal on the exact details of your
setup how this can be accomplished. And how much stomach you have for
hacking it out.

Apparently you installed apache 2 from source?

And if so, it ALL lives out in /usr/local/apache2 --or wherever you put
it if you changed the default location. An RPM installed apache, by
contrast, is spread out over the filesystem. The startup script reflects
this, and so all the differences have to be tracked down and changed !

If you've been running apache2 from your local build then the conf/ dir
is within /usr/local/apache2 not /etc/httpd/conf anymore. But that's
where /etc/init.d/httpd thinks the configuration is.

Likewise, the http daemon started up by your /etc/init.d/httpd script
(as installed by the rpm for apache 1.3) is /usr/sbin/httpd
But your locally compiled httpd will be at /usr/local/apache2/bin/httpd
instead --or wherever you put it.

Also, ontop of that there are modules for Apache that a redhat rpm will
install to /usr/lib/apache/.
But if you compiled your own apache2, the matching modules are out in
/usr/local/apache2/lib/

ALL references to these kinds of locations (/usr/sbin/httpd;
/usr/sbin/apachectl; /usr/lib/apache ) would need to be changed in the
startup script /etc/init.d/httpd to point to their appropriate locations
within /usr/local/apache2

---------
Of course, that leaves aside the question of whether this startup script
is altogether appropriate for apache2. It might work just fine. It might
not.

You could extract the httpd startup script from a more recent Redhat --a
RH version that has apache2-- by using rpm-utils. rpm-utils allows for
the extraction of a single file from an rpm if you know the filename. If
that isn't on your system you can get rpm-utils from
ftp://ftp.kaybee.org/pub/linux/rpm-utils-1.5.tar.gz

I've pasted an example below but its formatting likely to be really
mangled --and you may want to use a different rpm, like from RH9.

========================================================

I extracted /etc/init.d/httpd from an apache rpm of "whitebox linux" --a
free RHEL 3.0 version compiled from redhat SRPMS . The command to use
is rpm-get from the rpm-utils directory.
syntax: command rpm-package-file file-to-be-extracted output-filename
---------------------------------------------------------------
#cd rpm-utils-1.5
#./rpm-get /mnt/cdrom/RedHat/RPMS/httpd-2.0.46-25.ent.i386.rpm
/etc/rc.d/init.d/httpd

using the "httpd" script that this outputted, I modified it to point to
the locations of an apache2 build which I had downloaded as source from
apache.org and compiled meanwhile:

#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
RETVAL=0

# check for 1.3 configuration
check13 () {
CONFFILE=/usr/local/apache2/conf/httpd.conf
GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
GONE="${GONE}AccessConfig|ResourceConfig)"
if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
echo
echo 1>&2 " Apache 1.3 configuration directives found"
echo 1>&2 " please read /usr/share/doc/httpd-2.0.46/migration.html"
failure "Apache 1.3 config directives test"
echo
exit 1
fi
}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
check13 || exit 1
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
check13 || exit 1
killproc $httpd -HUP
RETVAL=$?
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/run/httpd.pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog
{start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL
-------------------------------------

this will start my freshly compiled apache-2.0.48 on a RH7.3 box. Never
mind the comments at the top of the file about etc/httpd/conf/httpd.conf
being the master config file: unless apache is told otherwise it will
use its local configuration file default of
/usr/local/apache2/conf/httpd.conf.
Just altering that file to treat /var/www/html as the document root got
things back in gear.

You could rename this startup script /etc/rc.d/init.d/httpd2 instead of
'httpd' just to keep it clear and to avoid rpm -e from erasing it by
accident. Set symlinks in rc3.d and rc5.d so that it is read at start
up, or a change of runlevel:
ln -s /etc/rc.d/init.d/httpd2 /etc/rc.d/rc3.d/S86httpd2
ln -s /etc/rc.d/init.d/httpd2 /etc/rc.d/rc5.d/S86httpd2

and killed off appropriately, too:
ln -s /etc/rc.d/init.d/httpd2 /etc/rc.d/rc3.d/K16httpd2
ln -s /etc/rc.d/init.d/httpd2 /etc/rc.d/rc5.d/K16httpd2
------------------

How you start your java stuff and link it in I don't know. I don't know
the process name or anything.
But this will at least "repair" the httpd startup to the point where you
can hack your "apatom" thing in. Maybe you want to start it up
separately and before httpd2, with its own /etc/init.d/ script and
runlevel symlinks, I don't know.

if you rpm -e apache* stuff from your system, the file named
/etc/rc.d/init.d/httpd will be deleted, too. Be careful to keep a backup
around that you can replace it with. The deleting by rpm is supposed to
clobber directories created by the rpm-- hopefully nothing like
/var/www/html will be deleted in the process because it won't be empty
--but be cautious.

Peter

unread,
Nov 21, 2003, 10:43:31 PM11/21/03
to
hazzmat <haz...@bellsouth.net> wrote in message news:<hlavb.8769$DX3....@bignews5.bellsouth.net>...

Well, I don't have the time to go there right now. What I'd like to
do right now is add a 'apatom' service to RH Manager that does the
following,

service tomcat start
sleep 30

java service start
service apache start

...so on bootup it runs.

-Peter

0 new messages