Operating System - HP-UX
1844867 Members
2499 Online
110233 Solutions
New Discussion

Re: Adding program to startup script

 
SOLVED
Go to solution
Jeffrey F. Goldsmith
Super Advisor

Adding program to startup script

I have a program (informix) that needs to be started on a new server in my office. I haven't done this in a couple of years and thought I would check to see if I am doing it correctly.

Here is the info on the current server:

/sbin/rc3.d/
lrwxr-xr-x 1 root sys 38 Oct 17 2004 S200.informix.rc -> /apps/informix/fnsbscripts/informix.rc
-rwxr-xr-x 1 root sys 3041 Jun 4 2003 S210.ifas.rc

/sbin/rc2.d/
lrwxr-xr-x 1 root sys 38 Oct 17 2004 K200.infxshdwn -> /apps/informix/fnsbscripts/informix.rc

Here is the commands that I think should be done to add them to the startup/shutdown scripts.

ln –s /apps/informix/fnsbscripts/informix.rc /sbin/rc3.d/S200.informix.rc
ln –s /apps/informix/fnsbscripts/informix.rc /sbin/rc2.d/K200.informix.rc


The only one that I am un sure of doing is the startup of the ifas.rc. How would I add that to the rc3.d?

Thanks for the help.

Jeff
13 REPLIES 13
Steven E. Protter
Exalted Contributor

Re: Adding program to startup script

Shalom,

to help i would like to see:

ll rwxr-xr-x 1 root sys 3041 Jun 4 2003 S210.ifas.rc

Need to know if the soft link is valid.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Geoff Wild
Honored Contributor
Solution

Re: Adding program to startup script

Well, first off, I would follow the standard whereby you place startup scripts in /sbin/init.d

Then in thos scripts, call /apps/informix/fnsbscripts/informix.rc

etc...

Example

/sbin/init.d/informix
#!/usr/bin/sh
#
# @(#) $Revision: 1.0 $
#
# NOTE: This script is not configurable! Any changes made to this
# scipt will be overwritten when you upgrade to the next
# release of HP-UX.
#

#
# Start Informix
#

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

rval=0
set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "ERROR CODE $x"
rval=1
fi
}

case $1 in
start_msg)
echo "Starting Informix."
;;

stop_msg)
echo "Stoping Informix."
;;

'start')
if [ -f /etc/rc.config.d/informix ] ; then
. /etc/rc.config.d/informix
else
echo "ERROR: /etc/rc.config.d/informix defaults file MISSING"
fi

if [ "$INFORMIX" -eq 1 ]; then
/apps/informix/fnsbscripts/informix.rc start /dev/null 2>&1" && echo informix started
set_return
else
rval=2
fi

;;

'stop')
if [ -f /etc/rc.config.d/informix ] ; then
. /etc/rc.config.d/informix
else
echo "ERROR: /etc/rc.config.d/informix defaults file MISSING"
fi

if [ "$INFORMIX" -eq 1 ]; then
/apps/informix/fnsbscripts/informix.rc stop && echo Informix stopped
set_return
else
rval=2
fi
;;

*)
echo "usage: $0 {start|stop}"
;;
esac

exit $rval




# cat /etc/rc.config.d/informix
#!/sbin/sh
# @(#) $Revision: 1.0 $
# Informixconfiguration.
#
# INFORMIX: Set to 1 to startInformix
#
INFORMIX=1


Rgds...Geoff


Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Jeffrey F. Goldsmith
Super Advisor

Re: Adding program to startup script

Steven,
Is this what you are asking for?


root: /sbin/rc3.d ==> ll
total 12
lrwxr-xr-x 1 root sys 23 Oct 17 2004 S100nfs.server -> /sbin/init.d/nfs.server
lrwxr-xr-x 1 root sys 38 Oct 17 2004 S200.informix.rc -> /apps/informix/fnsbscripts/informix.rc
lrwxr-xr-x 1 root sys 19 Oct 17 2004 S200tps.rc -> /sbin/init.d/tps.rc
-rwxr-xr-x 1 root sys 3041 Jun 4 2003 S210.ifas.rc
-rwxr-xr-- 1 root sys 2609 Feb 4 2002 S300.Openlink.rc
lrwxr-xr-x 1 root sys 30 Oct 17 2004 S600netwatch -> /etc/best/netwatch/netwatch.rc
lrwxr-xr-x 1 root sys 23 Oct 17 2004 S990dtlogin.rc -> /sbin/init.d/dtlogin.rc
root: /sbin/rc3.d ==> more S210.ifas.rc
#!/sbin/sh
#
# @(#) $Revision: 78.1 $
#
# NOTE: This script is not configurable! Any changes made to this
# script will be overwritten when you upgrade to the next
# release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
# is unbootable. Do not modify this script.

