#!/bin/bash -
#
#        +-----------------------------------------------------------------------------+
#        | OpenFW UTM Community                                                           |
#        +-----------------------------------------------------------------------------+


# Check the flagfile
if [ ! -e /tmp/openvpn_delay_triggers ]; then
  exit
fi

(
  # Prevent multiple simultaneous script execution
  flock -x -w 10 200 || exit 1

  # Check again
  if [ ! -e /tmp/openvpn_delay_triggers ]; then
    exit
  fi

  # Execute the triggers
  jobcontrol call openvpnjob.execute_delayed_triggers &>/dev/null

  # Delete the flagfile
  rm -f /tmp/openvpn_delay_triggers

) 200>/var/run/openvpn_delay_triggers_lock.tmp

