#!/bin/sh

# $FreeBSD: tags/RELEASE_8_4_0/www/kannel/files/kannel.in 300897 2012-07-14 14:29:18Z beat $
#
# PROVIDE: kannel_smsbox kannel_wapbox kannel_bearerbox
# REQUIRE: NETWORKING SERVERS 
# BEFORE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name=kannel
rcvar=kannel_enable

command="/usr/local/sbin/run_kannel_box"
extra_commands="reload"
sig_reload=SIGUSR1

load_rc_config $name
# Set defaults
kannel_config=${kannel_config:-"/usr/local/etc/kannel.conf"}
kannel_user=${kannel_user:-"kannel"}
# Config file is required
if [ ! -r ${kannel_config} ]; then
    warn "${kannel_config} is not readable."
    case $1 in
	force*) : ;;
	*) exit 1 ;;
    esac
fi

if test -n ${kannel_enable:-""} && checkyesno kannel_enable; then
    kannel_bearerbox_enable=${kannel_bearerbox_enable:-"YES"}
    kannel_smsbox_enable=${kannel_smsbox_enable:-"YES"}
    kannel_wapbox_enable=${kannel_wapbox_enable:-"YES"}
fi

# bearerbox
name=kannel_bearerbox
rcvar=kannel_bearerbox_enable
pidfile=/var/run/kannel/${name}.pid
# Defaults
kannel_bearerbox_user=${kannel_bearerbox_user:-"${kannel_user}"}
kannel_bearerbox_enable=${kannel_bearerbox_enable:-"NO"}
kannel_bearerbox_config=${kannel_bearerbox_config:-"${kannel_config}"}
kannel_bearerbox_flags=${kannel_bearerbox_flags:-"--pidfile ${pidfile} /usr/local/sbin/bearerbox ${kannel_bearerbox_flags} ${kannel_bearerbox_config}"}
#
load_rc_config $name
run_rc_command "$1"
#
_rc_restart_done=false

# smsbox
name=kannel_smsbox
rcvar=kannel_smsbox_enable
pidfile=/var/run/kannel/${name}.pid
# Defaults
kannel_smsbox_user=${kannel_smsbox_user:-"${kannel_user}"}
kannel_smsbox_enable=${kannel_smsbox_enable:-"NO"}
kannel_smsbox_config=${kannel_smsbox_config:-"${kannel_config}"}
kannel_smsbox_flags=${kannel_smsbox_flags:-"--pidfile ${pidfile} /usr/local/sbin/smsbox ${kannel_smsbox_flags} ${kannel_smsbox_config}"}
#
load_rc_config $name
run_rc_command "$1"
#
_rc_restart_done=false

# wapbox
name=kannel_wapbox
rcvar=kannel_wapbox_enable
pidfile=/var/run/kannel/${name}.pid
# Defaults
kannel_wapbox_user=${kannel_wapbox_user:-"${kannel_user}"}
kannel_wapbox_enable=${kannel_wapbox_enable:-"NO"}
kannel_wapbox_config=${kannel_wapbox_config:-"${kannel_config}"}
kannel_wapbox_flags=${kannel_wapbox_flags:-"--pidfile ${pidfile} /usr/local/sbin/wapbox ${kannel_wapbox_flags} ${kannel_wapbox_config}"}
#
load_rc_config $name
run_rc_command "$1"

