I am running HPUX 11.11 (HPUX 11i) in a QEMU parisc virtual machine for a couple years now, as described here. It uses the classic rcX.d and init.d based approach for scripts to execute while starting up and shutting down.
# ls -l /sbin/init.d/rclocal
-r-xr-xr-x 1 bin bin 3297 Oct 14 18:13 /sbin/init.d/rclocal
The contents of this script, based off HP-provided example in /sbin/init.d/template, are:
#!/sbin/sh | |
# ***** | |
# /sbin/init.d/rclocal | |
# execute Linux-style rc.local on HP-UX 11.11 or other rc and init.d based | |
# Unix environments that don't support rc.local directly; see | |
# https://supratim-sanyal.blogspot.com/2021/10/linux-style-etcrclocal-for-hp-ux-1111.html | |
# ***** | |
# Allowed exit values: | |
# 0 = success; causes "OK" to show up in checklist. | |
# 1 = failure; causes "FAIL" to show up in checklist. | |
# 2 = skip; causes "N/A" to show up in the checklist. | |
# Use this value if execution of this script is overridden | |
# by the use of a control variable, or if this script is not | |
# appropriate to execute for some other reason. | |
# 3 = reboot; causes the system to be rebooted after execution. | |
# 4 = background; causes "BG" to show up in the checklist. | |
# Use this value if this script starts a process in background mode. | |
# Input and output: | |
# stdin is redirected from /dev/null | |
# | |
# stdout and stderr are redirected to the /etc/rc.log file | |
# during checklist mode, or to the console in raw mode. | |
PATH=/usr/sbin:/usr/bin:/sbin | |
export PATH | |
# NOTE: If your script executes in run state 0 or state 1, then /usr might | |
# not be available. Do not attempt to access commands or files in | |
# /usr unless your script executes in run state 2 or greater. Other | |
# file systems typically not mounted until run state 2 include /var | |
# and /opt. | |
rval=0 | |
# Check the exit value of a command run by this script. If non-zero, the | |
# exit code is echoed to the log file and the return value of this script | |
# is set to indicate failure. | |
#set_return() { | |
# x=$? | |
# if [ $x -ne 0 ]; then | |
# echo "EXIT CODE: $x" | |
# rval=1 # script FAILed | |
# fi | |
#} | |
# Kill the named process(es). | |
# $1=<search pattern for your process> | |
#killproc() { | |
# pid=`ps -el | awk '( ($NF ~ /'"$1"'/) && ($4 != mypid) && ($5 != mypid) ){ print $4 }' mypid=$$ ` | |
# if [ "X$pid" != "X" ]; then | |
# if kill "$pid"; then | |
# echo "$1 stopped" | |
# else | |
# rval=1 | |
# echo "Unable to stop $1" | |
# fi | |
# fi | |
#} | |
case $1 in | |
'start_msg') | |
# Emit a _short_ message relating to running this script with | |
# the "start" argument; this message appears as part of the checklist. | |
echo "Executing SANYALnet Labs /etc/rc.local" | |
;; | |
'stop_msg') | |
# Emit a _short_ message relating to running this script with | |
# the "stop" argument; this message appears as part of the checklist. | |
#echo "Stopping the <specific> subsystem" | |
echo "Executing SANYALnet Labs /etc/rc.shutdown" | |
;; | |
'start') | |
# source the system configuration variables | |
if [ -f /etc/rc.config ] ; then | |
. /etc/rc.config | |
else | |
echo "ERROR: /etc/rc.config defaults file MISSING" | |
fi | |
if [ -x /etc/rc.local ] ; then | |
. /etc/rc.local #IMP: the file is sourced | |
else | |
echo "ERROR: cannot execute /etc/rc.local" | |
fi | |
# Check to see if this script is allowed to run... | |
#if [ "$CONTROL_VARIABLE" != 1 ]; then | |
# rval=2 | |
#else | |
# | |
# Execute the commands to start your subsystem | |
#: | |
#fi | |
;; | |
'stop') | |
# source the system configuration variables | |
if [ -f /etc/rc.config ] ; then | |
. /etc/rc.config | |
else | |
echo "ERROR: /etc/rc.config defaults file MISSING" | |
fi | |
if [ -x /etc/rc.shutdown ] ; then | |
. /etc/rc.shutdown #IMP - the files is sourced | |
else | |
echo "ERROR: cannot execute /etc/rc.shutdown" | |
fi | |
# Check to see if this script is allowed to run... | |
#if [ "$CONTROL_VARIABLE" != 1 ]; then | |
# rval=2 | |
#else | |
#: | |
# Execute the commands to stop your subsystem | |
#fi | |
;; | |
*) | |
echo "usage: $0 {start|stop|start_msg|stop_msg}" | |
rval=1 | |
;; | |
esac | |
exit $rval |
Place symbolic links to the init script from the /sbin/rc3.d directory using the "ln -s" command so that there are two links pointing to the same target as below:
# ln -s /sbin/init.d/rclocal /sbin/rc3.d/K99rclocal
# ln -s /sbin/init.d/rclocal /sbin/rc3.d/S99rclocal
# ls -l /sbin/rc3.d/*rclocal*
lrwxrwxrwx 1 root sys 34 Oct 14 16:03 /sbin/rc3.d/K99rclocal -> /sbin/init.d/rclocal
lrwxrwxrwx 1 root sys 34 Oct 14 16:03 /sbin/rc3.d/S99rclocal -> /sbin/init.d/rclocal
Now we can create /etc/rc.local and /etc/rc.shutdown and put stuff to be executed during boot or shutdown respectively. It is important to remember these scripts are sourced by /sbin/init.d/rclocal, so we don't want to put in an exit statement in those scripts. Here are the minimal scripts I have currently.
# ls -l /etc/rc.local /etc/rc.shutdown
-rwxr-xr-x 1 root sys 173 Oct 14 15:38 /etc/rc.local
-rwxr-xr-x 1 root sys 220 Oct 14 15:42 /etc/rc.shutdown
/etc/rc.local
# This file is sourced from /sbin/init.d/rclocal
#PATH=/usr/sbin:/usr/bin:/sbin
#export PATH
date > /tmp/created-by-rc.local
sync;sync;sync
# DO NOT "exit"!
/etc/rc.shutdown
# This file is sourced from /sbin/init.d/rclocal
#PATH=/usr/sbin:/usr/bin:/sbin
#export PATH
date > /tmp/created-by-rc.shutdown
sync;sync;sync
# DO NOT "exit"!
That's it. Now /etc/rclocal should be executed during bootup and /etc/rc.shutdown during shutdown.