Blob Blame History Raw
#!/bin/sh
#
# cntlmd: Start/stop the cntlm proxy.
#
# chkconfig:  - 26 89 
# Description:       Cntlm is meant to be given your proxy address and becomming
#                    the primary proxy then, listening on a selected local port. 
#                    You point all your proxy-aware programs to it and don't ever
#                    have to deal with proxy authentication again.
#
### BEGIN INIT INFO
# Provides:          cntlm
# Required-Start:    $syslog $network $time
# Required-Stop:     $syslog $network $time
# Short-Description: Authenticating HTTP accelerator for NTLM secured proxies
# Description:       Cntlm is meant to be given your proxy address and becomming
#                    the primary proxy then, listening on a selected local port. 
#                    You point all your proxy-aware programs to it and don't ever
#                    have to deal with proxy authentication again.
### END INIT INFO

# Determining Linux RedHat/SuSE 
#
# /etc/redhat-release
# /etc/SuSE-release

SuSE=false
RedHat=false

if [ -f /etc/SuSE-release ]; then
	SuSE=true
elif [ -f /etc/redhat-release ]; then
	RedHat=true
else
	echo "Error: your platform is not supported by $0" > /dev/stderr
	exit 1
fi

# Source function library SuSE/RedHat.

if $SuSE; then
    if [ -f /lib/lsb/init-functions ]; then
	. /lib/lsb/init-functions
    else
	echo "Error: your platform is not supported by $0" > /dev/stderr
    exit 1
    fi
else
    if [ -f /etc/init.d/functions ]; then
	. /etc/init.d/functions
    else
	echo "Error: your platform is not supported by $0" > /dev/stderr
    exit 1
    fi
fi    

[ -r /etc/sysconfig/cntlmd ] && . /etc/sysconfig/cntlmd

# First reset status of this service SuSE/RedHat

if $SuSE; then
  rc_reset
else
  RETVAL=0
fi

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

# Shell functions sourced from /etc/rc.status only on SuSE Linux:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

test -f $DAEMON  || exit 5

start() {
		# Start daemons.
		echo -n "Starting $DESC: "

		if $SuSE; then
			startproc -p $PIDFILE $DAEMON $OPTARGS 2>/dev/null
			rc_status -v
		else
			daemon cntlm $OPTARGS 2>/dev/null
			RETVAL=$?
			echo
			[ $RETVAL -eq 0 ] && touch $LOCKFILE
			return $RETVAL
		fi
}

stop() {
		echo -n "Shutting down $DESC: "

		if $SuSE; then
		## Stop daemon with killproc(8) and if this fails
		## set echo the echo return value.

		killproc -p $PIDFILE -TERM $DAEMON

		# Remember status and be verbose
		rc_status -v

		else 
			killproc cntlm
			RETVAL=$?
			echo
			[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
			return $RETVAL
		fi
}


# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
	echo -n "Checking for $DESC: "

	if $SuSE; then
	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0.

	# Status has a slightly different for the status command:
	# 0 - service running
	# 1 - service dead, but /var/run/  pid  file exists
	# 2 - service dead, but /var/lock/ lock file exists
	# 3 - service not running

	# NOTE: checkproc returns LSB compliant status values.
	checkproc -p $PIDFILE $DAEMON
	rc_status -v
	else
        	status cntlm
	fi
        ;;
  restart|reload)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
esac

if $SuSE; then
	rc_exit
else
	exit $RETVAL
fi