1832656 Members
3378 Online
110043 Solutions
New Discussion

Re: Startup Script

 
SOLVED
Go to solution

Startup Script

I have a program that I would like to start up when the system boots and I am a little shakey about how? I have looked @ some of the scripts in /sbin/rc2.d but don't want to screw anything up.

The way the program starts from command line is: uagent start

Again Thanks in advance :-)

DaveAA2
Whats it there for if you can't use it
7 REPLIES 7
Sanjay_6
Honored Contributor

Re: Startup Script

Hi Dave,

You can put the script "uagent" in /sbin/init.d. Net create a file in /sbin/rc2.d called Sxxxuagent. This should be linked to /sbin/init.d/uagent,

cd /sbin/rc2.d
ln -s /sbin/init.d/uagent Sxxxuagent

If the same script can be called with a stop command, add another entry to /sbin/rc1.d

cd /sbin/rc1.d
ln -s /sbin/init.d/uagent Kyyyuagent

The converntion is xxx+yyy=1000

If you use this, The application uagent will be started at run level 2 and will be shutdown at run level 1.

Hope this helps.

Regds
Mark Vollmers
Esteemed Contributor

Re: Startup Script

Dave-

If you look in /sbin/init.d, there is a file called template. You can use this to build your script. I would suggest just looking at the other scripts as well to get a feel for how to do it. As far as the number, the S900 level is free for user apps, so pick a number in there to use (we have apache launching under the S940apache script in /sbin/rc2.d). As long as you don't modify other files, you shouldn't screw up anything. Worst case, the app doesn't launch, and you go back and try again. Good luck!

Mark
"We apologize for the inconvience" -God's last message to all creation, from Douglas Adams "So Long and Thanks for all the Fish"
S.K. Chan
Honored Contributor

Re: Startup Script

If you look in at /sbin/init.d, there is a file called "template" which you can actually use for your startup program. Place your command appropriately and you would want to create a control file in /etc/rc.config.d and replace $CONTROL_VARIABLE with the variable name that you have chosen. Then follow Sanjay's procedure.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Startup Script

Okay Dave,

This is not difficult. Just because a script runs when you execute it via an interactive shell does not mean that it will execute correctly at startup. The main difference is that you need to make sure that your path is correctly set and exported. Do this somewhere explicitly in your script or use absolute pathnames. Any other environment variables that are normally set in your .profile need to also be explicitly set in your script as well.
By convention, any variables that your script needs are set in a file /etc/rc.config.d/myscript then /etc/rc.config.d/myscript is included in your actual script like this:
if [ -r /etc/rc.config.d/myscript ]
then
. /etc/rc.config.d/myscript

fi

You actual script should be installed in /sbin/init.d/myscript and then linked symbolically to the appropriate startup and shutdown directories. In your case, you decided to start in run level 2 so you need to stop in run level 1. You need to decide if your startup is dependent upon any other services and order your 'S' file so that it falls after any required scripts.

Let's say that you have determined myscript (uagent - in your case) needs to start after S950xxx has run. Let's then choose S952myscript as a file name and create the link.
ln -s /sbin/init.d/myscript /sbin/rc2.d/S952myscript

Now by cenvertion the 'S' Number + the 'K' number should add to 1000 and be zero-padded if necessary to 3 digits. This almost always insure the correct lexical order. Now let's create the kill script
ln -s /sbin/init.d/myscript /sbin/rc1.d/K048myscript

That's all there is to it, Clay


If you taken care of that, the rest is easy.

If it ain't broke, I can fix that.
Sanjay_6
Honored Contributor

Re: Startup Script

Hi Dave,

This might be userful,

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

Hope this helps.

Regds
James R. Ferguson
Acclaimed Contributor

Re: Startup Script

Hi Dave:

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...

Re: Startup Script

Well folks, once again you have been a great resource. I played around with the template and looked @ many of the examples in /sbin/init.d.
I now have a much better understanding of the whole process and I even got my software to run @ startup.
My script is a little crude in fact I am embarrased to show it, but it works.

Again thanks for the swift response :-)

DaveAA2
Whats it there for if you can't use it