#!/bin/bash
# This script restarts vami-lighttp after a specified delay.
# It is required to prevent lighttp from restarting during firstboot.
# The restart can also be initiated from the UI. That's why before
# making any changes the script tries to create the directory. If it
# succeeds it won and is allowed to restart the service.

if [ -n "$1" ]
then
    delay="$1"
else
    # default delay is 30 seconds
    delay=30
fi

sleep "$delay"

# maybe the server restart was already initiated from the UI?
if ! mkdir /dev/shm/vami-restart
then
    exit 0
fi
# delete marker file
rm -f /dev/shm/.restart-vami-lighttp

/sbin/service vami-lighttp restart