#
# Purpose: Start up IFAS deamons
#

# Allowed exit values:
# 0 = success; causes "OK" to show up in checklist.
# 1 = failure; causes "FAIL" to show up in checklist.
# 2 = skip; causes "N/A" to show up in the checklist.
# Use this value if execution of this script is overridden
# by the use of a control variable, or if this script is not
# appropriate to execute for some other reason.
# 3 = reboot; causes the system to be rebooted after execution.

# Input and output:
# stdin is redirected from /dev/null
#
# stdout and stderr are redirected to the /etc/rc.log file
# during checklist mode, or to the console in raw mode.

PATH=/usr/sbin:/usr/bin:/sbin
export PATH

# NOTE: If your script executes in run state 0 or state 1, then /usr might
# not be available. Do not attempt to access commands or files in
# /usr unless your script executes in run state 2 or greater. Other
# file systems typically not mounted until run state 2 include /var
# and /opt.

rval=0

# Check the exit value of a command run by this script. If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.

set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script FAILed
fi
}

# Kill the named process(es).
# $1=

killproc() {
pid=`ps -el | awk '( ($NF ~ /'"$1"'/) && ($4 != mypid) && ($5 != mypid)
){ print $4 }' mypid=$$ `
if [ "X$pid" != "X" ]; then
if kill "$pid"; then
echo "$1 stopped"
else
rval=1
echo "Unable to stop $1"
fi
fi
}


case $1 in
'start_msg')
# Emit a _short_ message relating to running this script with
# the "start" argument; this message appears as part of the checklist.
echo "Starting the IFAS daemons"
;;

'stop_msg')
# Emit a _short_ message relating to running this script with
# the "stop" argument; this message appears as part of the checklist.
echo "Stopping the IFAS daemons"
;;

'start')

# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi


# Execute the commands to start your subsystem
su - bsi -c ifasrc
su - testbsi -c ifasrc
su - devbsi -c ifasrc
/usr/openlink/bin/oplrqb -v
;;

'stop')
# source the system configuration variables
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi

# Check to see if this script is allowed to run...
if [ "$CONTROL_VARIABLE" != 1 ]; then
rval=2
else
:
# Execute the commands to stop your subsystem

fi
;;

*)
echo "usage: $0 {start|stop|start_msg|stop_msg}"
rval=1
;;
esac

exit $rval
root: /sbin/rc3.d ==>
DCE
Honored Contributor

Re: Adding program to startup script


Jeffrey,

there is a template in /sbin/init.d you can use to design the start/stop of informix
You place the startup and shutdown commands in one script, and the correct portion gets called depending on whether the system is starting or stopping

you can then use the same script to stop/start the app manually

i.e. /sbin/init.d/informix stop
/sbin/init.d/informix start

You link the /sbin/rcX.d files to the script in /sbin/init.d

If you really want to be correct, you place a flag file in /etc/rc.config.d that is used by the main script to determine if you want to even run it.

HTH
Dave

Tim Nelson
Honored Contributor

Re: Adding program to startup script

copy /sbin/init.d/template to /sbin/init.d/informix
edit /sbin/init.d/informix and add your startup script to the start secion and shutdown script to stop section. Change CONTROL_VARIABLE to whatever you like, i.e. INFORMIX
create /etc/rc.config.d/informix and set INFORMIX=1
chmod 775 /sbin/init.d/informix
ln -s /sbin/init.d/informix /sbin/rc3.d/S900informix
ln -s /sbin/init.d/informix /sbin/rc2.d/K900informix

Test.
/sbin/init.d/informix start
/sbin/init.d/informix stop

