#!/bin/bash
# Copyright (C) 2016-2022 eGloo Incorporated
#
# This is free software, licensed under the GNU General Public License v3.

# netifyd	Start up the Netify Agent
#
# chkconfig: 2345 55 25
# description: Netify Agent
#
# processname: netifyd
# config: /etc/netifyd.conf
# pidfile: /var/run/netifyd/netifyd.pid

### BEGIN INIT INFO
# Provides: netifyd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the Netify Agent
# Description: Netify Agent
### END INIT INFO

# Source function library.
. /etc/init.d/functions

RETVAL=0
prog="netifyd"
PID_FILE=/var/run/netifyd/netifyd.pid

start() {
    # Load defaults.
    if [ -f /usr/share/netifyd/functions.sh ]; then
        source /usr/share/netifyd/functions.sh

        NETIFYD_OPTS=$(auto_detect_options)

        load_modules
    fi

    echo -n "Starting $prog: "

    daemon $prog $NETIFYD_OPTS
    success
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    echo
    return $RETVAL
}

stop() {
    echo -n "Shutting down $prog: "
    killproc $prog
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    echo
    return $RETVAL
}

case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    status)
        $prog --status
        status $prog
    ;;
    restart)
        stop
        start
    ;;
    condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
            RETVAL=$?
        fi
    ;;
    *)
    echo "Usage: $prog {start|stop|status|restart|condrestart}"
    exit 1
    ;;
esac
exit $RETVAL

# vi: expandtab shiftwidth=4 softtabstop=4 tabstop=4 syntax=sh
