Solaris 10 – create an init script

First of all, we need to understand the procedure of the boot in Solaris. Next, follows a description of the boot sequence in Solaris.

Overview of the boot sequence in Solaris

  • When Solaris boots up, it runs “init”.
  • “init” looks in /etc/inittab to find out what runlevel it needs to boot into
    On Solaris, this is normally runlevel 3. On Linux, it is normally runlevel 5.
  • “init” reads a list of the programs it needs to start at each run-level from /etc/inittab
  • On Solaris, init runs both “/sbin/rc2” and “/sbin/rc3”. On Linux, init runs only “/etc/rc.d/rc 3”.
    Notice that on Solaris, there is a separate script for each runlevel, but on Linux there is only one script and it is passed a single argument telling it what run-level to process.
  • “/sbin/rc2” (“/etc/rc.d/rc 3” on linux) does the following:
    • reads a list of all the shell scripts matching the pattern /etc/rc2.d/K* (/etc/rc.d/rc3.d/K* on linux) and runs each of those programs with the single argument “stop”.
    • reads a list of all the shell scripts matching the pattern /etc/rc2.d/S* (/etc/rc.d/rc3.d/S* on linux) and runs each of those programs with the single argument “start”.
  • On Solaris, after “/sbin/rc2” is complete, init runs “/sbin/rc3” which does a similar thing, running the K* and S* scripts in /etc/rc3.d with the single arguments “stop” and “start” respectively.

A common technique for system administrators is to use a common location for application and services startup scripts. This location is  “/etc/init.d” (/etc/rc.d/init.d on Linux).

Each script is capable of taking a single argument, which can be either “start” or “stop”.
Based on the argument passed, the script “does the right thing” to stop or start an application or service.

I have made a template for startup scripts, and I use it whenever I need to make a startup script

——————– Template of startup script ——————————————-

#!/bin/sh
case $1 in 
'start') 
# put startup command(s) here 
;; 
'stop') 
# put shutdown command(s) here 
;; 
*) 
echo "Usage: $0 start|stop" >&2 
exit 1 
;; 
esac 
exit 0

——————–End of Template —————————————

I copy this template to the directory /etc/init.d/ with a name which defines the application. For example I used a name dnssvc for a startup script for multiple dns services.

Now, we need this shell script to be executed each time the system boots. We can choose to have the “init” program run this command in run-level 2 or run-level 3. I arbitrarily chose run-level 3, which means that I need to link the program from /etc/init.d into /etc/rc3.d.

Here is the command that I used:
# ln -s /etc/init.d/dnssvc /etc/rc3.d/S93dnssvc

The letter S defines that is a startup Script. If we wanted to write a Stop Script we should have named the link starting with the letter K. The number after the S letter gives the priority of the execution. A lower number means earlier execution at boot time. Two scripts can have the same number, and there is a deterministic way of execution but there is no way to explain it.

One Reply to “Solaris 10 – create an init script”

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove me that you are not a robot :) * Time limit is exhausted. Please reload the CAPTCHA.