#!/bin/bash
#
# /etc/init.d/numad

### BEGIN INIT INFO
# Provides: numad
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: 
# Should-Stop: 
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: numad daemon recommends or binds workloads to NUMA nodes
# Description:       numad is a userspace daemon that monitors NUMA usage
#                    and resource usage and attempts to configure workloads
#                    using cpusets to use a subset of CPUs and memory nodes
#                    to maximise the number local memory access for best
#                    performance. Alternatively, it can be used to give
#                    hints as to how workloads should be manually bound
#                    to CPUs and memory nodes.
### END INIT INFO

NUMAD_BIN=/usr/sbin/numad
NUMAD_CONFIG=/etc/numad.conf

. /etc/rc.status
LOCKFILE=${PIDFILE}.lock

# Reset status of this service
rc_reset

case "$1" in
start)
    test -x $NUMAD_BIN || exit 5
    test -f $NUMAD_CONFIG || exit 6
    echo -n "Starting numad "
    . $NUMAD_CONFIG
    $NUMAD_BIN -i $INTERVAL
    echo $! > "$PIDFILE"
    touch "$LOCKFILE"
    rc_status -v
    ;;

stop)
    echo -n "Shutting down numad "
    $NUMAD_BIN -i 0
    RETVAL=$?
    rc_status
    if [ $RETVAL -eq 0 ]; then
        rm -f "$LOCKFILE" "$PIDFILE"
    fi
    ;;

try-restart)
    $0 status > /dev/null && $0 restart
    rc_status
    ;;

restart)
    $0 stop
    $0 start
    rc_status
    ;;

reload)
    $0 restart
    ;;

force_reload)
    echo -n "Reload numad "
    $0 restart
    ;;

status)
    echo -n "Checking for numad "
    check_proc "$PIDFILE" "$LOCKFILE"

    rc_status -v
    ;;
*)
    echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
    exit 1
    ;;
esac
rc_exit
