HP-UX has some nice features in their initialization scripts, but you have to be aware of them in order to take advantage of them.
One good starting point is the rc(1m) man page. The rc program is the actual program that does all of what we can initialization: that is, all of the startup processes, the rc.d directories, the symbolic links, the run levels – rc does all this. It is rc that init(1) calls to make it happen.
Also, the init scripts are not where you would first look – or second. The scripts live in /sbin/init.d. This directory contains all of the scripts (and no links). Then look at one of the scripts in order to determine what can be done with your own scripts – and to see if there are any new features.
There are several features of the HP-UX init script mechanisms that you can take advantage of:
- The /etc/rc.config.d directory – to set configurable parameters for each individual subsystem (usually as represented by a script)
- The startup and shutdown messages: these are formatted nicely and make for quick viewing of the startup or shutdown process
- Results: not just SUCCEED or FAIL but also N/A (Not Applicable) and others.
To use the /etc/rc.config.d directory, just source the appropriate configuration “script” into your environment. Then the appropriate variables will be set.
The startup and shutdown messages are exquisitely simple: instead of start and stop, the routine is called with start_msg and stop_msg. Respond to these subcommands by printing the appropriate text for a descriptive message. With these set, your init script will display its appropriate message when it is started or stopped during startup or shutdown.
Then the results of the script – which show up in the HP-UX startup or shutdown in the far right hand side of the line. The possible results are:
- (0) Subsystem was brought up (or down) successfully.
- (1) Subsystem encountered errors.
- (2) Subsystem was skipped, such as from configuration in the /etc/rc.config.d file or other reasons, and did nothing.
- (3) A reboot of the system is requested; rc(1m) will perform the actual reboot. /etc/rc.bootmsg will be displayed on the console prior to reboot, then deleted.
- (4) Subsystem was successful and started a process in the background.
Any return value larger than 4 is the same as 1: subsystem encountered errors.
Note, too – there is nothing that mandates that these must be shell scripts (except perhaps for rc.config.d file syntax). If you must, it could be a perl script – although a shell script is best. Just make sure to have the proper header so that the system doesn’t try to interpret your perl script as a shell script.
And a quickie tip for you! If you find yourself using a shell and are expecting to edit the history using vi – only to find that there is no history – you can find that your display no longer responds (!). In reality, the system is responding just fine, except you can’t see it (small things, right?). This is because the editing sequence for vi is ^[k (ESCape-K). This mucks up the display as it is not being handled by the shell but rather by the terminal display.
How to get out? I use the following command sequence: first, do a set command – then another. How does this work? Well, I can’t explain everything, but the first output from set will contain the ^[k sequence in it (look in the variable $_). My theory is that that is not the only place to find it. It also does not seem to matter what the second command is, just one with output (and not just a carriage return).
Anyone who feels the need for a challenge can research this – I just know it works, and can be typed very fast.
3 thoughts on “Writing HP-UX init scripts (and a tip!)”
The start was very good. However it’s not covering complete information. Like different levels of rc-scripts , different run levels , how to enter there etc
The focus was on how to write the startup scripts. HP-UX uses the standard AT&T System V runlevel mechanism, albeit in /sbin/init.d and /sbin/rc.* instead of /etc.