Sponsored Content
Full Discussion: Script to restart a process
Top Forums Shell Programming and Scripting Script to restart a process Post 302580845 by Sekullos on Saturday 10th of December 2011 06:24:05 AM
Old 12-10-2011
I might be wrong but I see a flaw in your contrôl.

Your contrôl is based on this check :
Code:
if [ $INCEPT -gt 0 ]

$INCEPT being the value of your watched log_file. What happens if the process who feeds your log file crashs? Or if the application fucks up and don't have anything else to feed to your log_file?

Your log file will still be greater than 0 and your script won't detect it.

I was thinking of a similar script for work with the same check on a log file (ls -lrt | awk '{print $5}' )
but instead of checking the current value, I compare the new value to the previous one (just by redirecting old value to random file > old_value) and if it's equal to the previous value => restart.

Something like this

Code:
NEW_VALUE=`ls -lrt $LOG_FILE |awk '{print $5}'`
OLD_VALUE=$(cat /filesystem/scripts/old_value)

if [ $NEW_VALUE = $OLD_VALUE ]
   then
          echo "bla bla, not working"
          # restart process
   else
          echo "Log check ok, incrementing"
          $NEW_VALUE > "/filesystem/scripts/old_value"
fi

Might need a little tweaking or add a count so that it only restarts the process after 2 failed checks or something.


Just an idea anyway.

Last edited by Sekullos; 12-10-2011 at 07:55 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

suspend/restart a process in shell script

Hi, I have a task that Im stuck on. I have an elementary script named 'myscript' that prints "the script is running" once a second. It runs for 27 seconds. I need to write a 2nd script that starts 'myscript' and takes a parameter '$1' for a number. my 2nd script then needs to pause myscript... (1 Reply)
Discussion started by: daneensign
1 Replies

2. Shell Programming and Scripting

need help to write script to check the process health and automatically restart it

I am working on a project, which need to constantly watch the process, and check its status, if it was dead, it should be restart automatically. Please kindly refer me to URL which teach how to write this kind of script, or service. Thanks. (1 Reply)
Discussion started by: dragondad
1 Replies

3. 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

4. Shell Programming and Scripting

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 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... (11 Replies)
Discussion started by: e-l-diablo
11 Replies

5. 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

6. 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

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

8. 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

9. 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

10. 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
DH_SYSTEMD_START(1)						     Debhelper						       DH_SYSTEMD_START(1)

NAME
dh_systemd_start - start/stop/restart systemd unit files SYNOPSIS
dh_systemd_start [debhelperoptions] [--restart-after-upgrade] [--no-stop-on-upgrade] [unitfile...] DESCRIPTION
dh_systemd_start is a debhelper program that is responsible for starting/stopping or restarting systemd unit files in case no corresponding sysv init script is available. As with dh_installinit, the unit file is stopped before upgrades and started afterwards (unless --restart-after-upgrade is specified, in which case it will only be restarted after the upgrade). This logic is not used when there is a corresponding SysV init script because invoke-rc.d performs the stop/start/restart in that case. OPTIONS
--restart-after-upgrade Do not stop the unit file until after the package upgrade has been completed. This is the default behaviour in compat 10. In earlier compat levels the default was to stop the unit file in the prerm, and start it again in the postinst. This can be useful for daemons that should not have a possibly long downtime during upgrade. But you should make sure that the daemon will not get confused by the package being upgraded while it's running before using this option. --no-restart-after-upgrade Undo a previous --restart-after-upgrade (or the default of compat 10). If no other options are given, this will cause the service to be stopped in the prerm script and started again in the postinst script. -r, --no-stop-on-upgrade, --no-restart-on-upgrade Do not stop service on upgrade. --no-start Do not start the unit file after upgrades and after initial installation (the latter is only relevant for services without a corresponding init script). NOTES
Note that this command is not idempotent. dh_prep(1) should be called between invocations of this command (with the same arguments). Otherwise, it may cause multiple instances of the same text to be added to maintainer scripts. Note that dh_systemd_start should be run after dh_installinit so that it can detect corresponding SysV init scripts. The default sequence in dh does the right thing, this note is only relevant when you are calling dh_systemd_start manually. SEE ALSO
debhelper(7) AUTHORS
pkg-systemd-maintainers@lists.alioth.debian.org 11.1.6ubuntu2 2018-05-10 DH_SYSTEMD_START(1)
All times are GMT -4. The time now is 10:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy