Operating System - HP-UX
1834149 Members
2255 Online
110064 Solutions
New Discussion

Re: Start script starts twice during transient from 3 -> 4 level

 
SOLVED
Go to solution
MQ'ski
Regular Advisor

Start script starts twice during transient from 3 -> 4 level

I notice following problem during test of start script. I have done:
1) In rc4.d I created link: /sbin/rc4.d/S999myscript that is a link to my own script created in: /sbin/init.d/myscript

2) my script does as follows:
#First: switches to user "myuser" and executes myscript.sh script as below:

#!/bin/sh
/usr/bin/su - myuser -c "/home/myuser/myscript.sh" >> /dev/null

#Second: It checks if previous command was successfully executed and if not it writes error to log... if yes it sends good notice to log as example below:

x=$?
if [ "$x" -gt 0 ]; then
echo "myscript failed to start" > /home/myuser/myscript.log
else
echo "myscript started"
exit 0
fi

3)Finally in /home/myuser/myscript.sh script is following action taken - start program:
nohup ./start_binary_program &
exit 0

Now I tested few scenarios and the most important and problematic for me is that
when I start it manually from command line:
./S999myscript

I see process of my_binary_program running once.

When I go from run level 3 to run level 4 I can see two processes of my_binary_program started the same time... exact started almost in the same second...
I checked rc.log and I confirm that somehow... this start script is called two times......
I can say it after following test:
I modified /sbin/init.d/myscript by adding one line that writes current date to /tmp/out.log
as follows: date >> /tmp/out.log.
So the script looks like:
#!/bin/sh
date >> /tmp/out.log
/usr/bin/su - myuser -c "/home/myuser/myscript.sh" >> /dev/null
x=$?
if [ "$x" -gt 0 ]; then
echo "myscript failed to start" > /home/myuser/myscript.log
else
echo "myscript started"
exit 0
fi

Maybe you could help somehow becaus at this stage I don't have more ideas what can be wrong...
8 REPLIES 8
Jdamian
Respected Contributor

Re: Start script starts twice during transient from 3 -> 4 level

Please, show us the contents of the directory /sbin/rc4.d
James R. Ferguson
Acclaimed Contributor

Re: Start script starts twice during transient from 3 -> 4 level

HI:

Make sure that you haven't inadvertantly created multiple startup links to your script:

# ls -lR /sbin/rc?.d|grep myscript

Regards!

...JRF...
MQ'ski
Regular Advisor

Re: Start script starts twice during transient from 3 -> 4 level

Answers:
1. In the rc4.d/ is only my S999myscript script and another link
with S301 prefix that does (starts) different think related to system resources and surely not related to my staff
(I can comment -t out _S301 to prove that it is not related to my problem)

2. Exactly one link only... 100% sure...
Jdamian
Respected Contributor

Re: Start script starts twice during transient from 3 -> 4 level

I suggest the following actions:

1. Create a new startup script in /sbin/init.d. The only action needed is to log the time stamp.

2. Create a symbolic link in /sbin/rc4.d as usual

3. Test the new script

If the new script exhibits the expected behaviour, focus on your "myscript". If not, /sbin/rc might have a bug (I never found that).

Good luck
MQ'ski
Regular Advisor

Re: Start script starts twice during transient from 3 -> 4 level

So I did following
In /sbin/rc4.d
S998scripta -> /sbin/init.d/myscripta
where
/sbin/init.d/myscripta

is just:
echo test >> /tmp/test.out

I go to init 3...
Tests starts now:
init 4
I do more /tmp/test.out
test
test

Seems test written two time to file... That means taht S998scripta is called twice...
MQ'ski
Regular Advisor

Re: Start script starts twice during transient from 3 -> 4 level

Hi...
This was probably my misunderstanding.
I read more carefully...
start script I have written havent contain
following syntax...
probably this was the problem.
Now I checking last reboot... but I think it is right...:

case
start_msg)
stop_msg)
start)
stop)
*)
esac
Bill Hassell
Honored Contributor
Solution

Re: Start script starts twice during transient from 3 -> 4 level

As you mentioned, your script must follow a defined format and handle 4 specific options. To write any start/stop script, use the template file located in /sbin/init.d and pay attention to the return codes in the template. It is strongly recommended to code both a start and stop set of actions, and to include a symlink for both S### as well as K### so your process(es) may be started and stopped cleanly.


Bill Hassell, sysadmin
MQ'ski
Regular Advisor

Re: Start script starts twice during transient from 3 -> 4 level

I have found solution myself... Hovewer I submited some points as collegues did help to isolate potential reasons of this problem.