How to set up legacy services right on Solaris 10

I want to add auto startup and shutdown script to Solaris 10's legacy services as they run in Solaris 9 or in Linux.

To make this work, I created the crontrol script in /etc/init.d and then link it to /etc/rc0.d and /etc/rc2.d directories. rc0.d is for shutdown and rc2.d is for srat. After I reboot the Solaris 10 box, I went to /var/svc/log directory to check these log files: milestone-multi-user:default.log, rec5.log and so on. I have found that shutdown part in control script worked. But the startup part in the control script didn't work. The message was like: Excuting legacy init script "/etc/rc2.d/S99dbora", Oracle Startup: cannot start. In the next line, log file told me this: legacy init script "/etc/rc2.d/S99dbora" exited with return code 0. Why the second part of code in the same script worked (shutdown) and the first part (startup) didn't work? What is wrong on my settings? Anyone knows about this, please help. Thank you very much in advance.

After the server has booted and Oracle has failed to start, does running the start scripts work ?

ie:
/etc/rc2.d/S99dbora start

Test this and if it does, maybe it needs to run via rc3 not rc2

Take also into account that, when booting, is root who run the scripts. Perhaps you need to run your script as another user (oracle, for instance)...

Regards.

Tornado, grial:

Thanks so much for your advice. I have followed your instruction to test as:
/etc/rc2.d/S99dbora, returning message is: Oracle startup: cnanot start. Then I linked dbora to rc3.d as S99dbora and tested as /etc/rc3.d/S99dbora. I got the same message: Oracle startup: cannot start. Then I checked user to run the script. Since I created dbora as root user, etc - run by sys, rc2 - root, rc2.d - sys, rc3 -root, rc3.d - sys, S99dbora - root under rc2.d or rc3.d. These settings were generated by installation. Should I chown S99dbora to be run by oracle or group user dba? Thanks.

Try to run it like this:

su - oracle -c "/etc/init.d/dbora start"

or whatever Oracle is run as.
You may want to create a "wrapper" script to do so...

grial:

I run #su - oracle -c "/etc/init.d/dbora start". Returning message is: Ksh: /etc/init.d/dbora cannot execute. Because root is bash shell and oracle is korn shell, the dbora was created by root, not oracle. is this the reason? And what is the wrapper script?

That's, most probably, a perms issue. Just chmod it to allow execution to the Oracle user.

A wrapper script, in your case, would be another script that calls the original one using "su". That new script is the one you would use to start/stop Oracle during the boot process. For example:

#!/bin/ksh
/usr/bin/su - oracle -c "/etc/init.d/dbora $1"

grial:

Thanks a lot for the details. But I have some questions:

  1. Do you mean I can chmod dbora to allow everyone to execute. Or you mean I need to chown dbora from root to oracle. The dbora is the control script, I have linked it from /etc/init.d to /etc/rc0.d and /etc/rc2.d as S99dbora. If I chmod S99dbora to be executed by oracle user, will that work?

  2. Based on your code for wrapper script. I understand it is to use wrapper one to call control script-dbora. The dbora is under root. So I have to create this wrapper one as oracle user because #!/bin/ksh is korn shell for oracle. Am I right? Please clarify this for me. What does $1 represent for?

755 would be enough for /etc/init.d/dbora
No matter to what user it belongs with that perms.

Say you create the script I posted, and you call it calldbora.
Then this is the script you have to link to /etc/rc0.d and /etc/rc2.d (and delete the old ones).
$1 represets the first parameter passed to the script: start or stop :slight_smile:
But try first the "su" comand to test it :wink:

You can su in the script under the the start option in your case statement
All the rc scripts get run by the root user, so you don't need to chmod 755 your script. You don't need a wrapper and really shouldn't set it up like this, stick to the standard way of using rc boot up scripts, using a case statement with start/stop options.
Your rc start config is correct, its your script that is not working.

Here's a couple of old example oracle start scripts..

Installation instructions appear below each script

