1833978 Members
2244 Online
110063 Solutions
New Discussion

Startup scripts

 
SOLVED
Go to solution
Matthew Couper
Frequent Advisor

Startup scripts

I'm trying to add a custom script into to the system boot. If I'm not mistaken, I should only have to link the script to the proper rc directory like so

ln -s /path/to/script /sbin/rc3.d/S999script.name

This is a script that starts and runs fine from the command line, but addinig to startup will be very useful. Is this correct or am I way off and risk hanging the boot like this? As you can see I want it to be the last thing that starts at boot time.
11 REPLIES 11
Michael Tully
Honored Contributor

Re: Startup scripts

For consistancy purposes the script really should be in /sbin/init.d with the link in /sbin/rc?.d/S999scriptname.
Did you use the template startup script as a guide in /sbin/init.d ? If not there could be something wrong. You may wish to post a copy here.
Anyone for a Mutiny ?
Sundar_7
Honored Contributor

Re: Startup scripts

The /sbin/rc script executes the script with "start" as the argument if the link starts with S and executes the script with "stop" as the argument if the link starts with "K".

As suggested, copy /sbin/init.d/template and include the script commands in the "start" section of the template.

Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Startup scripts

HP-UX does things a little differently that other UNIX flavors. You should really put your script in /sbin/init.d and softlink your Snnn startup and Knnn kill scripts to this file in /sbin/init.d. There is a template in /sbin/init.d that you should copy and use as a model. One difference in HP-UX is that in addition to the traditional "stop" and "start" arguments, "stop_msg" and "start_msg" arguments are also supplied by rc. That's where those [BUSY] [WAIT] [OK] startup/shutdown messages come from.

By convention, the startup and kill values should add to 1000. This tends to order the startup/shutdown sequences nicely. For example if you link:
ln -s /sbin/init.d/myscript /sbin/rc3.d/S999myscript

You should link a kill script in run-level -1
ln -s /sbin/init.d/myscript /sbin/rc2.d/K001myscript

Make sure that you set and export and needed environment variables including PATH or you may find that the command will work perfectly when executed manually (when you have a nice PATH, etc.) but fail when rc'ed.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Startup scripts

HP-UX does things a little differently that other UNIX flavors. You should really put your script in /sbin/init.d and softlink your Snnn startup and Knnn kill scripts to this file in /sbin/init.d. There is a template in /sbin/init.d that you should copy and use as a model. One difference in HP-UX is that in addition to the traditional "stop" and "start" arguments, "stop_msg" and "start_msg" arguments are also supplied by rc. That's where those [BUSY] [WAIT] [OK] startup/shutdown messages come from.

By convention, the startup and kill values should add to 1000. This tends to order the startup/shutdown sequences nicely. For example if you link:
ln -s /sbin/init.d/myscript /sbin/rc3.d/S999myscript

You should link a kill script in run-level -1
ln -s /sbin/init.d/myscript /sbin/rc2.d/K001myscript

Make sure that you set and export any needed environment variables including PATH or you may find that the command will work perfectly when executed manually (when you have a nice PATH, etc.) but fail when rc'ed.
If it ain't broke, I can fix that.
Sundar_7
Honored Contributor

Re: Startup scripts

One more thing, /sbin/rc determines whether the script execution is successful or not based on the exit value.

an exit value of 3 from your script would mean the system will keep rebooting :-).

an exit value of 1 means failure, 2 means the script execution is skipped based on setting in some configuration file the script uses. (the startup scripts source /etc/rc.config.d/* files).
Learn What to do ,How to do and more importantly When to do ?
Con O'Kelly
Honored Contributor

Re: Startup scripts

Hi

I've attached a document on startup that provides excellent info on how startup/shutdown scripts work under HP-UX.

Cheers
Con
Robert True
Frequent Advisor

Re: Startup scripts

This is off-thread, but Con, can you supply the link to the complete Doc that you attached Chap3 from? Got it somewhere, on some system, but I've lost it.

Thanks,
Rt.
Matthew Couper
Frequent Advisor

Re: Startup scripts

Thanks everyone, very helpful indead (even helped me on another issue I had!)

You've given me more then enough to get in the right direction on this, thanks so much!

If I have any other questions I'll post them here

(and Clay, no points for double posting! =)
Matthew Couper
Frequent Advisor

Re: Startup scripts

I'm stumped on the template file, what is the CONTROL_VARIABLE for? Should that be changed or is the default fine for that?
Matthew Couper
Frequent Advisor

Re: Startup scripts

I think I found my answer, the CONTROL_VARIABLE is used to determine if this should run or not.
So say I make a new script from the template and call it "start_script" and I use RUN_IT for the control variable, I need another file in /etc/rc.config.d called "start_script" and in there is a line that says RUN_IT=1 which say to run the script, if the 1 was a 0 it would skip running the script.

Is that run-on sentence the correct pattern (other then the obvious grammar errors)?
Sundar_7
Honored Contributor

Re: Startup scripts

Yes you are right on ! :-)

# vi /etc/rc.config.d/myapp
RUN_IT=1
#

# vi /sbin/init.d/myapp
- Replace CONTROL_VARIABLE with RUN_IT

create sym links in /sbin/rc3.d to start and in /sbin/rc2.d (or below) to shutdown the application.
Learn What to do ,How to do and more importantly When to do ?