#!/bin/sh

# Load ipmodule variables
. /opt/gira/share/devicestack/ipmodule-vars

case "$1" in
  start)
    echo -n "Starting devicestack ... "
    # Do not use the ${DS_LOGFILE} to log the output b/c it is not logrotated.
    # This can lead to a system that does not have free space in the tmpfs /var partition.
    # Proper operation is not guaranteed in that case and logfiles cannot be downloaded anymore.
    # The log file can be used again if there is a means to logrotate at a maximum size.
    #${DEVICESTACK} > ${DS_LOGFILE} 2>&1 &

    # We use the system logger until there is a better way to logrotate ${DS_LOGFILE}
    # To have the content in /var/log/devicestack.log, we log to local0.notice facility
    # and configure a rule for that to the log file in /etc/syslog.conf.
    ${DEVICESTACK} 2>&1 | logger -t devicestack -p local0.notice &
    echo $! > ${DS_PIDFILE}
    echo $!
    ;;
  stop)
    echo -n "Stopping DeviceStack ... "
    if start-stop-daemon --stop --quiet --pidfile ${DS_PIDFILE}
    then
      echo "done."
    else
      echo "failed."
    fi
    ;;
  *)
    echo "Usage: $0 (start|stop)"
    exit 1
esac

exit 0
