#!/bin/sh

### BEGIN INIT INFO
# Provides:          dpdk
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     S
# Default-Stop:      0 1 6
# Short-Description: start dpdk runtime environment
### END INIT INFO

set -e

PATH="/sbin:/bin:/usr/bin"

[ -d /lib/dpdk ] || exit 0

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

error=0
case "$1" in
start)
    log_action_begin_msg "Starting DPDK environment" "dpdk"
    output=$(/lib/dpdk/dpdk-init start 2>&1) || error="$?"
    if [ ! -z "$output" ]; then
        echo "$output" | while read line; do
            log_action_cont_msg "$line"
        done
    fi
    log_action_end_msg $error
    exit $error
    ;;
stop)
    ;;
restart|force-reload)
    ;;
status)
    output=$(/lib/dpdk/dpdk-init --status 2>&1) || error="$?"
    if [ ! -z "$output" ]; then
        echo "$output" | while read line; do
            log_action_cont_msg "$line"
        done
    fi
    log_action_end_msg $error
    exit $error
    ;;
*)
    echo "Usage: $0 {start|stop|restart|force-reload|status}"
    exit 1
    ;;
esac

exit 0

