Re: kill and restart a cobol daemon (598 Views)
Reply
Honored Contributor
Todd McDaniel_1
Posts: 1,387
Registered: ‎08-26-2002
Message 1 of 9 (598 Views)
Accepted Solution

kill and restart a cobol daemon

guys,

I have a script I am working on and it works fine when the daemon isnt running just to restart it, but when I have to kill the running daemon and then start it again it abends b/c of the kill command.

I issue a kill command in the script but it then terminates my script without trying to start the daemon again.

# ./mflm_manager.sh
LMF-common is missing. Running...
killing mflm_manager...
Terminated

I cant seem to get around this issue...
Unix, the other white meat.
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 2 of 9 (598 Views)

Re: kill and restart a cobol daemon

Can you post to us the actual script?
"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
Esteemed Contributor
Mark Fenton
Posts: 429
Registered: ‎01-08-2001
Message 3 of 9 (598 Views)

Re: kill and restart a cobol daemon

A little context --
Is this intended to run from cron or interactively?
Are you merely trying to 'bounce' the lmf?

If this isn't interactive, then perhaps a pair of scripts one to stop and the other to stop. Or, maybe you need to trap the return code from your kill process and then issue the start command.

thoughts.

Mark
Please use plain text.
Honored Contributor
Todd McDaniel_1
Posts: 1,387
Registered: ‎08-26-2002
Message 4 of 9 (598 Views)

Re: kill and restart a cobol daemon

here you go...

============================================
MFLM_PID=$!
MFLM_PID=`ps -aef |grep mflm_manager |grep -v grep |awk '{ print $2 }'`

# If the cobol manager isnt running then kill the tmp lockfile and restart it.
if [ `ps -aef |grep mflm_manager |grep -v grep|wc -l` -ne 1 ]
then
echo "Restarting MFLMMAN... "
kill $MFLM_PID
rm /var/tmp/LMF-common
cd /opt/cobol/mflmf;./mflmman
fi

# if /var/tmp/LMF-common is not present then kill the daemon and restart it via
the mflmman.
if [ `find /var/tmp/ -name LMF-common|wc -l` -ne 1 ]
then
echo "LMF-common is missing. Running..."
echo "killing mflm_manager..."
kill $MFLM_PID
cd /opt/cobol/mflmf;./mflmman
else
echo "MLFM_manger is running, exiting..."
fi
===========================================
Unix, the other white meat.
Please use plain text.
Honored Contributor
Jeff_Traigle
Posts: 1,354
Registered: ‎03-04-2004
Message 5 of 9 (598 Views)

Re: kill and restart a cobol daemon

Shouldn't you grep for mflmman instead of mlfm_manager to set MLFM_PID? You are indeed killing your script as it stands now.
--
Jeff Traigle
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 6 of 9 (598 Views)

Re: kill and restart a cobol daemon

The way I see it is that MFLM_PID is still set to $!, and the next assignment doesn't make it. So, you're killing your own script.

What is the name of this script, does it happen to have a name that is a substring of "mflm_manager"?

Also the following line:
if [ `ps -aef |grep mflm_manager |grep -v grep|wc -l` -ne 1 ]

then
echo "Restarting MFLMMAN... "
kill $MFLM_PID

reads to me that if mflm_manager isn't up - then echo a line, and then - "kill my own pid" - because it didn't exist at the top of script for the parameter assignment...

BUT... if it is already dead, then why do you want to kill anything, why not just remove the kill command, and go?

Or, if you still wanted the above line to work - change the "-ne 1" to "-ne 0".

right?
"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
Honored Contributor
Todd McDaniel_1
Posts: 1,387
Registered: ‎08-26-2002
Message 7 of 9 (598 Views)

Re: kill and restart a cobol daemon

thanks I changed the name of my script. So it should work now. I will have to wait till Friday to test it though. when my clients come back in.
Unix, the other white meat.
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 8 of 9 (598 Views)

Re: kill and restart a cobol daemon

One more thing, instead of using the ol' "ps -ef | grep [command] | grep -v grep " type command - convert your script to use:

`UNIX95= ps-fC mflm_manager| wc -l`

instead.

Cleaner more reliable, more energy efficient, and much less likely to give you problems from searches that end up being accidently true from other fields of the "ps" command line output.
"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 9 of 9 (598 Views)

Re: kill and restart a cobol daemon

One more thing, instead of using the ol' "ps -ef | grep [command] | grep -v grep " type command - convert your script to use:

`UNIX95= ps -fC mflm_manager| wc -l`

instead.

Cleaner more reliable, more energy efficient, and much less likely to give you problems from searches that end up being accidently true from other fields of the "ps" command line output.
"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation