Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run levels and start/stop

Status
Not open for further replies.
Joined
Apr 13, 2004
Messages
316
Location
US
I am somewhat new to Solaris and am wondering how to handle the starting/stopping of applications upon system start/reboot.

I know that Solaris uses the S* and K* to start and stop applications, respectively. And also that the scripts are read alpha-numeric, e.g., S10apache is read before S15sendmail. I also know that custom scripts are put in /etc/init.d and linked to /etc/rc2.d or /etc/rc3.d.

One thing I am wondering looking at /sbin/rc2 is if I create a script in /etc/init.d do I have to name it something like ‘oracle.start.sh’ since I am not passing a start or stop?

for f in /etc/rc2.d/S*; do
if [ -s $f ]; then
case $f in
*.sh) . $f ;;
*) /sbin/sh $f start ;;
esac
fi
done

So if I name it /etc/init.d/oracle.start.sh then I would link it to /etc/rc2.d/S88oracle (or whatever number I choose). Is that correct?

Another thing I wonder is the /etc/rc2.d and /etc/rc3.d. If my servers are at run-level 3, do I link the start/stop scripts to /etc/rc2.d, /etc/rc3.d or both? A consultant with a company setting up the servers told me both because it depends. But my thought was that if you are at rc3 then it will run a K* or S* for rc3, rc2, rc1, rc0; and for a rc2 it would run rc2, rc1, rc0. Therefore if I link to /etc/rc2.d then my custom scripts would be started/stopped at either run-level 2 or 3. But he says not so. But he also said to me that max filesystem size is based on whether you run a 32- or 64-bit kernel, which in AIX is not true because it is based on filesystem type: JFS or JFS2, not on the kernel (I would think that is true for Solaris, too. Don’t know how it could be different).

Thanks!
 
if you arent passing it a start or stop when you run the script, then, it will pass it anyway, and *should* ignore the argument.

___________________________________
[morse]--... ...--[/morse], Eric.
 
You'll only need to put your startup script in /etc/rc2.d or /etc/rc3.d. As you guessed, your system goes through the various /etc/rc*.d directories during boot so you won't need it it both places. I'd recommend putting it in /etc/rc3.d. This way if you ever need to boot your system up with network services (TCP/NFS/etc) and you don't have your database running, you can just boot to run level 2.
 
Just to satifsy my thinking.

If a script is put in /etc/rc3.d and a system is started at run level 2, then the script won't be executed?

If a script is put in /etc/rc2.d and a system is started at run level 3, then the script is executed?

Also, if you don't pass start/stop to the script do you have to end the script in .sh? (I got this from the /sbin/rcX runtime script):
for f in /etc/rc2.d/S*; do
if [ -s $f ]; then
case $f in
*.sh) . $f ;;
*) /sbin/sh $f start ;;
esac
fi
done


Thanks!!
 
You are right:
If a script is put in /etc/rc3.d and a system is started at run level 2, then the script won't be executed.

If a script is put in /etc/rc2.d and a system is started at run level 3, then the script is executed.

if you don't pass start/stop to the script do you DONOT have to end the script in .sh.
From the syntax:
*.sh) . $f ;;
its seen the *.sh scripts will be sourced to the present shell.

Hope this will help.
-sbs
 
>> So if I name it /etc/init.d/oracle.start.sh then I would link it to /etc/rc2.d/S88oracle (or whatever number I choose). Is that correct?

do not forget to write a script that stopps Oracle and link it to /etc/rc0.d/K??oracle

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years
 
Why do I need to link it to /etc/rc0.d? I linked it to /etc/rc3.d/K60oracle.

Can you please provide a more detailed explanation of exactly how the start/stop are executed at run levels?

Thanks!!
 
when the system boots the init process looks at /etc/inittab

Code:
# grep initdefault  /etc/inittab
is:[b][COLOR=red]3[/color][/b]:initdefault:

default this system will boot to runlevel 3

to reach runlevel 3 which executables must be startet by init? look at /etc/inittab again, if column #2 contains a 3 then "execute" column #3

