Operating System - HP-UX
1821245 Members
2963 Online
109632 Solutions
New Discussion юеВ

Start & Kill scripts in rc*.d

 
SOLVED
Go to solution
Vibhor Kumar Agarwal
Esteemed Contributor

Start & Kill scripts in rc*.d

Hi,

I am trying to put start & kill files in rc*.d folders.

At the moment my S* scripts are getting executed from rc3.d, but K* scripts are not getting executed from and of the rc*.d folder.

Here is my script:
start)
echo "Start rc0 `date`" >> /etc/init.d/log
;;
stop)
echo "Stop rc0 `date`" >> /etc/init.d/log
;;
*)
echo Invalid $1 >> /etc/init.d/log
;;
esac

Have put the K scripts rc0.d, rc1.d, rc2.d & rc3.d
After the system reboot, i could see only "Start rc3" entry in my log file (/etc/init.d/log)

Could somebody help me in solving why the K scripts are not getting executed.

Thanks
Vibhor Kumar Agarwal
29 REPLIES 29
Steven E. Protter
Exalted Contributor

Re: Start & Kill scripts in rc*.d

Shalom,

There is a document on this, but here is the quick run.

Startup script must be in /sbin/init.d (HP-UX)

soft link the S start script in /sbin/rc3.d pointing to startup script.

Kill script is soft linked in /sbin/rc2.d pointing to the same script.

When starting from scratch:

cd /sbin/init.d
cp template myscript
# edit myscript
cd /sbin/rc3.d
ln -s /sbin/init.d/myscript S70myscript
cd /sbin/rc3.d
ln -s /sbin/init.d/myscript K30myscript

That is the basics.

SEP
hpuxadmin in gtalk
hpuxconsulting in yahoo messenger
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor

Re: Start & Kill scripts in rc*.d

Sounds like you need to spend some time with the rc man page. The scripts do not "go in" the rc directories. They exist in the /sbin/init.d directory and are linked into the appropriate rc?.d directories. That could be a major portion of your problem.


Pete

Pete
Mark S Meadows
Valued Contributor

Re: Start & Kill scripts in rc*.d

Hi Vibhor,

To ensure that you are conforming to the correct rules with regard to the shutdown "K" scripts do a "man rc" or refer to the following link, which is still relevant even though it relates to HP-UX 10.x :

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

Regards,

Mark
Administrating HP-UX systems for more years than I care to admit, but still enjoying it (most of the time!).
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

Thanks for the inputs.

I have made the changes according to the document, still can't get the K* scripts getting executed.

As you people have suggested, my scripts are in /sbin/init.d & all rc*d folers have links.

bash-2.05# find /sbin -name "K990server" -exec ls -l {} \;
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc2.d/K990server -> /sbin/init.d/server
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc1.d/K990server -> /sbin/init.d/server
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc0.d/K990server -> /sbin/init.d/server
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc3.d/K990server -> /sbin/init.d/server

bash-2.05# find /sbin -name "S990server" -exec ls -l {} \;
lrwxrwxrwx 1 root sys 19 Aug 28 16:47 /sbin/rc3.d/S990server -> /sbin/init.d/server


Any thoughts what i may be missing.
Vibhor Kumar Agarwal
Matti_Kurkela
Honored Contributor

Re: Start & Kill scripts in rc*.d

Please read /etc/rc.log to see any error messages your script may have caused.

The script you showed in your first message seems to be incomplete: the beginning of the "case" statement is missing. If your actual script has this error, this may cause strange behaviour.

MK

MK
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

That was a typo, the case statement is complete.

In /etc/rc.log, I could see a single entry of S990server without any error.
However, couldn't find a single entry of K990server.

What could be the reason.
Vibhor Kumar Agarwal
James R. Ferguson
Acclaimed Contributor

Re: Start & Kill scripts in rc*.d

Hi:

Are you replicating the same kill script at every run-level as your post suggests? If so, this isn't correct nor necessary.

Remember that the environment provided to the run-level scripts is sparse. That is, unless you specifically provide variables that you normally have in a login session, they will not be present. Too, the PATH is limited.

Does your script run successfully to kill your process(s) if you execute it at the commandline?

Regards!

...JRF...
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

Yes, at the moment i am linking the same script in every run level.

I couldn't figure out whether my service was getting stopped or just killed due to system boot.

Hence, at the moment this is my only script.
This doesn't have any command that should require the full path. The only ones used are "echo" & "date" which should be available to all environments.
Vibhor Kumar Agarwal
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

> Does your script run successfully to kill your process(s) if you execute it at the commandline?
Yes, if i run it, it adds the stop statement in /etc/init.d/log file.
Vibhor Kumar Agarwal
Patrick Wallek
Honored Contributor

Re: Start & Kill scripts in rc*.d

>>In /etc/rc.log,

For the K* scripts you need to look in /etc/rc.log.old.

When you reboot or shut down the system, entries for the shutdown (K* scripts) gets appended to the current /etc/rc.log.

When the system starts, /etc/rc.log gets moved to /etc/rc.log.old. So there will only be entries for Startup.
Pete Randall
Outstanding Contributor

