#!/bin/sh

PATH='/sbin:/bin:/usr/sbin:/usr/bin'
DAEMON='avregd'
DAEMON_BIN="/usr/sbin/$DAEMON"
PIDDIR='/run/avreg'
CONF='/etc/avreg/avreg.conf'
PROFILESDIR='/etc/avreg/profiles'

set -eu

[ -d "$PIDDIR" ] || exit 0
[ -x "$DAEMON_BIN" ] || exit 0

if [ $# -gt 0 ]; then
   profiles=$@
else
   profiles='@'
fi

for profile in $profiles ; do
   if [ "${profile}" = 'x@' ]; then
      pidfile="${PIDDIR}/${DAEMON}.pid"
   else
      pidfile="${PIDDIR}/${DAEMON}-${profile}.pid"
   fi

   if [ -r "$pidfile" ]; then
      kill -USR1 `cat $pidfile` || true
   fi
done

exit 0
