xref: /onnv-gate/usr/src/cmd/ypcmd/ypstart.sh (revision 1573:7338e65f2666)
10Sstevel@tonic-gate#!/bin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*1573Sdp# Common Development and Distribution License (the "License").
7*1573Sdp# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
23*1573Sdp# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate#
260Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate#
280Sstevel@tonic-gate# Enable appropriate NIS daemons based on the current configuration.
290Sstevel@tonic-gate
300Sstevel@tonic-gateenable () {
310Sstevel@tonic-gate	/usr/sbin/svcadm enable -t $1
320Sstevel@tonic-gate	[ $? = 0 ] || echo "ypstart: unable to enable $1"
330Sstevel@tonic-gate
340Sstevel@tonic-gate	if [ "`/usr/bin/svcprop -p restarter/state $1`" = "maintenance" ]; then
350Sstevel@tonic-gate		echo "ypstart: unable to enable $1; in maintenance"
360Sstevel@tonic-gate	fi
370Sstevel@tonic-gate}
380Sstevel@tonic-gate
390Sstevel@tonic-gate
400Sstevel@tonic-gatedomain=`domainname`
410Sstevel@tonic-gateif [ -z "$domain" ]; then
420Sstevel@tonic-gate	echo "ERROR: Default domain is not defined.  \c"
430Sstevel@tonic-gate	echo "Use \"domainname\" to set the domain."
440Sstevel@tonic-gate	exit 1
450Sstevel@tonic-gatefi
460Sstevel@tonic-gate
470Sstevel@tonic-gateecho "starting NIS (YP server) services:\c"
480Sstevel@tonic-gate
49*1573Sdpzone=`/sbin/zonename`
500Sstevel@tonic-gate
510Sstevel@tonic-gateif [ -d /var/yp/$domain ]; then
520Sstevel@tonic-gate	state=`/usr/bin/svcprop -p restarter/state network/nis/server:default`
530Sstevel@tonic-gate
540Sstevel@tonic-gate	[ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypserv`" ]; then
550Sstevel@tonic-gate		echo "ypstart: ypserv already running?"
560Sstevel@tonic-gate	fi
570Sstevel@tonic-gate
580Sstevel@tonic-gate	enable svc:/network/nis/server:default && echo " ypserv\c"
590Sstevel@tonic-gate
600Sstevel@tonic-gate	YP_SERVER=TRUE	# remember we're a server for later
610Sstevel@tonic-gate
620Sstevel@tonic-gate	# check to see if we are the master
630Sstevel@tonic-gate	if [ -f /var/yp/NISLDAPmapping ]; then
640Sstevel@tonic-gate		passwdfile=/var/yp/$domain/LDAP_passwd.byname
650Sstevel@tonic-gate	else
660Sstevel@tonic-gate		passwdfile=/var/yp/$domain/passwd.byname
670Sstevel@tonic-gate	fi
680Sstevel@tonic-gate	master=`/usr/sbin/makedbm -u $passwdfile | grep YP_MASTER_NAME \
690Sstevel@tonic-gate	    | nawk '{ print tolower($2) }'`
700Sstevel@tonic-gatefi
710Sstevel@tonic-gate
720Sstevel@tonic-gate# Enabling the YP client is not strictly necessary, but it is
730Sstevel@tonic-gate# traditional.
740Sstevel@tonic-gatestate=`/usr/bin/svcprop -p restarter/state network/nis/client:default`
750Sstevel@tonic-gate
760Sstevel@tonic-gate[ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypbind`" ]; then
770Sstevel@tonic-gate	echo "ypstart: ypbind already running?"
780Sstevel@tonic-gatefi
790Sstevel@tonic-gate
800Sstevel@tonic-gateenable svc:/network/nis/client:default && echo " ypbind\c"
810Sstevel@tonic-gate
820Sstevel@tonic-gate# do a ypwhich to force ypbind to get bound
830Sstevel@tonic-gateypwhich > /dev/null 2>&1
840Sstevel@tonic-gate
850Sstevel@tonic-gateif [ "$YP_SERVER" = TRUE ]; then
860Sstevel@tonic-gate	# Are we the master server?  If so, start the
870Sstevel@tonic-gate	# ypxfrd, rpc.yppasswdd and rpc.ypupdated daemons.
880Sstevel@tonic-gate	hostname=`uname -n | tr '[A-Z]' '[a-z]'`
890Sstevel@tonic-gate
900Sstevel@tonic-gate	if [ "$master" = "$hostname" ]; then
910Sstevel@tonic-gate		enable svc:/network/nis/xfr:default && echo " ypxfrd\c"
920Sstevel@tonic-gate		enable svc:/network/nis/passwd:default &&
930Sstevel@tonic-gate		    echo " rpc.yppasswdd\c"
940Sstevel@tonic-gate
950Sstevel@tonic-gate		if [ ! -f /var/yp/NISLDAPmapping -a -f /var/yp/updaters ]; then
960Sstevel@tonic-gate			enable svc:/network/nis/update:default &&
970Sstevel@tonic-gate			    echo " rpc.ypupdated\c"
980Sstevel@tonic-gate		fi
990Sstevel@tonic-gate	fi
1000Sstevel@tonic-gatefi
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate# As this operation is likely configuration changing, restart the
1030Sstevel@tonic-gate# name-services milestone (such that configuration-sensitive services
1040Sstevel@tonic-gate# are in turn restarted).
1050Sstevel@tonic-gate/usr/sbin/svcadm restart milestone/name-services
1060Sstevel@tonic-gate
1070Sstevel@tonic-gateecho " done."
108