#!/bin/sh /etc/rc.common
# Copyright (C) 2017 OpenWrt.org

START=92

USE_PROCD=1

#PROCD_DEBUG=1

DAEMON=baresip
DEFAULT=/etc/default/$DAEMON
LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON"
OPTIONS=
PROG=/usr/bin/$DAEMON

[ -f $DEFAULT ] && . $DEFAULT

start_service() {
  local dir=

  if [ "$ENABLE_BARESIP" != yes ]; then
    $LOGGER User configuration incomplete - not starting $DAEMON
    $LOGGER Check ENABLE_BARESIP in $DEFAULT
    return 1
  fi

  procd_open_instance
  procd_set_param command $PROG
  procd_append_param command \
    -f /etc/$DAEMON \
    $OPTIONS
  procd_set_param pidfile /var/run/${DAEMON}.pid
  # forward stderr to logd
  procd_set_param stderr 1
  # forward stdout to logd
  #procd_set_param stdout 1
  procd_set_param user $DAEMON
  procd_close_instance
}
