#!/bin/sh
#
# Copyright (c) 1995, by Sun Microsystems, Inc.
# All Rights Reserved
#
#ident  "$Header: /net/projects/S2.6/cvs/os_net/src_ws/usr/src/tadcmd/locations/init.d/inetd,v 1.1 1997/10/09 10:36:58 ang Exp $"
#
#LocINFO Internet daemon
#
# This is third phase of TCP/IP startup/configuration.  This script
# runs after the NIS/NIS+ startup script.
#

hupproc() {		# kill the named process(es)
	pid=`/usr/bin/ps -e |
	     /usr/bin/grep " ${1}$" |
	     /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	[ "$pid" != "" ] && kill -HUP $pid
}

procexist() {
    pid=`/usr/bin/ps -e | /usr/bin/grep " ${1}$" |
	     /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
    if [ -z "$pid" ]
    then
	return 1
    fi
    return 0
}

case "$1" in
'start')
    cp -p $LOCDB/etc/inet/inetd.conf /etc/inet

    #
    # If inetd is running (it probably is as it's not killed below)
    # simply tell it to re-read the conf file.
    #
    if procexist inetd
    then
	hupproc inetd
    else
	/usr/sbin/inetd -s
    fi
    ;;

'stop')
    # Killing inetd is not a good idea if you want to keep CDE running
    # so don't do anything now. The inetd services should have been
    # killed by the inetsvc script before getting here.

#    killproc inetd
#    rm -f /etc/inet/inetd.conf
    ;;

'create')
    echo "/etc/inet\n/etc/inet/inetd.conf" | cpio -pdmu $LOCDB 2>/dev/null
    exit `procexist inetd && [ -f /etc/inetd.conf ]`
    ;;

*)
    echo "Usage: $0 { start | stop | create }" 1>&2
    ;;
esac

exit 0
