Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What's good "ghetto process monitor" without installing any additional software besides cron and some standard UNIX tools? I.e. check in a shell script if a certain process has died and been dead for a while to restart it? This would be to restart segfaulting Varnish process.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can create a simple bash script running every minute and checking whether the process is running. If not, it can create file and in one of the next runs according to the file creation date it can make a decision whether to start the varnish process again or not.

Simple example:

#!/bin/bash
pid=$(ps -ewwo args | grep [v]arnish)
check_file=/var/run/varnish.checker

# minimum difference in seconds
min_difference=180

if [ -f "$check_file" ]
then
    difference=$(($(date +"%s") - $(stat -c %Y "$check_file")))
    if [ $difference -gt $min_difference ]
    then
        ### start the varnish process here ###
        rm -f "$check_file"
    fi
else
    if [ -z $pid ]
    then
        touch "$check_file"
    fi
fi

But why you doesn't want to use external utility for this? Monit is a great tool (daemon) for this stuff. Also it can monitor many other processes.

share|improve this answer
    
Thanks! I want to be able to deploy one version without dependencies to anything, so no monit this time. –  Mikko Ohtamaa May 24 '11 at 23:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.