Operating System - HP-UX
1820038 Members
3080 Online
109608 Solutions
New Discussion юеВ

My script in /sbin/init.d does not seem to be executing.

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

My script in /sbin/init.d does not seem to be executing.

Hi All,

I have written script and placed it in /sbin/init.d. And then rebooted the machine, but the script does not seem to be executing.

I checked the file /etc/rc.log in which i found no information regarding the script i have written.

In script there are some echo statements, i am not seeing them printed on startup.

Can any one help?

Thanks in advance.
Prasad
17 REPLIES 17
Luk Vandenbussche
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Hi,

Did you create a link in the directory /sbin/rc2.d to this script.

This link must be made before the script is executed at startup time
Muthukumar_5
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

You have to link to /sbin/rc.d/ directory.

For example:
/sbin/rc3.d/S100nfs.server -> /sbin/init.d/nfs.server

Read rc man page.

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Hi Prasad,

You can take a look at this thread

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=480208
[Subject: Proper Way of Adding rc Startup Scripts on HPUX ]


-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Antonio Cardoso_1
Trusted Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Hi Prasad,

putting a script in /sbin/init.d is not enough,
you also need to place a link in /sbin/rc.d/ according to run-level and order you want it to be started.

For example, /sbin/rc3.d contains:
S100nfs.server S823hpws_apache S823hpws_webmin S823hpws_xmltools S990dtlogin.rc
S200tps.rc S823hpws_tomcat S823hpws_webproxy S900mysql S99prngd.rc

if you want your application to be started after all other initialisations, you may add a S999myapp link to your /sbin/init.d script

Also remember to add a killing link in run-level -1 (i.e. rc2.d in this example).

Consider reading the following man pages:
- init
- rc
- inittab

antonio.
sysadm_1
Valued Contributor

Re: My script in /sbin/init.d does not seem to be executing.


Hello prasad,

after creating the script,you have to make a link to a particular run level folder.like /sbin/rc1.d /sbin/rc2.d etc.
you have to make a S link for startup and K link for shutdown.Start up program execute S link and shutdown program execute K link.

csysadm

Prasad Joshi
Regular Advisor

Re: My script in /sbin/init.d does not seem to be executing.

Thanks a lot instant replay

This what i have done

1. I placed the script in /sbin/init.d
2. Created a link from /sbin/rc3.d
3. And rebooted the machine,

this is the output related to my script from /etc/rc.log


Starting the subsystem
Output from "/sbin/rc3.d/S999SUpDown start":
----------------------------
"/sbin/rc3.d/S999SUpDown start" SKIPPED

I think still there is some problem can any one help?

Thanks a lot.
Regards,
Prasad
Peter Godron
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Prasad,
could you please provide the output from command:
ls -l /sbin/rc3.d/S999SUpDown
and
ls -l /sbin/init.d/your_file
Muthukumar_5
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Your script is failing some where. Try to open the script with editor and search for the string "SKIP"? Are you able to identify it. Else post that script.

--
Muthu
Easy to suggest when don't know about the problem!
Peter Godron
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Prasad,
check you have a file in /etc/rc.config.d

For details please see:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=310066
James R. Ferguson
Acclaimed Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Hi Prasad:

The notation of "SKIPPED" in '/etc/rc.log' suggests that your script exited with a return value of two (2). This is standard behavior as described in '/sbin/init.d/template'. Perhaps you have never setup a contol variable in a file in '/etc/rc.config.d/'. Perhaps you used, but never finished customizing, '/sbin/init.d/template' for your purposes.

Regards!

...JRF...
Prasad Joshi
Regular Advisor

Re: My script in /sbin/init.d does not seem to be executing.

Thanks for replay.
These are permissions

bash-2.02# ls -l /sbin/init.d/SUpDown
-rwxr-xr-x 1 root sys 3616 Apr 5 16:31 /sbin/init.d/SUpDown


bash-2.02# ls -l /sbin/rc3.d/S999*
lrwxr-xr-x 1 root sys 20 Apr 5 16:31 /sbin/rc3.d/S999SUpDown -> /sbin/init.d/SUpDown


I will search the script for word "SKIP"

Thanks & regards,
Prasad
Muthukumar_5
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Did you read rc man page?

2 Script was skipped due to overriding control variables from
/etc/rc.config.d files, or for other reasons, and did not
actually do anything.

You are having a variable that decides the script execution. Try to create a file or update available file in /etc/rc.config.d/.

It will work.

--
Muthu
Easy to suggest when don't know about the problem!
Peter Godron
Honored Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Prasad,
many thanks for the ls -l listing, just confirming execute privs and link status.

Re /etc/rc.config.d see my earlier posting.
Prasad Joshi
Regular Advisor

Re: My script in /sbin/init.d does not seem to be executing.

Hi Muthu/James/Peter,

Thanks for your replay.

I copied the standard pattern from /sbin/template.

I have not customized it, only changed some part.

I am not getting how a file in /etc/rc.config.d is linked with my script.

What should be the name of the file in /etc/rc.config.d ? Is there any naming convention should i follow?

Thanks & regards.
Prasad
James R. Ferguson
Acclaimed Contributor

Re: My script in /sbin/init.d does not seem to be executing.

Hi Prasad:

Yes, the standard is to name the configuration file in '/etc/rc.config.d' the same as the executable in '/sbin/init.d'. Too, the start and stop links in '/sbin/rc?.d' should also (ideally) contain the same character string. The 'cron' scripts are a good example:

/sbin/init.d/cron
/etc/rc.config.d/cron
/sbin/rc1.d/K270cron
/sbin/rc2.d/S730cron

If you haven't already noticed, there is the "rule-of-1000" which says that the sum of the Kill sequence number and the Start sequence number should equal 1000. In this way all scripts shutdown or startup in the same sequence of relationships.

An old, but very well written discussion can be found here:

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

Regards!

...JRF...
Tor-Arne Nostdal
Trusted Contributor
Solution

Re: My script in /sbin/init.d does not seem to be executing.

Hi Prasad
I noticed that you booted the system to see how your script would work.

You can check if the script works for starting/stopping your service, before you restart the system.

If you have written the script correctly, you should be able to run it, simply by:
/sbin/init.d/SUpDown start_msg
/sbin/init.d/SUpDown start
echo $? #to see the return code
and/or
/sbin/init.d/SUpDown stop_msg
/sbin/init.d/SUpDown stop
echo $? #to see the return code

You should not link into the runlevel directories /sbin/rc*.d/ before this is ok.

The start_msg/stop_msg is the messages you would see on the console.
-----
I also noted that you use bash as your command shell.
Be aware that the start/stop scripts should be written as sh-posix(see man pages) scripts.
Check also that the shell is specified in the first line (a copy of the template file, would have this line)
#!/sbin/sh
------
A brief syntax check of the script can be made with command: sh -n /sbin/init.d/SUpDown
This does not run the script.
To see how the script execute, use: sh -x /sbin/init.d/SUpDown
------
As James already pinpointed, the exit code from the script is 2.
You should create a file named /etc/rc.config.d/SUpDown
This file normally contain environment variables for the start/stop script (/sbin/init.d/SUpDown).
The minimum is one control variable indicating if you want the service to be controlled by the startup/shutdown process.
example:
echo '# STARTUP SupDown 1=true 0=false' >/etc/rc.config.d/SUpDown
echo 'SUPDOWN=1' >> /etc/rc.config.d/SUpDown

Then edit the /sbin/init.d/SUpDown file and replace the CONTROL_VARIABLE with SUPDOWN
(it should be two occurances)
--------
Finally remember that if your script depends on other services (like nfs) you must check the start/stop sequence (filenames/number in the /sbin/rc*.d) appropriately.

/Tor-Arne
I'm trying to become President of the state I'm in...
Prasad Joshi
Regular Advisor

Re: My script in /sbin/init.d does not seem to be executing.

Thanks a lot to all.

I am doing testing, and in the part of that i need to reboot a machine continuously. I wanted to write the script for the same.

I have written a script, but it does not seem to be working.

I am copying the script here.

First Script
************
This is an initial script which perfroms copying of the files to the remote machine in appropriate directories, making soft links etc.

