mirror of https://github.com/sipwise/mediator.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
4.0 KiB
144 lines
4.0 KiB
#! /bin/sh
|
|
### BEGIN INIT INFO
|
|
# Provides: mediator
|
|
# Required-Start: $remote_fs $syslog
|
|
# Required-Stop: $remote_fs $syslog
|
|
# Should-Start: sshd mysql
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Short-Description: Ngcp Mediator
|
|
# Description: Create accounting CDRs
|
|
### END INIT INFO
|
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
NAME=mediator
|
|
DESC="ACC mediator"
|
|
RUN_MEDIATOR=no
|
|
|
|
case $(dirname $0) in
|
|
/*) FULLPATH=$(dirname $0);;
|
|
*) FULLPATH=$(pwd)/$(dirname $0);;
|
|
esac
|
|
|
|
DAEMON=`which mediator`
|
|
DEFAULTS=/etc/default/mediator
|
|
|
|
test -f $DAEMON || exit 0
|
|
|
|
# Load startup options if available
|
|
if [ -f $DEFAULTS ]; then
|
|
. $DEFAULTS || true
|
|
fi
|
|
|
|
if [ "$RUN_MEDIATOR" != "yes" ]; then
|
|
echo "mediator not yet configured. Edit $DEFAULTS first."
|
|
exit 0
|
|
fi
|
|
[ -z "$PIDFILE" ] && PIDFILE="/var/run/mediator.pid"
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
|
|
OPTIONS=""
|
|
|
|
[ -z "$PIDFILE" ] || OPTIONS="$OPTIONS -D $PIDFILE"
|
|
[ -z "$INTERVAL" ] || OPTIONS="$OPTIONS -i $INTERVAL"
|
|
[ -z "$SOURCE_HOST" ] || OPTIONS="$OPTIONS -h $SOURCE_HOST"
|
|
[ -z "$SOURCE_PORT" ] || OPTIONS="$OPTIONS -o $SOURCE_PORT"
|
|
[ -z "$SOURCE_USER" ] || OPTIONS="$OPTIONS -u $SOURCE_USER"
|
|
[ -z "$SOURCE_PASS" ] || OPTIONS="$OPTIONS -p $SOURCE_PASS"
|
|
[ -z "$SOURCE_DB" ] || OPTIONS="$OPTIONS -b $SOURCE_DB"
|
|
[ -z "$DEST_HOST" ] || OPTIONS="$OPTIONS -H $DEST_HOST"
|
|
[ -z "$DEST_PORT" ] || OPTIONS="$OPTIONS -O $DEST_PORT"
|
|
[ -z "$DEST_USER" ] || OPTIONS="$OPTIONS -U $DEST_USER"
|
|
[ -z "$DEST_PASS" ] || OPTIONS="$OPTIONS -P $DEST_PASS"
|
|
[ -z "$DEST_DB" ] || OPTIONS="$OPTIONS -B $DEST_DB"
|
|
[ -z "$PROV_HOST" ] || OPTIONS="$OPTIONS -S $PROV_HOST"
|
|
[ -z "$PROV_PORT" ] || OPTIONS="$OPTIONS -T $PROV_PORT"
|
|
[ -z "$PROV_USER" ] || OPTIONS="$OPTIONS -R $PROV_USER"
|
|
[ -z "$PROV_PASS" ] || OPTIONS="$OPTIONS -A $PROV_PASS"
|
|
[ -z "$PROV_DB" ] || OPTIONS="$OPTIONS -N $PROV_DB"
|
|
[ -z "$STATS_HOST" ] || OPTIONS="$OPTIONS -Z $STATS_HOST"
|
|
[ -z "$STATS_PORT" ] || OPTIONS="$OPTIONS -z $STATS_PORT"
|
|
[ -z "$STATS_USER" ] || OPTIONS="$OPTIONS -W $STATS_USER"
|
|
[ -z "$STATS_PASS" ] || OPTIONS="$OPTIONS -w $STATS_PASS"
|
|
[ -z "$STATS_DB" ] || OPTIONS="$OPTIONS -X $STATS_DB"
|
|
[ -z "$STATS_PERIOD" ] || OPTIONS="$OPTIONS -x $STATS_PERIOD"
|
|
if test "$FORK" = "yes" ; then
|
|
OPTIONS="$OPTIONS -d"
|
|
fi
|
|
|
|
|
|
case "$1" in
|
|
start)
|
|
if [ -x "/usr/sbin/ngcp-check_active" ]; then
|
|
/usr/sbin/ngcp-check_active -q
|
|
status=$?
|
|
case "${status}" in
|
|
0|3)
|
|
echo "Active node or transition."
|
|
;;
|
|
*)
|
|
echo "Ignored start action in inactive node ($status)"
|
|
exit 0
|
|
;;
|
|
esac
|
|
fi
|
|
set -e
|
|
|
|
echo -n "Starting $DESC: $NAME"
|
|
start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE \
|
|
--exec $DAEMON -- $OPTIONS || echo -n " already running"
|
|
log_end_msg $?
|
|
;;
|
|
stop)
|
|
echo -n "Stopping $DESC: $NAME"
|
|
start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \
|
|
--exec $DAEMON
|
|
if [ "$?" -ne 0 ]; then
|
|
return $?
|
|
fi
|
|
rm -f $PIDFILE
|
|
log_end_msg $?
|
|
;;
|
|
restart|force-reload)
|
|
echo -n "Restarting $DESC: $NAME"
|
|
start-stop-daemon --oknodo --stop --quiet --pidfile \
|
|
$PIDFILE --exec $DAEMON
|
|
if [ "$?" -ne 0 ]; then
|
|
return $?
|
|
fi
|
|
rm -f $PIDFILE
|
|
sleep 1
|
|
|
|
if [ -x "/usr/sbin/ngcp-check_active" ]; then
|
|
/usr/sbin/ngcp-check_active -q
|
|
status=$?
|
|
case "${status}" in
|
|
0|3)
|
|
echo "Active node or transition."
|
|
;;
|
|
*)
|
|
echo "Ignored start action in inactive node ($status)"
|
|
exit 0
|
|
;;
|
|
esac
|
|
fi
|
|
set -e
|
|
start-stop-daemon --start --quiet --pidfile \
|
|
$PIDFILE --exec $DAEMON -- $OPTIONS
|
|
log_end_msg $?
|
|
;;
|
|
status)
|
|
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
|