Operating System - HP-UX
1830957 Members
1877 Online
110017 Solutions
New Discussion

Re: Scripts to be automated after, Server Reboots

 
SOLVED
Go to solution
Shahbaz_1
Regular Advisor

Scripts to be automated after, Server Reboots

Hi,
I want to start some services, like application server, thru a shell script, immediately I reboot the server (hp unix 11).
Where should I specify the script name to be run immediately server comes up?

Thanks
Let's share the great thing "THE KNOWLEDGE"
6 REPLIES 6
Michael Tully
Honored Contributor

Re: Scripts to be automated after, Server Reboots

Hi,
Hi,

Automatic startup scripts are placed into
the /sbin/init.d directory. Also a symbolic
link is created in the /sbin/rc2.d or /sbin/rc3.d
directory pointing to the script.

For example if you had an application called x
you would have a startup script in /sbin/init.d/x
with a symbolicc link pointing to it from
/sbin/rc3.d/S501x and another script in
/sbin/rc2.d/K499x to stop it.
It is good practise to use these numbers that
add up to 1000. You will see that this occurs
for other applications that start and stop
on your server.

HTH
-Michael
Anyone for a Mutiny ?
Alexander M. Ermes
Honored Contributor

Re: Scripts to be automated after, Server Reboots

Hi there.
Check directory /sbin.
There you have some subdirectories named rc0.d and so on. the rcand the number represent the runlevel, where different services will be started. The original start script should be placed in /sbin/init.d Then you should place a softlink ( ln -s originalfile linkname )to your original startscript in rc3.d, because then your machine is in runlevel 3 and all necessary services have been started.
Rgds
Alexander M. Ermes
;-)
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Printaporn_1
Esteemed Contributor

Re: Scripts to be automated after, Server Reboots

addition to above post , there are /sbin/init.d/template that you can copy and modify to your own script.
then make link.
enjoy any little thing in my life
Michael Tully
Honored Contributor

Re: Scripts to be automated after, Server Reboots

Hi,

For a full understanding, here is link to a document that will explain it fully.

http://docs.hp.com/hpux/onlinedocs/os/startup.pdf

HTH
-Michael
Anyone for a Mutiny ?
Shahbaz_1
Regular Advisor

Re: Scripts to be automated after, Server Reboots

Hi Michael
Thanks lot, I just need some further clarifications, I am not a unix guy.
As I have to restart the datbase and other application services, imme after server starts up. I have a script called STARTALL.sh
so i have placed it in /sbin/init.d dir.
after this how should I create a link from /sbin/rc2.d dir?
is this is the only thing I have to do?

And one more thing, I saw there are many files in /sbin/init.d dir, does unix run all these files while starting up unix server?

Thanks & Regards
Syed
Let's share the great thing "THE KNOWLEDGE"
James R. Ferguson
Acclaimed Contributor
Solution

Re: Scripts to be automated after, Server Reboots

Hi Syed:

As already suggested, if you haven't, read either version of the document below. I???ll summarize the key points here.

/usr/share/doc/start_up.txt

http://docs.hp.com/hpux/onlinedocs/os/startup.html

The file /sbin/init.d/template is a good starting place for making your own start/stop scripts.

The /sbin/init.d directory contains all scripts used to startup and shutdown various subsystems.

Each script under /sbin/init.d should perform BOTH the startup and shutdown functions. In order to control the functionality within the script, each must also support standard arguments and exit codes. Scripts must be written for the POSIX shell. A template script may be found in /sbin/init.d/template.

There is no reason why the startup and shutdown script cannot start/kill multiple, but related processes. Remember to choose the appropriate rc.d directory -- one (1) is for core services; two (2) is for multiuser run-state; three (3) is for networked, multi-user; and four (4) is for graphical interfaces. Depending on the processes you are starting, or stopping, you want to make sure prerequisite services exist.

Each script in /sbin/init.d performs BOTH the startup and shutdown functions, and each will have two links pointing towards the script from /sbin/rc*.d: one for the start action and one for the stop action.

Start scripts begin with "S"; Kill (stop) scripts begin with "K". The order of execution for kill scripts is the reverse of the startup ones.

if a start script is placed in directory '/sbin/rc{X}.d' then its corresponding kill script is put in directory '/sbin/rc{X-1}.d'

A general rule-of-thumb is that the sequence number of the start script plus the sequence number of the kill script should add to 1000.

Subsystems should be killed in the opposite order they were started. This implies that kill scripts will generally not have the same numbers as their start script counterparts. If two subsystems must be started in a given order due to dependencies (e.g., S200sys1 followed by S300uses_sys1), the counterparts to these scripts must be numbered so that the subsystems are stopped in the opposite order in which they were started (e.g., K700uses_sys1 followed by K800sys1). The '1000' rule leads to this behavior.

Regards!

...JRF...