restart process based on file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting restart process based on file
# 1  
Old 07-21-2009
restart process based on file

Hi all.
I do have a script "startApp.sh" (app result is a file /opt/extract/appextract.txt)

I have no problems with stopping app

Code:
var1=`ps -ef | grep -v grep | grep MyApp | awk '{print $2}'`
kill -9 $var1

What I want to achieve is:

I start app, app is doing some extraction, after extraction is done i would like to stop app (kill app if/when) wait some time (~ 30 sec. different processes/scripts taking place) and start app again (until next extract)

I will try to be more schematic
- start App
- app is running, doing stuff, and creates a file
- when file is created I have to stopApp
- wait ~30sec
- start app

Could you please guide me how to create some script that will be in "constant loop" or a service and will watch for that file, if exist do somethinh (kill my app)

thank you very much
e-l-diablo

Use CODE-tags when displaying code, data or logs to enhance readability and to preserve formatting like indention etc., ty.

Last edited by zaxxon; 07-21-2009 at 08:15 AM.. Reason: code tags
# 2  
Old 07-21-2009
Script could look like:

Code:
#!/bin/sh

./app start

while :; do
     sleep 1 # just to give it short breaks
     if [[ -e /<path-to-your-output-file>/filename ]]; then
          ./app stop
          sleep 30
          break
     fi
done

./app start

exit 0

# 3  
Old 07-21-2009
perfect.
Wht I dod not think about that.
That is what I was searching for. I will give a try and let you know if it works as it should (there are more scripts in that process)
very, very much thank you (i will do some modifications, i already see some options)
# 4  
Old 08-12-2009
Hi again. After testing it does not work

What i have done:
I have script called startMe.sh. It starts app and should kill when file in specific directory exists.
Code:
#!/bin/sh
rm /opt/tmp/restart.txt *that removes restart file if exist

./startApp.sh

while :; do
     if [[ -e /opt/tmp/restart.txt ]]; then
          ./killapp.sh
          sleep 30
          break
     fi
done

./startApp.sh
exit 0

killapp.sh looks like
Code:
var1=`ps -ef | grep -v grep | grep java | grep username | awk '{print $2}'`
kill -9 $var1

Where am i doing something wrong?
# 5  
Old 08-12-2009
No idea if this is a typo:

Code:
... *that removes restart file if exist

Comments should start with a # nor a *.

Is ./startApp.sh touching that flag file?
Also what is not working? A bit more details could help, ty.
# 6  
Old 08-12-2009
Hi.
Code:
*that removes restart file if exist

That was FYI
Few more details. I am running Solaris 10 on SUN x4450 box (really nice work horse) with 128GB RAM.
when I run ./startApp.sh all works as it should: my application starts
and i get messages (all the time)
Code:
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found

when i place killapp.txt under /opt/tmp nothing, just nothing. That is strange becaus in theory should work.
# 7  
Old 08-12-2009
So your script ./startApp.sh seems to have a problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Can't stop/restart postfix - pid associated with another process

This issue could happen to any other service but in this case its commssioning Postfix - it seems i can't stop postfix as the PID relates to another service - i've delete the 'master.lock' but to no available - any ideas, memeory commands etc ? thanks in advance ps. the serve is in Production so... (2 Replies)
Discussion started by: stevie_velvet
2 Replies

2. Shell Programming and Scripting

How do i restart a process if it fails?

Hi Guru's, I just want to have an idea on how to restart a particular step when it fails? SCENARIO we have plenty of steps such as the following below: Step 1 copy file from source to target location which is in a different server. Step 2 create initial and incremental process ... (4 Replies)
Discussion started by: reignangel2003
4 Replies

3. Shell Programming and Scripting

Monitor and restart UNIX process

Hi all, Tearing my hair out..! I have a requirement to monitor and restart a unix process via a simple watchdog script. I have the following 3 scripts that dont work for me.. script 1 (only produces 1 output if process is up or not)... (4 Replies)
Discussion started by: jonnyd
4 Replies

4. Shell Programming and Scripting

Script to restart process

HI, I am trying to write a scrip which would restart active process. This is what i have written till now. $ xms show pr PRESE.* NAME STATUS ROLE PID RSTRTS STARTED MACHINE... (8 Replies)
Discussion started by: Siddheshk
8 Replies

5. Emergency UNIX and Linux Support

Check hung process and restart

Hi all I have networker running on a RHEL 5.7 and over time it hangs. So the solution backup team proposed is to check if the process is hung, to stop and start it. Unfortunately for me, the rc script only allows three commands, start, stop and status (no restart option) so I managed to set... (15 Replies)
Discussion started by: hedkandi
15 Replies

6. Shell Programming and Scripting

Script to restart a process

I have written a script which checks for a file if that is being updated or not. If the files is not being updated then it will restart the process. #!/bin/sh DATE=`date +%Y%m%d%H%M%S` LOG_FILE=/var/xmp/log/XMP_* INCEPT=`ls -l $LOG_FILE |awk '{print $5}'` PROC=`xms show pr |grep -i... (3 Replies)
Discussion started by: Siddheshk
3 Replies

7. Shell Programming and Scripting

How to keep process running after apache restart.

I have posted this on the Web subforum but it seems that nobody knows to do this, maybe someone has a solution here. Thank you I have a PHP application that starts a couple of processes on the server...the problem is that if I restart apache those running apps will die. How can I start them... (1 Reply)
Discussion started by: valiadi
1 Replies

8. Web Development

How to keep process running after apache restart.

Hi, I have a PHP application that starts a couple of processes on the server...the problem is that if I restart apache those running apps will die. How can I start them in a way that they are not killed when I restart/stop apache ? $cmdstr = "nohup ".$config."/".$config."... (6 Replies)
Discussion started by: valiadi
6 Replies

9. Shell Programming and Scripting

Restart script based on MD5sum

Ok, I run a small script, that restarts a perl script when it fails (it's a very unreliable perl script, but I can't change it, it's crucial, and I don't know perl) It outputs data into a logfile. Unfortunately, it also regularly hangs. This is a major problem because if it hangs, no data is... (6 Replies)
Discussion started by: Bakes
6 Replies

10. SuSE

Restart process

I have a process that gradually eats up memory, it's currently at 80.2% and slowing down the linux server > ps aux | grep SNMPME root 3129 0.0 80.2 3591752 2480700 ? Sl Feb13 5:04 /opt/nampe/lib/snmpme/SNMPME config/startup.xml Is there a command I can execute to restart this... (3 Replies)
Discussion started by: brendan76
3 Replies
Login or Register to Ask a Question