{"id":5111,"date":"2015-08-13T14:20:33","date_gmt":"2015-08-13T06:20:33","guid":{"rendered":"http:\/\/rmohan.com\/?p=5111"},"modified":"2015-08-13T14:20:33","modified_gmt":"2015-08-13T06:20:33","slug":"solaris-10-create-an-init-script","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5111","title":{"rendered":"Solaris 10 \u2013 create an init script"},"content":{"rendered":"<p>First of all, we need to understand the procedure of the boot in Solaris. Next, follows a description of the boot sequence in Solaris.<\/p>\n<h2>Overview of the boot sequence in Solaris<\/h2>\n<ul>\n<li>When Solaris boots up, it runs \u201cinit\u201d.<\/li>\n<li>\u201cinit\u201d looks in \/etc\/inittab to find out what runlevel it needs to boot into<br \/>\nOn Solaris, this is normally runlevel 3. On Linux, it is normally runlevel 5.<\/li>\n<li>\u201cinit\u201d reads a list of the programs it needs to start at each run-level from \/etc\/inittab<\/li>\n<li>On Solaris, init runs both \u201c\/sbin\/rc2? and \u201c\/sbin\/rc3?. On Linux, init runs only \u201c\/etc\/rc.d\/rc 3?.<br \/>\nNotice 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.<\/li>\n<li>\u201c\/sbin\/rc2? (\u201c\/etc\/rc.d\/rc 3? on linux) does the following:\n<ul>\n<li>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 \u201cstop\u201d.<\/li>\n<li>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 \u201cstart\u201d.<\/li>\n<\/ul>\n<\/li>\n<li>On Solaris, after \u201c\/sbin\/rc2? is complete, init runs \u201c\/sbin\/rc3? which does a similar thing, running the K* and S* scripts in \/etc\/rc3.d with the single arguments \u201cstop\u201d and \u201cstart\u201d respectively.<\/li>\n<\/ul>\n<p>A common technique for system administrators is to use a common location for application and services startup scripts. This location is\u00a0\u00a0\u201c\/etc\/init.d\u201d (\/etc\/rc.d\/init.d on Linux).<\/p>\n<p>Each script is capable of taking a single argument, which can be either \u201cstart\u201d or \u201cstop\u201d.<br \/>\nBased on the argument passed, the script \u201cdoes the right thing\u201d to stop or start an application or service.<\/p>\n<p>I have made a template for startup scripts, and I use it whenever I need to make a startup script<\/p>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2013 Template of startup script \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<\/p>\n<pre>#!\/bin\/sh<\/pre>\n<pre>case $1 in\u00a0\r\n'start')\u00a0\r\n# put startup command(s) here\u00a0\r\n;;\u00a0\r\n'stop')\u00a0\r\n# put shutdown command(s) here\u00a0\r\n;;\u00a0\r\n*)\u00a0\r\necho \"Usage: $0 start|stop\" &gt;&amp;2\u00a0\r\nexit 1\u00a0\r\n;;\u00a0\r\nesac\u00a0\r\nexit 0<\/pre>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2013End of Template \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<p>I copy this template to the directory \/etc\/init.d\/ with a name which defines the application. For example I used a name\u00a0<strong>dnssvc<\/strong>\u00a0for a startup script for multiple dns services.<\/p>\n<p>Now, we need this shell script to be executed each time the system boots. We can choose to have the \u201cinit\u201d 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.<\/p>\n<p>Here is the command that I used:<br \/>\n# ln -s \/etc\/init.d\/dnssvc \/etc\/rc3.d\/S93dnssvc<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First of all, we need to understand the procedure of the boot in Solaris. Next, follows a description of the boot sequence in Solaris.<\/p>\n<p> Overview of the boot sequence in Solaris When Solaris boots up, it runs \u201cinit\u201d. \u201cinit\u201d looks in \/etc\/inittab to find out what runlevel it needs to boot into On Solaris, this [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5111"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5111"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5111\/revisions"}],"predecessor-version":[{"id":5112,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5111\/revisions\/5112"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}