1834586 Members
2747 Online
110069 Solutions
New Discussion

Re: Init Run Levels

 
SOLVED
Go to solution
devshlom
Regular Advisor

Init Run Levels

Hi guys,

During installation I will have to install a service.
1. Can you give me a quick overview about the run-levels on HPUX 11.23 PARisc?
2. How do I create the S/K links on /sbin/rcX.d? is there any command for that, as the chkconfig on linux or create a soft link via "ln"?
3. Do you have a good HP documentation link for this subject?

tx.
34 REPLIES 34
Venkatesh BL
Honored Contributor
Mustafa Gulercan
Respected Contributor

Re: Init Run Levels

hi;

read the man page.
# man rc


regards,
mustafa
Kenan Erdey
Honored Contributor
Solution

Re: Init Run Levels

Hi,

run level directories contains scripts that will run while start up, while changing run levels ( up or down) or shutting down. While going down from rc3 to rc1 K scripts run, while going up from s1 to s3 S scripts run. S is for starting, K is for killing.

/sbin/init.d/ director is your directory where you'll put your script for start and kill. And the synax is below:



#!/sbin/sh

case "$1" in
start_msg)
echo "Start "
;;

stop_msg)
echo "Stop "
;;

'start')

;;
'stop')
# Stop the oracle databases

;;
esac

and after you should create links for Rc directories. change with appropriate file names. And also you may change run levels in which the service will be started and killed.

ln -s /sbin/init.d/ /sbin/rc3.d/S999

ln -s /sbin/init.d/ /sbin/rc3.d/K999

Kenan.
Computers have lots of memory but no imagination
Dennis Handly
Acclaimed Contributor

Re: Init Run Levels

>Kenan: And also you may change run levels in which the service will be started and killed.
ln -s ... /sbin/rc3.d/S999
ln -s ... /sbin/rc3.d/K999

Typically these numbers add to 1000, so that they are done in reverse order.

devshlom
Regular Advisor

Re: Init Run Levels

hi,

I wonder about those numbers... (Knnn/Snnn)
As I saw and also as dennis said, these number will complete to 1000.
For all the UNIX I know, the complition it to 100.

so,
1. are the lower number reserved for something?
2. what is the reason for these higer number?
3. if I have a service that for all the other UNIXes started at 91 and killed on 09 - what numbers you suggest me to set?

tx
devshlom
Regular Advisor

Re: Init Run Levels

and another important questions
1. if my service uses networking - basically I can start it on level 2 - don't I?
2. it this acceptable to do so?
3. I saw that most of the sevices/daemons don't have a kill script on level 0 - what should happen on system shutdown? (should I put K links on level 0, 1?

tx again
Dennis Handly
Acclaimed Contributor

Re: Init Run Levels

>1. are the lower number reserved for something?

No, except they are done first.

>2. what is the reason for these higher number?

The range from 000 to 999? For more choices.
Note these numbers are an illusion. The scripts are done in ascii order and the reverse.

>3. if I have a service that for all the other UNIXes started at 91 and killed on 09 - what numbers you suggest me to set?

Probably 901 and 009.

>1. if my service uses networking - basically I can start it on level 2 - don't I?

You have to order it after the networking starts.
devshlom
Regular Advisor

Re: Init Run Levels

what about level 0 and 1?
should I put K link there?
devshlom
Regular Advisor

Re: Init Run Levels

one more:

What about the fact that when I reboot the machine I don't see my product in the printed down list:
XXX daemon was stopped.........OK
bla bla is down................OK


should I do something specific in order to get in this list?
Dennis Handly
Acclaimed Contributor

Re: Init Run Levels

>what about level 0 and 1? should I put K link there?

rc(1M) says that S is at rcN.d and K is at rcN-1.d.

>What about the fact that when I reboot the machine I don't see my product in the printed down list: should I do something specific in order to get in this list?

Do you have start_msg & stop_msg entry as Kenan mentions?
devshlom
Regular Advisor

Re: Init Run Levels

>Do you have start_msg & stop_msg entry as Kenan mentions?

I don't use these names? should I? I have functions "stop" and "start"...

by the way.
I didn't understant the issue with init script:
If I want my service to be started for level 3 and above and be down for level 2 and below, where should I put my links? because somehow, when I'm on level 3 and I moved to level 4 with "init 4" the system runs my S link from rc4.d and fails.
shouldn't it recognize the the service is already up? should I remove the S link from rc4.d?

tx




James R. Ferguson
Acclaimed Contributor

Re: Init Run Levels

Hi:

The manpages for 'rc(1M)' and the original 10.0 whitepaper on system startup scripts (which *still* applies today) provide a complete overview of the requirements you should meet.

The "rule of 1000" as mentioned, the difference betweent the number assigned to a start script and a kill script is discussed.

Use '/sbin/init.d/template' as a starting model for any script you write. In this way, you will follow the essential rules noted in the documentation.

http://docs.hp.com/en/934/startup.pdf

http://docs.hp.com/en/B2355-60130/rc.1M.html

Regards!

...JRF...
devshlom
Regular Advisor

Re: Init Run Levels

1. I can go with this template but am I required to?
I already have a file that works on all the other platform. Can I make it work with minimal changes?
James R. Ferguson
Acclaimed Contributor

Re: Init Run Levels

Hi (again):

> I can go with this template but am I required to? I already have a file that works on all the other platform. Can I make it work with minimal changes?

You are *not* required to use the template, but you *are* required to follow the same logic. This logic is also discussed in the aforementioned documentation I cited.

Regards!

...JRF...
devshlom
Regular Advisor

Re: Init Run Levels

of course same logic!!!

but,
will it be acceptable to use a script that doesn't have "stop_message" and "start_message" for example (and "start_proc" instead "start")

do I have to use the rc.config.d/xxx file?

tx
James R. Ferguson
Acclaimed Contributor

Re: Init Run Levels

Hi (again):

> but, will it be acceptable to use a script that doesn't have "stop_message" and "start_message" for example (and "start_proc" instead "start")

NO. You need to look at the documentation and the 'template' logic. These requirements are clearly documented. If you want your script to participate in startup and shutdown in HP-UX then follow the HP-UX guidelines!

You are making this much more difficult than it needs to be.

> do I have to use the rc.config.d/xxx file?

This is somewhat optional. However, by declaring variables in a file in '/etc/rc.config.d/' you can easily disable your startup and shutdown script without having to unlink the 'sbin/rc?.d' files from the '/sbin/init.d/' script. Look at '/etc/rc.config.d/mailservs' and '/sbin/init.d/sendmail' for one example of this mechanism.

Regards!

...JRF...




devshlom
Regular Advisor

Re: Init Run Levels

ok man,
I understand that.

let me give you the following scenario:
I have script on /sbin/init.d
S link on rc3
K link on rc2

If I run /sbin/init.d/my_s start twice, in the second time, I failed with the msg that the service is alreay up.

BUT,
if I move from level 3 to level 2 (the service is still up), and if I move from level 2 to 3, the sys tries to start the service again and it gets error msg from service - but not from the script as I expected.
How can I avoid that?
Why the script doesn't avoid this case?

tx

James R. Ferguson
Acclaimed Contributor

Re: Init Run Levels

Hi (again):

> If I run /sbin/init.d/my_s start twice, in the second time, I failed with the msg that the service is alreay up.

Yes, that would be expected. You have done nothing to stop (kill) the first instance.

> BUT, if I move from level 3 to level 2 (the service is still up), and if I move from level 2 to 3, the sys tries to start the service again and it gets error msg from service - but not from the script as I expected.

Then your shutdown ("K"ill) script failed to stop the first instance of your process.

There are any number of good examples if you look at the scripts in the '/sbin/init.d' directory.

Regards!

...JRF...

devshlom
Regular Advisor

Re: Init Run Levels

Hi dude,

In my script, before starting it, I check that the service is yet up!
if it's up, I print the msg that the service is alreay started.
According to documentation (if I got it right) when I have S script on level 3 and K script on level 2, when I move from level 3 to 2, the Kill script on rc2.d shouldn't be invoked (only the K scripts from level 3)
that's why the service is still up when I moved from 3 to 2.
you understand my problem here?

also, I will look at more examples, but if you have some enlighment I will be happy to hear.

tx
James R. Ferguson
Acclaimed Contributor

Re: Init Run Levels

Hi (again):

Your kill script has a problem in stopping (killing) your process(es).

The 'rc' manpages are very clear: "If a start script link e.g., /sbin/rcN.d/S123test) in sequencer N has a stop action, the corresponding kill script should be placed in sequencer N-1 (e.g., /sbin/rcN-1.d/K200test). Actions started in level N should be stopped in level N-1"

Instead of testing your scripts by rebooting, start by using them from the command line to start and stop correctly.

When you are satisfied with their behavior there you can examine the '/etc/rc.log' and 'etc/rc.log.old' to see the actions taken during startup and shutdown.

Regards!

...JRF...
devshlom
Regular Advisor

Re: Init Run Levels

hi,

The main problem is that when I run those scripts from the command line everything works fine but when I run the *init* command I get the mentioned problem ....
That's the reason I'm digging in this.

tx again.

Dennis Handly
Acclaimed Contributor

Re: Init Run Levels

>when I run the *init* command I get the mentioned problem

Perhaps when you run it from the command line you should use env(1):
# env -i rc-script

This removes all of the environment variables and would be a better simulation of rc(1m).
devshlom
Regular Advisor

Re: Init Run Levels

b.t.w James,

why do you think I have a problem with the stop operation.
according to the documentation, when I move from level 3 to 2 - only the K script of level 3 should be invoked - isn't it?
should I put the K script also on level 3 instead on level 2?
devshlom
Regular Advisor

Re: Init Run Levels

tx Dennis,

Even with the *env -i rc-script* everything works great from the command line.
Any idea?