prasad:/MyUpdown # cat UpDown
#!/bin/csh
set user=`whoami`
if ( $user == "root" )then
if ( $#argv < 2 ) then
echo "Usage: UpDown start|stop> "
exit 1
endif
else
echo "Only root user can use this script."
exit 1
endif

set option = $argv[1]
shift

echo "Driver: 10.216.59.00" > updown
echo "Path: $PWD" >> updown

switch ($option)
case "start":
while($#argv > 0)
set sys = $argv[1]
echo "Working With : $sys"
touch ${sys}
scp ./updownconf ${sys}:/etc/rc.config.d/
if ( $? != 0 ) then
echo "Unable to COPY Configuration files to ${sys}"
exit 1
endif
scp ./SUpDown ${sys}:/sbin/init.d
if ( $? != 0 ) then
echo "Unable to COPY Script files to ${sys}"
exit 1
endif

ssh ${sys} "ln -s /sbin/init.d/SUpDown /sbin/rc3.d/S999SUpDown"
if ( $? != 0 ) then
echo "Unable to Create START Links on ${sys}"
exit 1
endif

ssh ${sys} "ln -s /sbin/init.d/SUpDown /sbin/rc2.d/K1SUpDown"
if ( $? != 0 ) then
echo "Unable to Create KILL Links on ${sys}"
exit 1
endif

scp ./updown ${sys}:/tmp/
if ( $? != 0 ) then
echo "Unable to COPY files to ${sys}"
exit 1
endif

ssh ${sys} "sync ; sync ; sync ; reboot"

shift
end

breaksw
case "stop":
while ( $#argv > 0 )
ls -l ${argv} >&/dev/null
if ( $? != 0 ) then
echo "Up Down is not started on ${argv}. Skiping It."
else
rm ${argv}
if ( $? == 0 ) then
echo "Up Down Stopped on ${argv}."
else
echo "Up Down Cannot Be Stopped On ${argv}."
endif
endif
shift
end

breaksw
default:
echo "Unknown Command."
exit 1
breaksw
endsw



Second Script
*************
This script is placed in the /sbin/init.d directory of the remote machine.

rval=0
set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script FAILed
fi
}

killproc() {
pid=`ps -el | awk '( ($NF ~ /'"$1"'/) && ($4 != mypid) && ($5 != mypid) ){ print $4 }' mypid=$$ `
if [ "X$pid" != "X" ]; then
if kill "$pid"; then
echo "$1 stopped"
else
rval=1
echo "Unable to stop $1"
fi
fi
}


case "$1" in
"start_msg")
echo "Starting the UPDOWN subsystem"
rval=0
;;

"stop_msg")
rval=0
;;

"start")

if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi

if [ "$UPDOWN_START" != 1 ]; then
rval=2
else

driver=`awk '/Driver:/ { print $2}' /tmp/updown`
path=`awk '/Path:/ { print $2}' /tmp/updown`

echo "Driver Is : $driver"
echo "Path Is : $path"

ssh {$driver} "ls -l $path/$HOSTNAME"
if [ $? -ne 0 ] ; then
echo "Stopping Up Down."
rm /sbin/init.d/$0
rm /sbin/rc3.d/S999SUpDown
rm /sbin/rc2.d/K1SUpDown
rm /tmp/updown
rm /etc/rc.confid.d/updownconf
else
echo "Doing Reboot."
sync ; sync ; sync ; reboot
fi

rval=0
fi
;;

"stop")
if [ -f /etc/rc.config ] ; then
. /etc/rc.config
else
echo "ERROR: /etc/rc.config defaults file MISSING"
fi

if [ "$UPDOWN_START" != 1 ]; then
rval=2
else
echo "DO NOTING."
rval=0
fi
;;

*)
echo "usage: $0 {start|stop|start_msg|stop_msg}"
rval=1
;;
esac
exit $rval

This script should reboot the machine.
************************************

I could see that my script is started but, it is not rebooting the machine.

Can any one point out the error in the script?

Is there any other way i can do the same?

Thanks a lot for your help.

Thnaks & regards.
Prasad