#!/bin/sh
### BEGIN INIT INFO
# Provides: squid-captive
# Required-Start: $all mysql redis-server
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Captive redirection proxy instance
### END INIT INFO

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

case "$1" in
    start)
        echo "Starting Captive Hook"
        squid -YC -f /etc/squid/squid-captive.conf
        echo "Captive Hook Started"
        ;;

    stop)
        echo "Stopping Captive Hook"
        kill -9 $(ps aux | grep squid-captive.conf | grep -v grep | awk '{print $2}')
        echo "Captive Hook stopped"
        ;;

    restart)
        echo "Restarting Captive Hook"
        stop
        start
        echo "Captive Hook restarted"
        ;;

    *)
        echo "start stop restart"
        ;;
esac