We help IT Professionals succeed at work.

Adding scripts to  boot sequence in Linux

atorex
atorex asked
on
Medium Priority
408 Views
Last Modified: 2012-05-12
I need some help from a Linux expert perhaps SUSE Linux expert, I have a system that Im trying to get 2 applications to auto start in run level 3 and 5.

the OS is Suse Linux Enterprise 11 with SP1, the applications  I want to run are
Tomcat and a Java application.
the 2 applications are in the /opt/mydir directory, they each have a start script that work if i execute them from within the directory.
I have created a script that will execute the 2 startup scripts and placed them in /etc/init.d/
I created an S09 and a K01for linked to the tomcat start script in rc3.d and rc5.d, my issue is that if I execute the  S09 script tomcat starts however rebooting the system does not start the apps.
I really need help with this one have tried several times but cant seam to get it to run, I have both Gnome and KDE versions of the desktop manager same issue with both.
if anyone know what I'm doing wrong or perhaps whats the correct way of doing this I would be forever in your dept.  
Comment
Watch Question

CERTIFIED EXPERT

Commented:
If you execute the script as the system does, aka with the "start" and "stop" arguments, does it still work for both?

/etc/rc3.d/S09myscript start
/etc/rc5.d/K01myscript stop

Open in new window

Author

Commented:
OK, this is interesting to me!
if I execute as you requested both will start tomcat?? I'm thinking my script to start is not complete does causing this. here is the script Im using in /etc/init.d/

#/bin/bash
###################################################################################::HEADER_END
#::DESCRIPTION_START
#
#::DESCRIPTION_END
#
#######################################################################################################

# Check for a running tomcat instance ...
BASHPID=$(pstree -a| grep "java -Xrs -Djava.endorsed.dirs=/opt/Torex/WebServer/common/endorsed -classpath/opt/Torex/libs")

if  [[ ! -z $BASHPID ]]  ; then
echo "Web server already running"

else
cd /opt/Torex && ./startWebServer.sh >> /opt/Torex/Application.log
fi
CERTIFIED EXPERT

Commented:
Okay, first things first, here's a slightly rewritten script that will take "start" and "stop" as arguments, which goes into /etc/init.d.  Please modify the stop() function to use your actual stop command.

After that, please make sure that the two commands I gave you in my first post are working properly.
#/bin/bash

if [ -z $1 ]; then
        echo "Usage: `basename $0` [start|stop]"
        exit 1
fi

case "$1" in
  start)
        # Check for a running tomcat instance ...
        BASHPID=$(pstree -a| grep "java -Xrs -Djava.endorsed.dirs=/opt/Torex/WebServer/common/endorsed -classpath/opt/Torex/libs")
        if  [[ ! -z $BASHPID ]]  ; then
                echo "Web server already running.  Exiting"
                exit 1
        else
                cd /opt/Torex && ./startWebServer.sh >> /opt/Torex/Application.log
        fi
        ;;
  stop)
        # CHANGE THIS TO WHATEVER YOUR SHUTDOWN COMMAND IS
        cd /opt/Torex && ./stopWebServer.sh >> /opt/Torex/Application.log
        ;;
esac

Open in new window

Author

Commented:
The start works, my problem is that the developers created the startWebServer.sh script but did not provide a stop script, can I eliminate the stop option?
CERTIFIED EXPERT

Commented:
Yes, just comment out these two lines:

#else
             #cd /opt/Torex && ./stopWebServer.sh >> /opt/Torex/Application.log

Now at least it won't try to start your process again when the system is shutting down

Author

Commented:
So, before I test the boot here is what I have, the updated script in /etc/init.d/
removed the K01 in rc5.d
S09 in rc3.d linked to the updated script
commented out the stop lines and the start as a command works.
a reboot should get it started or do I need more settings changed?
CERTIFIED EXPERT

Commented:
Right after the line that says "#/bin/bash" please add the code below. Then we'll see if it's actually being called or not after you boot.

If you boot, and the file is present but your program doesn't start, then please show me the last several lines of "/opt/Torex/Application.log"
# temporary debug to see if this script is actually being executed
echo "I was ran at `$date`" > /tmp/myprogram.debug

Open in new window

Author

Commented:
Looks like it is not being executed during boot here is the log,


**Nov 2, 2011 9:54:58 AM,ProcessManager:Start,2,Start Called: Process: EntityUpdator^M
Started: EntityUpdator
**Nov 2, 2011 9:54:58 AM,ProcessManager:Start,2,Start Called: Process: SoftwareUpdateProcess^M
Started: SoftwareUpdateProcess
CERTIFIED EXPERT

Commented:
Did the file "myprogram.debug" show up in /tmp?

Author

Commented:
Sorry I forgot to mention that, no it did not create the file in /tmp
CERTIFIED EXPERT

Commented:
Okay, so its not even running your init script.  Maybe you didn't make it executable?

