#!/bin/bash

### BEGIN INIT INFO
# Provides: cpu-limit
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
#
# cpu-limit     Datapipe CPU Limit Script
#
# chkconfig: 345 90 10
# description:  Script to make Nod32 Scanner not run wild

#export PATH=/bin:/usr/bin:/usr/local/bin
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

case "$1" in
start)
        setlock -n /tmp/cpulimit_daemon.sh.lock /bin/true ||
        {
                echo " * cpulimit daemon can't be started, because it is already running"
                exit 0;
        }
        /usr/bin/cpulimit_daemon.sh start
        fuser -s /tmp/cpulimit_daemon.sh.lock &>/dev/null && echo " * cpulimit daemon started successfully";;

stop)
        (/usr/bin/cpulimit_daemon.sh stop &>/dev/null)
        status=$(fuser -s /tmp/cpulimit_daemon.sh.lock &>/dev/null; echo $?)
        case $status in
                0) echo " * cpulimit daemon can not be stopped";;
                1) echo " * cpulimit daemon stopped successfully / is not running";;
        esac;;

restart)
$0 stop
sleep 3
$0 start ;;

status)
        status=$(fuser -s /tmp/cpulimit_daemon.sh.lock &>/dev/null; echo $?)
        case $status in
                0) echo " * cpulimit daemon is running";;
                1) echo " * cpulimit daemon is not running";exit 3;;
        esac;;

force-reload)
  ;;
esac

exit 0
