1834174 Members
2609 Online
110064 Solutions
New Discussion

Startup script

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Startup script

Hi Guys,

I have created a script but wants to execute during booting of the hpux 11i.
Can anyone suggest how to achieve this on hpux 11i ?

Thanks,
Shiv
8 REPLIES 8
Steven E. Protter
Exalted Contributor
Solution

Re: Startup script

startup script itself resides in /sbin/init.d

It must contain a start section and a stop section. See /sbin/init.d/template for an example.

To actually have it do something, for example start a server process at run level 3 and stop it at run level 2, this is an example with the ficticous service schmo

cd /sbin/rc3.d
ln -s /sbin/init.d/schmo S990scho

cd /sbin/rc2.d

ln -s /sbin/init.d/schmo K110scho

The K kills and the S starts.

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
Eknath
Trusted Contributor

Re: Startup script

Hi Shiv,

Create a script which accepts start and stop as option for starting and stopping
(e.g. #script start =>will start the script)

Place this script in /sbin/init.d

Decide in which run level you want to start the script and any service and daemon required for script (e.g. inetd )Create a link in the run level directory
#ln -s /sbin/init.d/script /sbin/rc3.d/SXXXscript
XXX -is number which decides the order for executig the script (asending order) and S indicates the script will be started.

similarly for stopping use
#ln -s /sbin/init.d/script /sbin/rc2.d/KXXXscript
where XXX is again a no and K is to stop the script.

Cheers!!!
eknath
Nguyen Anh Tien
Honored Contributor

Re: Startup script

pls see my attached doc
HP is simple
Amit Agarwal_1
Trusted Contributor

Re: Startup script

Create your startupcsript based on /sbin/init.d/template. You can look at the other startu files for better understanding.

Copy your script in /sbin/init.d directory. Change the permission accordingly (execute permission is must)

Next is to decide at what runlevel the sscript should be executed. It depends on the nature of your scripts. If it depends on some subsystem to be up, then your script should be numbered in such a way as to exeute after that subsystem. Lets say the runlevel is N, that means the run level for stopping your script should be N-1.

Next is to decide the script number, this again depends on the dependencies of your script. Your start script number should be higher than that of any dependency script. Lets say you decide on M, then the kill script number would be 1000-M.

If you have configuration file, make sure to keep ti in /etc/rc.config.d/ directory. This will ensure that /sbin/rc source in your configuration before executing your script.
At the end the setup should look something like

/sbin/init.d/script

/sbin/rc{N}.d/S{M}script links to /sbin/init.d/script

/sbin/rc{N-1}.d/K{1000-M}script links to /sbin/init.d/script

You are done.

-Amit
Senthil Kumar .A_1
Honored Contributor

Re: Startup script

Hi Shiva,

The elegant way of running the script is to decide in which run level you want to start and use the /sbin/init.d, /etc/rc.config.d and /sbin/rc*.d paths as others have
suggested.

The other way would be to place a line for you script
in /etc/inittab file.

Please consult the man page of inittab for further details.

Regards.
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Ganesha Sridhara
Honored Contributor

Re: Startup script

Hello Shiv,

Please check the attachment.

Regards
Ganesha Sridhara
vinod_25
Valued Contributor

Re: Startup script

hi shiv

i will explain you in a 4 step process:

Step 1:Decide run level

a)whats started in run level2:
ls /sbin/rc2.d/S*
b)whats started in run level3:
ls /sbin/rc3.d/S*

it will list all the start process in that run level for eg;
/sbin/rc3.d/S100nfs.server

this file S100nfs.server is a link to /sbin/init.d/nfs.server

The start and stop scripts are numbered in such a fashion that their sum is 1000 for eg:

/sbin/rc3.d/S100nfs.server
/sbin/rc2.d/K900nfs.server

Step 2: write startup and shutdown script

you can use /sbin/init.d/template
copy this file as script name eg: web_server
and write a script

sample script
#!/bin/ksh
#
# Copyright(C) 2001 VERITAS Software Corporation. ALL RIGHTS RESERVED.

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

mode=$1
case "$mode" in
'start_msg')
echo "Start WEB Server"
exit 0
;;

'stop_msg')
echo "Stop WEB Server"
exit 0
;;
'start')
/bin/nohup /opt/HPweb/bin/web_server >/dev/null 2>&1 &
;;
'stop')
/opt/HPweb/bin/web_server -k
;;
*)
echo "Usage: \$0 { start | stop }"
exit 1
;;
esac
exit 0

Then create a config file /etc/rc.config.d/web_server to tell the above script where to find the daemon.and whether to start or stop ?
cat /etc/rc.config.d/web_server
#!/sbin/sh
# $Header: /kahlua_src/web/server/etc/webadmin 72.1 1999/09/16 03:51:04 lancer E
xp $
# WebAdmin application server configuration.
#
# WEB_SERVER: Set to 1 to start the WebServer application server.
#
WEB_SERVER=1

note: its always a better idea to turn the script to 0 rather than deleting or moving the script, if you dont want to run the script.

Step 3: Create symbolic links

This will cause the script to run at the right place in the boot and shutdown sequences.
start process:
ln -s /sbin/init.d/web_server /sbin/rc2.d/S900web_server

kill process:

ln -s /sbin/init.d/web_server /sbin/rc1.d/K100web_server

(This script is for starting the web_server on run level 2 and stopping it on run level 1)

Step 4: Test the script

test the script on a test server . start and stop the daemon, run the script manually
by

/sbin/init.d/web_server

Reboot the server

Hope I have given you the step by step procedure... if anything is missed out pls update me to correct myself...

Regards and all the best

Vinod

Cem Tugrul
Esteemed Contributor

Re: Startup script

it is a really useful doc and i sometimes
need to look again and again...
Good Luck,
Our greatest duty in this life is to help others. And please, if you can't