#!/bin/bash

PID=$$
PIDFILE={{ pid_file }}

sleep $((RANDOM % 10))

if [ ! -f $PIDFILE ]; then
  echo $PID > $PIDFILE
  sleep {{ wait_time }}
  {{ lazy_command }}
  rm -f $PIDFILE
else
  ps --pid `cat $PIDFILE` &>/dev/null
  if [ $? -eq 0 ]; then
    echo "Skipped"
  else
    echo $PID > $PIDFILE
    sleep {{ wait_time }}
    {{ lazy_command }}
    rm -f $PIDFILE
  fi
fi
