4

I have a Solaris 10 test guest logical domain (LDom). I plan to have the network on this be reconfigured before rebooting using a startup script in /etc/rc0.d.

At the moment, when the system boots, everything in the startup script is run as I want it to be, except that the reboot does not occur.

I have created a test script, and stripped it of everything except the essentials:

#!/sbin/sh

# MAIN

case "$1" in
start)
   if [ -f /etc/DR_Network_Configured ]; then
      exit 0
   else
      touch /etc/DR_Network_Configured
      reboot
   fi
   exit 0
   ;;
*)
   echo "Usage: $0 { start }"
   exit 1
   ;;
esac
exit 0

If I run the script from the command line, /etc/rc0.d/S99testing start, the file /etc/DR_Network_Configured is created and the system immediately reboots, i.e. the desired behaviour.

However, if I remove the file /etc/DR_Network_Configured, shut the system down, and boot it again, the file /etc/DR_Network_Configured gets recreated by the script during boot, but no subsequent reboot occurs.

Is there a fail-safe mechanism to stop startup scripts from potentially causing infinite reboots? If so, is there a way around this?

3

I have tested moving this script from /etc/rc0.d to /etc/rcS.d, /etc/rc1.d, /etc/rc2.d and /etc/rc3.d with the following results:

  • /etc/rcS.d - same behaviour as /etc/rc0.d - /etc/DR_Network_Configured is created, but no reboot occurs.
  • /etc/rc1.d - /etc/DR_Network_Configured is not created, and no reboot happens.
  • /etc/rc2.d - /etc/DR_Network_Configured is created and the system is rebooted.
  • /etc/rc3.d - /etc/DR_Network_Configured is created and the system is rebooted.

To summarise, when the system is booted to its default (milestone/multi-user-server:default, similar to run-level 3), it executes startup scripts located in /etc/rc0.d, /etc/rcS.d, /etc/rc2.d and /etc/rc3.d, but not /etc/rc1.d.

The reboot and init commands do not work when run from a startup script in /etc/rc0.d, /etc/rcS.d (and possibly /etc/rc1.d although I can't confirm this as the startup script in this directory never ran). They do work when run from startup scripts in /etc/rc2.d and /etc/rc3.d.

I imagine that this is designed to prevent a system from constantly rebooting. Should an erroneous startup script in /etc/rc2.d or /etc/rc3.d put the system into an infinite reboot loop, then the system can be fairly easily be rebooted to the single-user milestone and the offending startup script disabled rather than having to locate alternate boot media to boot off, mount the root volume/disk and disable the offending script.

Based on the above, I have modified my network reconfiguration script as follows:

  1. Kept my script in /etc/rc0.d to change the network settings.
  2. Added a function to it so that if the system needs to be rebooted after reconfiguring the network, a new script /etc/rc2.d/S99reboot is created which will reboot the system.
  3. If the /etc/DR_Network_Configured file exists, and /etc/rc2.d/S99reboot exists, then remove the latter to avoid the system constantly rebooting.

My relevant code is:

#!/sbin/sh
reboot_script="/etc/rc2.d/S99reboot"

Create_Reboot_File ()
{
   echo "#!/sbin/sh" > $reboot_script
   echo "case \"\$1\" in" >> $reboot_script
   echo "start)" >> $reboot_script
   echo "  init 6" >> $reboot_script
   echo "  exit 0" >> $reboot_script
   echo "  ;;" >> $reboot_script
   echo "esac" >> $reboot_script
   echo "exit 0" >> $reboot_script
   chmod 740 $reboot_script
   chown root:root $reboot_file
}

case "$1" in
start)
   if [ -f /etc/DR_Network_Configured ]; then
      [ -f $reboot_script ] && rm $reboot_script
      exit 0
   else
      # My reconfigure network functions are here
      # ...
      touch /etc/DR_Network_Configured
      Create_Reboot_File
   fi
   exit 0
   ;;
*)
   echo "Usage: $0 { start }"
   exit 1
   ;;
esac
exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.