Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

kill and restart a cobol daemon

SOLVED
Go to Solution
Honored Contributor Honored Contributor

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.
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

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?
We are the people our parents warned us about --Jimmy Buffett
8 REPLIES
Honored Contributor Honored Contributor

Re: kill and restart a cobol daemon

Can you post to us the actual script?
We are the people our parents warned us about --Jimmy Buffett
Esteemed Contributor Esteemed Contributor

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
Honored Contributor Honored Contributor

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.
Honored Contributor Honored Contributor

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
Honored Contributor Honored Contributor

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?
We are the people our parents warned us about --Jimmy Buffett
Honored Contributor Honored Contributor

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.
Honored Contributor Honored Contributor

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.
We are the people our parents warned us about --Jimmy Buffett
Highlighted
Honored Contributor Honored Contributor

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.
We are the people our parents warned us about --Jimmy Buffett