init-script failing because of /etc/rc.d/init.d/functions

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat init-script failing because of /etc/rc.d/init.d/functions
# 1  
Old 05-06-2011
init-script failing because of /etc/rc.d/init.d/functions

I encountered a problem on one of our database servers.

OS: CentOS 5.5 final
Kernel: 2.6.18-238.5.1.el5.028stab085.2 (OpenVZ kernel)

We wrote some DB-Start/Stop-scripts ("/db2/admin/scripts_dba/start_services.ksh" and ".../stop_services.ksh") to start the database instances. (Database instances are started with their own user, "dbwlpiopr" in this case.)

The scripts worked fine and i wrote an init-script to automate the process and used "chkconfig" to create the service:

Code:
#!/bin/sh
#
# chkconfig: - 95 02
# description: Starts and stops Oracle Services for dbwlpiopr
#

declare  PROG=oradb_dbwlpiopr
declare  RUNAS=dbwlpiopr
declare  STOP_SCRIPT=/db2/admin/scripts_dba/stop_services.ksh
declare  START_SCRIPT=/db2/admin/scripts_dba/start_services.ksh

if [ $UID -ne 0 ] ; then
     exit 127
fi

. /etc/rc.d/init.d/functions



start()
{
local -i RETVAL=0

action "Starting Oracle services for $RUNAS: " \
       "/bin/su -c $START_SCRIPT &> /dev/null - $RUNAS"
RETVAL=$?

if [ "$RETVAL" = 0 ] ; then 
     touch /var/lock/subsys/$PROG
fi

return $RETVAL
}



stop()
{
local -i RETVAL=0

action "Stopping Oracle services for $RUNAS: " \
       "/bin/su -c '$STOP_SCRIPT &> /dev/null' - $RUNAS"
RETVAL=$?

if [ "$RETVAL" = 0 ] ; then
     rm -f /var/lock/subsys/$PROG
fi

return $RETVAL
}




# main()

case "$1" in
     start)
          start
          ;;

     stop)
          stop
          ;;

     restart)
          stop
          start
          ;;

     *)
          echo $"Usage: $0 {start|stop|restart}"
          exit 1
          ;;

esac

exit 0

I tried the command

Code:
/bin/su -c '/db2/admin/scripts_dba/stop_services.ksh &> /dev/null' - dbwlpiopr

from command line and this worked fine too. Still, the command came back with an error:

Code:
# service oradb_dbwlpiopr start
Starting Oracle services for dbwlpiopr:  /etc/rc.d/init.d/functions: line 500: su -c '/db2/admin/scripts_dba/start_services.ksh &> /dev/null' dbwlpiopr: No such file or directory

After some debugging i found the following:

The culprit is the function "action()" in the sourced-in file "/etc/rc.d/init.d/functions", which starts around line 500. The relevant line looks like this:

Code:
action() {
[....]
"$@" && success $"$STRING" || failure $"$STRING"
[....]

There the line from the first script marked as "START_SCRIPT" (or "STOP_SCRIPT") should get executed - and in principle, it is. The problem is that the string which should be executed is quoted too much - the system doesn't try to execute "/bin/su" with some parameters, but the command completely - of course there is no file named "/bin/su -c ....".

I eliminated the problem changing the line in action() by preceding it with "eval":
Code:
action() {
[....]
eval "$@" && success $"$STRING" || failure $"$STRING"
[....]

but i feel a bit uneasy about the cure maybe being worse than the curse. I do not light-heartedly change the system itself and obviously people have written init-scripts successfully before my "invention" too.

Any suggestions?

bakunin
# 2  
Old 05-06-2011
Just an idea: since the shell doesn't differentiate between a command and a function, move the whole line to a function, and let action() execute that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Troubleshooting init.d script

This is what I did: 1. I wrote a simple init.d script (myscript.sh) 2. I placed it under /etc/init.d (where many other default scripts already are) 3. Set the perms to 755 4. Run: update-rc.d myscript.sh defaults I can run it perfectly by doing: /etc/init.d/myscript.sh start... (2 Replies)
Discussion started by: rlopes
2 Replies

2. Shell Programming and Scripting

Start up init d script

Hi All, I'm trying to build a start up script, wud be gr8 if any one can explain what the below field means and how can i check it for my script. DAEMON_PATH="/home/wes/Development/projects/myapp" DAEMON=myapp DAEMONOPTS="-my opts" NAME=myapp DESC="My daemon description"... (4 Replies)
Discussion started by: Karthick N
4 Replies

3. Shell Programming and Scripting

INIT Script Getting Executed Twice?

Hello All, I copied and pasted the "/etc/init.d/skeleton" file to a new one so I could create my own init script for a program. Basically the ONLY edit I made to the skeleton "template" so far was to search and replace "FOO" with "snort". *NOTE: I know there are a bunch of snort init scripts... (6 Replies)
Discussion started by: mrm5102
6 Replies

4. UNIX for Advanced & Expert Users

Init.d script stdout location

I'm looking into a Solaris(S10) startup problem, with a script configured to run in /etc/rc3.d. It's written to output trace information to a logfile using tee, but the file itself is clearly not being updated. Is there a default stdout/stderr location for startup scripts where the other branch of... (6 Replies)
Discussion started by: JerryHone
6 Replies

5. Red Hat

Unable to get $PWD value from script in /etc/init.d

Hi ppl hope to have your advice, i am run out of idea... I have 3 scripts: a.sh, b.sh, and c.sh a.sh resided in /etc/init.d b.sh and c.sh /opt/xSystem I intend to start my system with "service" command which will trigger my a.sh service a.sh start then. a.sh will trigger... (4 Replies)
Discussion started by: cielle
4 Replies

6. Solaris

What is the diffe b/w init s and init S

i did my research in finding the answer but couldn't find right one. Please give your inputs. (6 Replies)
Discussion started by: ranumala
6 Replies

7. UNIX for Advanced & Expert Users

Problem on init 0, execution is the same with init 6

Hi, I am experiencing a weird thing on my SUNFIRE machine with Solaris 9 OS. When I do init 0 to shutdown the machine to go to ok prompt, what it did was shutdown and reboot like an init 6 command do. I did check the corresponding rc scripts that were involved with init 0 and compared with rc... (2 Replies)
Discussion started by: Yenthanh
2 Replies

8. Red Hat

Difference between 'init s' and 'init 1'

What is the difference between 'init s' and 'init 1'. I know that both will work to change the current run level to single user mode. Is there any difference in those two commands? (5 Replies)
Discussion started by: praveen_b744
5 Replies

9. Linux

How to I change init levels after typing init 1

Dear all, I typed in init 1 on my redhat box as root and according to wikipedia (http://en.wikipedia.org/wiki/Runlevel): 1 Single-User Mode Does not configure network interfaces, start daemons, or allow non-root logins So now I can't connect back to it. How do I change the init back to 3?... (8 Replies)
Discussion started by: z1dane
8 Replies

10. UNIX for Advanced & Expert Users

Init 6 & Init 0 problem

Hi Expert, I have encountered some problem with my SUN system. Everytime when i issue command #init 6 OR #init 0 it just logout and prompt for login again instead of rebooting the server when run init 6 and system shutdown when run init 0.. I can only reboot the system using reboot ... Was... (6 Replies)
Discussion started by: sc2005
6 Replies
Login or Register to Ask a Question