#!/sbin/sh
# Start/stop Oracle database(s) found in /var/opt/oracle/oratab
# NOTE that tns listener must start AFTER this script (S98tns start)
# and stop BEFORE (K20tns stop) this script.

case "$1" in
'start')
	su oracle -c "/oracle/app/oracle/product/8.1.6/bin/dbstart"
	;;
'stop')
	su oracle -c "/oracle/app/oracle/product/8.1.6/bin/dbshut"
	;;
*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit 0

Install this script as /etc/init.d/oracle then symlink it:

# link -s /etc/init.d/oracle /etc/rc2.d/S97oracle
# link -s /etc/init.d/oracle /etc/rc1.d/K21oracle
# link -s /etc/init.d/oracle /etc/rc0.d/K21oracle
# link -s /etc/init.d/oracle /etc/rcS.d/K21oracle
#!/sbin/sh
# Start/stop Oracle TNS listener
# NOTE that TNS listener must start AFTER dbstart (S97oracle start)
# and stop BEFORE (K20oracle stop).

/bin/logger $0 $1

case "$1" in
'start')
	su oracle -c "/oracle/app/oracle/product/8.1.6/bin/tnsctl start"
	;;
'stop')
	su oracle -c "/oracle/app/oracle/product/8.1.6/bin/tnsctl stop"
	;;
*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit 0

Install this script as /etc/init.d/tns then symlink it:

# link -s /etc/init.d/tns /etc/rc3.d/S98tns
# link -s /etc/init.d/tns /etc/rc1.d/K20tns
# link -s /etc/init.d/tns /etc/rc0.d/K20tns
# link -s /etc/init.d/tns /etc/rcS.d/K20tns

Tornado, grial:

Many thanks to both of you for your informative advice. You are right. The problem might be in my script. I am going to find the time to implement your code. Hereafter, I post my dbora script for your comments. I put all start and stop commands in one script. Also, in my $ORACLE_HOME/bin/dbstart script, the ORATAB=/etc/oratab, not in /var/opt/oracle/oratab. I copy oratab from /etc to /var/opt/oracle. Is this OK or I have to modify the ORATAB path to point to /var/opt/oracle. Please advise too.

#!/bin/sh
ORA_HOME=/u01/app/oracleproduct/10.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo " Oracle startup: cannot start"
exit
fi
case "$1" in
'start') # Start the Oracle database and listeners
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl start"
;;
'stop') # Stop the Oracle database and listeners
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl stop"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
;;
esac

Tornado, as you can read on my posts avobe, the script "dbora" is supposed to accept start/stop parameters. Assuming this, you don't need to use a "case" again inside the wrapper script. That's why just a "$1" is enough.

Yo DO need to set 555, at least, in the "dbora" script if you want to execute it as the Oracle user from the wrapper script. Obviously, you DO NOT need it on the wrapper script as long as it's executed by root.

Back to your script, duke0001, the problem seems to be that the file /u01/app/oracleproduct/10.2.0/db_1/bin/dbstart does not exist. Check it and, for now, forget everything about the wrapper script. :slight_smile:

grial:

/u01/app/oracle/product/10.2.0/db_1/bin/dbstart script do exist. I can manually execute it and I have tried a couple of times, it work perfectly. Thanks.

mmm... that's a weird thing if, as you've posted, you are getting the message "Oracle startup: cannot start". That looks like failing on:

if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo " Oracle startup: cannot start"
exit
fi

Just remove this part if you are sure about /u01/app/oracle/product/10.2.0/db_1/bin

grial:

You are right. This may be the reason. I will remove " exit " and test script again. Then I will come back to report result. Thanks for your help.

grial, Tornado:

You know what. I make it work. The problem is in the $ORACLE_HOME directory. I made a typo as /oracleproduct/. It should be /oracle/product. This is why dbstart can not be found and be started. After I put correct path. It works. Oracle DB, listener, em and isqlplus all automatically started. Anyway, thanks for your help and I have learned a lot from you.