Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 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:

pid=$(ps -ewwo args | grep [v]arnish)

# minimum difference in seconds

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

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


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.