Re: Start & Kill scripts in rc*.d

Time to return to the man page. This time pay particular attention to the "Script Output" section.


Pete

Pete
OldSchool
Honored Contributor

Re: Start & Kill scripts in rc*.d

"46 /sbin/rc3.d/K990server -> /sbin/init.d/server

bash-2.05# find /sbin -name "S990server" -exec ls -l {} \;
lrwxrwxrwx 1 root sys 19 Aug 28 16:47 /sbin/rc3.d/S990server -> /sbin/init.d/server
"

note that if you use S990server at run level 3, the usual kill script would be K010server at run level 3. Output from the kill script would be in th old log, as noted previously. In that way, they start in the numerical sequence indicated by the S# and stop in the reverse order (last started becomes the first stopped)
Tingli
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

I still say this, that the sum of S number and K number should be 1000.
Patrick Wallek
Honored Contributor

Re: Start & Kill scripts in rc*.d

>>I still say this, that the sum of S number and K number should be 1000.

That is the common convention, but it is not a system requirement.
OldSchool
Honored Contributor

Re: Start & Kill scripts in rc*.d

"I still say this, that the sum of S number and K number should be 1000."

As Patrick notes, that's the convention. I don't see any difference between that statement and what I illustrated, either.
James R. Ferguson
Acclaimed Contributor

Re: Start & Kill scripts in rc*.d

Hi:

>>I still say this, that the sum of S number and K number should be 1000.

If you examine the original whitepaper from 10.0 (referenced above and here) you will read:

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

/*begin_quote*/

Subsystems are killed in the opposite order they were started. This implies that kill scripts will generally not have the same numbers as their start script counterparts. For example, if two subsystems must be started in a given order due to dependencies (e.g., S111sys1 followed by S222uses_sys1), the counterparts to these scripts must be numbered so that the subsystems are stopped in the opposite order in which they were started (e.g., K555uses_sys1 followed by K777sys1). Also, kill scripts for start scripts in directory /sbin/rcN.d reside in /sbin/rc(N-1).d.

/*endof_quote*/

Hence, the "delta-of-1000" makes it easy to conform to this, given the 3-digit sequence number notation.

I would agree that for most folks with a small number of application scripts to start/stop, following this guideline (rule) may not make any difference.

Regards!

...JRF...
Tingli
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

Maybe the word "should" is too strong.
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

Okay,
Here is the present status:

Changed the script to comply with "Script Output" section of rc man page. Now i am just echoing messages & not redirecting.
case $1 in
start)
echo "Start Test Server `date`"
;;
stop)
echo "Stop Test Server `date`"
;;
*)
echo Invalid $1
;;
esac

Since adding up to 1000 is just a convention, I haven't changed that yet.

Below is the output of /etc/rc.log
[snip]
Invalid start_msg
Output from "/sbin/rc3.d/S990server start":
----------------------------
Start Test Server Mon Aug 31 13:00:26 IST 2009
[/snip]

The first line "Invalid start_msg" states i haven't implemented the start_msg call. Does it make any difference. The "start" call is getting executed which is what i need.

I am not getting a single of K in /etc/rc.log.old leave alone my script "K990server"

Any thoughts
Vibhor Kumar Agarwal
Suraj K Sankari
Honored Contributor

Re: Start & Kill scripts in rc*.d

Hi,

Did you checked the permission of your K script...
double check if you made any link.

Suraj
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

Yes,

bash-2.05# ls -l /sbin/init.d/server
-rwxrwxrwx 1 root sys 169 Aug 31 12:56 /sbin/init.d/server

Manually running the script with "start" & "stop" parameters echoes the desired output.
Vibhor Kumar Agarwal
Suraj K Sankari
Honored Contributor

Re: Start & Kill scripts in rc*.d

Hi,
Can you paste output of your Startup and Kill file both.

ls -l Sfile and ls -l Kfile

Suraj
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

bash-2.05# find /sbin -name "K990server" -exec ls -l {} \;
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc2.d/K990server -> /sbin/init.d/server
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc1.d/K990server -> /sbin/init.d/server
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc0.d/K990server -> /sbin/init.d/server
lrwxrwxrwx 1 root sys 19 Aug 28 16:46 /sbin/rc3.d/K990server -> /sbin/init.d/server

bash-2.05# find /sbin -name "S990server" -exec ls -l {} \;
lrwxrwxrwx 1 root sys 19 Aug 28 16:47 /sbin/rc3.d/S990server -> /sbin/init.d/server
Vibhor Kumar Agarwal
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Start & Kill scripts in rc*.d

Query:

I am giving "reboot" command. Does that make any difference?

eg: On Solaris to execute K* scripts you have to give "init 6" and not reboot.
Vibhor Kumar Agarwal
Dennis Handly
Acclaimed Contributor
Solution

Re: Start & Kill scripts in rc*.d

>I am giving "reboot" command. Does that make any difference?

Well, yes! reboot(1M) skips all of the rc(1m) processing. The proper command is: shutdown -r