The permissions should be:
-rwxr-xr-x. 1 root root 4600 Aug  3 03:55 yourscript

Please show me
ls -l /etc/init.d/yourscript

If it doesn't look like mine above, please do:
chmod 755 /etc/init.d/yourscript

Open in new window

CERTIFIED EXPERT

Commented:
Well, never mind that - if you can run it from the command line then I guess it is executable already.  Do instead for me:

ls -l /etc/rc3.d/S09yourscript

Open in new window

Author

Commented:
lrwxrwxrwx 1 root root 11 2011-11-02 06:42 rc3.d/S09rjtomcat -> ../rjtomcat
-rwxr-xr-x 1 root root 1804 2011-11-02 10:12 rjtomcat
they are both executable

Author

Commented:
if I go in to yast, System Services RunLevel it shows as one of the services however if I enable or disable it returns

¦/etc/init.d/rjtomcat start returned 1 (unspecified error):
CERTIFIED EXPERT

Commented:
I know why both are happening.

The unspecified error is probably because you don't have the various chkconfig attributes that you might see in the other scripts in /etc/init.d (look at the top 10 or 15 lines of one of the others, and you'll see what it needs to be manageable by yast)

Nevertheless, your symlink looks wrong.

You have /etc/rc3.d/S09rjtomcat ->../rjtomcat

According to that, its executing /etc/rjtomcat, which is not right, it should be /etc/init.d/rjtomcat

The symlink should look like:

rc3.d/S09rjtomcat -> ../init.d/tomcat

So do the command below and then make sure you can use the script "/etc/rc3.d/S09tomcat start" from the command line successfully
cd /etc/rc3.d
ln -sf ../init.d/rjtomcat S09rjtomcat

Open in new window

Author

Commented:
rc3.d is in /etc/init.d, so my script is in /etc/init.d

# ls -l /etc/init.d/ | more
-rwxr-xr-x 1 root root  9995 2010-05-05 07:31 rc
drwxr-xr-x 2 root root  4096 2011-10-25 09:20 rc0.d
drwxr-xr-x 2 root root  4096 2011-10-28 09:16 rc1.d
drwxr-xr-x 2 root root  4096 2011-10-28 09:16 rc2.d
drwxr-xr-x 2 root root  4096 2011-11-02 06:43 rc3.d
drwxr-xr-x 2 root root  4096 2011-10-28 09:16 rc4.d
drwxr-xr-x 2 root root  4096 2011-11-02 09:35 rc5.d
drwxr-xr-x 2 root root  4096 2011-10-25 09:20 rc6.d
drwxr-xr-x 2 root root  4096 2011-10-25 09:50 rcS.d
-rw-r--r-- 1 root root  7827 2010-05-05 07:31 README
lrwxrwxrwx 1 root root     4 2011-10-25 09:20 reboot -> halt
-rwxr-xr-x 1 root root  1804 2011-11-02 10:12 rjtomcat

Author

Commented:
# cd /etc/rc3.d
-bash: cd: /etc/rc3.d: No such file or directory

Author

Commented:
this type of data on the other scripts you refer to or actual code, just init info?

#!/bin/bash
#
# Network interface configuration
#
# Copyright (c) 2001-2002 SuSE Linux AG, Nuernberg, Germany.
# Copyright (c) 2003-2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
CERTIFIED EXPERT

Commented:
Okay, slightly different structure on yours than other sysv Linux setups.  Okay, give me a few minutes and I'll test it on my SuSE laptop and get back to you.

Author

Commented:
Thanks so much I appreciate all the help, take your time.
CERTIFIED EXPERT

Commented:
The section below is what I'm talking about - if you paste that into your script, I think then you'll be able to use Yast to add it to the system startup
### BEGIN INIT INFO
# Provides: rjtomcat
# Required-Start: $remote_fs $syslog 
# Required-Stop:  $remote_fs $syslog
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start my personal tomcat server
# Short-Description:   Start tomcat
### END INIT INFO

Open in new window

Normally, when you are creating startup scipts, SUSE has included a sample template file called /etc/init.d/skeleton

You can use this file as a template for your startup and shutdown script. This files follows the all the guide lines needed to create startup/shutdown script and to resolve dependency services to be started/stops before the required service is started or stopped.

This is the concept.

Thanks.
Kisor Kumar Das

Author

Commented:
It just wont work I can execute the script I have with the start and it will start execute without start it exits with error that start/stop is required it also starts when I enable it in yast, just will not work on reboot its killing me!
CERTIFIED EXPERT

Commented:
Can you please do the following commands and then paste the output?  If no errors, see if that changes your luck on a reboot?
update-rc.d rjtomcat defaults

Open in new window

Commented:
I have decided to change the Desktop Manager to KDE where I can add the scripts to the Autostart directory and its executing as needed. Thanks for the brainstorming I appreciate the input

Author

Commented:
I changed the DM on the OS where KDE provides the auto start process and my issue is resolved.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.