Operating System - HP-UX
1846363 Members
3755 Online
110256 Solutions
New Discussion

Process started with startup script terminates

 
Rohan_7
Advisor

Process started with startup script terminates

Hi

I tried search for my problem in the forum but couldn't find the exact match, hence asking the question.

I have a startup script in run level 3. It starts two servers. One directly running the binary and second through another script.
The code goes something like this
mystartupscript.sh
-----------------------------------------------
SERVER1="/path/to/bin/server1 "
# Start server1
$SERVER1
# server1 runs as daemon and internally
# detaches from terminal

SERVER2="/path/to/server2.sh "
$server2

exit 0

-----------------------------------------------

server2.sh
SERVER2_BIN="/path/to/bin/server2 "
$SERVER2 &
-----------------------------------------------

As the server1 is daemon and does not attach to terminal it starts up and runs fine when the system boots up.
However, the problem is with server2. It does start up, but gets terminated after sometime. May be when all processing of "rc3" is over.
I get following in rc.log
---------------------------------------------
( Terminating process 1569 ("/path/to/bin/server2 options") )

----------------------------------------------
1569 is the process id for server2. And next to pid is the command line with which the process was started.

What I can understand after some reading is that, server2.sh is not executed with nohup, but "server2" was started as background process. hence this should work. But for some reason its not working.
I cannot run "$server2 2>&1 >/dev/null" as $server2 echos the status and pid of the second server.

the 'mystartupscript.sh ' runs properly as cron job and both servers come up properly.
It also continues to run when I start it through login shell and then logout and exit that shell.

Any clues?

Apologies for long posting.

Thanks in advance
Rohan
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: Process started with startup script terminates

Even though the process is being started in the background, it is very possible, even likely, that the process will get terminated when the shell that starts it terminates.

You can try this yourself from a terminal. Just start something in the background and then do an 'exit'. You will get a warning message about running processes. If you exit again, you will be logged out and your process terminated.

When you start it through the login shell, how do you start it? Are you doing the exact same thing as the startup script?

I would start the process with 'nohup processname &' and see if the helps.
Steven E. Protter
Exalted Contributor

Re: Process started with startup script terminates

I agree with Patrick:

I find this useful when diagnosing such issues:

env > /tmp/env.txt

have the startup script dump its environment. Boot the box, copy off the file and restart the server.

Any environmental differences can effect start up results.

SEP
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
Rohan_7
Advisor

Re: Process started with startup script terminates

Thanks for response Patrik and SEP.

Same script I use while starting up server through terminal.
As I mentioned earlier, this works even when I exit from the login and the shell terminates.

However, I am not clear that why the server2 is terminated by 'rc3' or 'init' process?
Someone had suggested in one of the postings that starting the process in background is more safer than 'nohup'.

Still looking for better solution!

Thanks
Rohan
Rohan_7
Advisor

Re: Process started with startup script terminates

Hi guys,

Probably I got the solution.
I'm now ignoring SIGHUP in my second server.

After ignoring SIGHUP, it works fine, from terminal as well as startup scripts.

Thanks a lot for your help

Rohan