locating all startup controls in /sbin/init.d/ helps to keep things organized. ( you only have to look in /sbin/init.d/ to see what could be used at boot time.

Don't forget to set env and extra path statements in the scripts. Boot time runs with basic env.

James R. Ferguson
Acclaimed Contributor

Re: Adding program to startup script

Hi Jeff:

This is worth a quick read for a complete understanding of the startup paradigm:

http://docs.hp.com/en/934/startup.pdf

The manpages for rc(1M) also provide a brief(er) overview.

Yes, althoght the whitepaper is titled for 10x it *is* approriate for all releases since then, too.

Your start and kill script sequence numbers should differ by 1000 to keep your script in the proper relationship to others both as you startup and shutdown. Hence, for S200 at runlevel N you should use K800 at runlevel N-1.

Regards!

...JRF...
Jeffrey F. Goldsmith
Super Advisor

Re: Adding program to startup script

Thanks to all for the help. Here is a copy of my /sbin/init.d/informix and /etc/rc.config.d/informix files. Would you mind taking a look at them to see if I got them correct? Thanks.


root: /sbin/init.d ==> more informix
#!/sbin/sh
#
# @(#)B11.23_LR
#
# NOTE: This script is not configurable! Any changes made to this
# script will be overwritten when you upgrade to the next
# release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
# is unbootable. Do not modify this script.

#
# Start Informix
#

PATH=/usr/sbin:/usr/bin:/sbin
export PATH

rval=0
set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script FAILed
fi
}

case $1 in
'start_msg')
echo "Starting Informix."
;;

'stop_msg')
echo "Stopping Informix."
;;

'start')
if [ -f /etc/rc.config.d/informix ] ; then
. /etc/rc.config.d/informix
else
echo "ERROR: /etc/rc.config.d/informix defaults file MISSING"
fi

if [ "$INFORMIX" != 1 ]; then
/apps/informix/fnsbscripts/informix.rc start /dev/null
2>&1" && echo Informix started
set_return
else
rval=2
fi
;;

'stop')
if [ -f /etc/rc.config.d/informix ] ; then
. /etc/rc.config.d/informix
else
echo "ERROR: /etc/rc.config.d/informix defaults file MISSING"
fi

if [ "$INFORMIX" != 1 ]; then
/apps/informix/fnsbscripts/informix.rc stop && echo informix stopped
set_return
else
rval=2
fi
;;

*)
echo "usage: $0 {start|stop}"
rval=1
;;
esac

exit $rval
root: /sbin/init.d ==>


root: /etc/rc.config.d ==> more informix
#!/sbin/sh
#
# Revision: 1.0
#
# Informix configuration.
#
# INFORMIX: Set to 1 to start informix
#
INFORMIX=1

root: /etc/rc.config.d ==>




James R. Ferguson
Acclaimed Contributor

Re: Adding program to startup script

Hi Jeff:

Well, you have this negated:

if [ "$INFORMIX" != 1 ]; then

...You want to start or stop your database when equal one, as:

if [ "${INFORMIX}" -eq 1 ]; then

Regards!

...JRF...
Jeffrey F. Goldsmith
Super Advisor

Re: Adding program to startup script

I ran the stop scrip /sbin/init.d/informix stop and got the following error:

root: /sbin/init.d ==> /sbin/init.d/informix stop
/sbin/init.d/informix[28]: Syntax error at line 68 : `"' is not matched.
root: /sbin/init.d ==>


I took a look at the /sbin/init.d/informix file at line 68 but don't see a problem.

echo "usage: $0 {start|stop|start_msg|stop_msg}"

What could be causing this problem?

THanks
A. Clay Stephenson
Acclaimed Contributor

Re: Adding program to startup script

You are missing a closing quote somewhere in your script and the line number reported only indicates where the interpreter got lost. Examine each line and make sure that there are pairs of quotes.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Adding program to startup script

Hi Jeff:

Actually, the problem exists ~line 46:

2>&1" && echo Informix started

...should read:

2>&1 && echo Informix started

...that is, without the double-quote character.

*ALSO*: Please re-read my last post. Your testing of 'if [ "$INFORMIX" != 1 ]; then' is backwards from convention.

Regards!

...JRF...



Dave La Mar
Honored Contributor

Re: Adding program to startup script

Jeff -
I've attached an older HP doc that addresses startup programs. We're on 11.0, but still find the doc relevent.

Best of luck on this.

-dl
"I'm not dumb. I just have a command of thoroughly useless information."
Jeffrey F. Goldsmith
Super Advisor

Re: Adding program to startup script

I was able to get all the information needed to allow me to make some changes to my startup / shutdown scripts.