Code:
# grep 3  /etc/inittab
is:3:initdefault:
p3:s12[b][COLOR=red]3[/color][/b]4:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog
s2:2[b][COLOR=red]3[/color][/b]:wait:/sbin/rc2                    >/dev/msglog 2<>/dev/msglog </dev/console
s3:[b][COLOR=red]3[/color][/b]:wait:/sbin/rc3                     >/dev/msglog 2<>/dev/msglog </dev/console
sc:2[b][COLOR=red]3[/color][/b]4:respawn:/usr/lib/saf/sac -t 300
co:2[b][COLOR=red]3[/color][/b]4:respawn:/usr/lib/saf/ttymon -g -h -p "`uname -n` console login: " -T sun -d /dev/console -l console -m ldterm,ttcompat
#

in your case look at /sbin/rc3
Code:
        for f in [b][COLOR=red]/etc/rc3.d/K*[/color][/b]; do
                if [ -s $f ]; then
                        case $f in
                                *.sh)   .        $f ;;
                                *)      /sbin/sh $f stop ;;
                        esac
                fi
        done

        for f in [b][COLOR=red]/etc/rc3.d/S*[/color red][/b]; do
                if [ -s $f ]; then
                        case $f in
                                *.sh)   .        $f ;;
                                *)      /sbin/sh $f start ;;
                        esac
                fi
        done

this means rc3 is executing all Killscripts in /etc/rc3.d first THEN runs all Startscripts... (so if you want to be absolutely sure when you start Oracle at /etc/rc3.d/S99oracle there must not be any Oracle Instance running (maybe you need one temporarily on rc2) then you should create a /etc/rc3.d/K90oracle, if you do not do things like that you don't need a /rc3.d/K??oracle)

If you shutdown the machine running eg. "init 0" the init process will again look at /etc/inittab and will find
Code:
grep 0 /etc/inittab
p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog
s0:0:wait:[b]/sbin/rc0[/b]                     >/dev/msglog 2<>/dev/msglog </dev/console
fw:0:wait:/sbin/uadmin 2 0              >/dev/msglog 2<>/dev/msglog </dev/console
sc:234:respawn:/usr/lib/saf/sac -t 300
#

/sbin/rc0 is exactly the same mechanism like /sbin/rc3 except it is using /etc/rc0.d as a workingdir instead of /etc/rc3.d

(btw init 5 and init 6 will run through /etc/rc0.d, too. Look at /sbin/rc5 and rc6)

I hope you can understand what I am talking about in my "English"...

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years
 
Thank you, Franz.

Now one more question. What if someone runs 'shutdown' instead of 'init'? Does that look at the /etc/rc?.d? and which one(s)?

Thanks!!
 
man shutdown ;-)

I'm at home and I can not lookup myself, I THINK it's more or less a synonym

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years
 
The "shutdown" command encompasses the init command. Alls it does is basically a Do you want to do this? shutdown of the system where it allows you to set a grace period before it goes down, and also notifies all of the logged on users that the machine is going down in the grace period. Courteous admins will always do this when people are logged in.

___________________________________
[morse]--... ...--[/morse], Eric.
 
...But BOFH don't bother with such courtesy! :-)

Such is life.....

___________________________________
[morse]--... ...--[/morse], Eric.
 
well, shutdown is more or less a wrapper for init as navley wrote

Code:
admin6# which shutdown
/usr/sbin/shutdown
admin6# tail -5 /usr/sbin/shutdown
then
        /usr/bin/kill $pid1 $pid2 > /dev/null 2>&1
fi

/sbin/init ${initstate}
admin6#

BOFB (Bastarrd Operator from Bavaria) ;-)

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years
 
If your new to Solaris (or unix), I would recomend you install webmin.


Take a look, it's free & really easy to install and enables a novice to start managing a solaris system, while you get your command line skills up to speed.

-
| Mike Nixon
| Unix Admin
-------------
 
10 years AIX and about 6 months (not FT though) Solaris.

Thanks.
 
don't worry screwloose, when I change to AIX I know someone to ask the same "silly" questions... ;-)

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top