xref: /titanic_44/usr/src/cmd/ypcmd/ypstart.sh (revision 749f21d359d8fbd020c974a1a5227316221bfc9c)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"%Z%%M%	%I%	%E% SMI"
28#
29# Enable appropriate NIS daemons based on the current configuration.
30
31enable () {
32	/usr/sbin/svcadm enable -t $1
33	[ $? = 0 ] || echo "ypstart: unable to enable $1"
34
35	if [ "`/usr/bin/svcprop -p restarter/state $1`" = "maintenance" ]; then
36		echo "ypstart: unable to enable $1; in maintenance"
37	fi
38}
39
40
41domain=`domainname`
42if [ -z "$domain" ]; then
43	echo "ERROR: Default domain is not defined.  \c"
44	echo "Use \"domainname\" to set the domain."
45	exit 1
46fi
47
48echo "starting NIS (YP server) services:\c"
49
50zone=`/usr/bin/zonename`
51
52if [ -d /var/yp/$domain ]; then
53	state=`/usr/bin/svcprop -p restarter/state network/nis/server:default`
54
55	[ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypserv`" ]; then
56		echo "ypstart: ypserv already running?"
57	fi
58
59	enable svc:/network/nis/server:default && echo " ypserv\c"
60
61	YP_SERVER=TRUE	# remember we're a server for later
62
63	# check to see if we are the master
64	if [ -f /var/yp/NISLDAPmapping ]; then
65		passwdfile=/var/yp/$domain/LDAP_passwd.byname
66	else
67		passwdfile=/var/yp/$domain/passwd.byname
68	fi
69	master=`/usr/sbin/makedbm -u $passwdfile | grep YP_MASTER_NAME \
70	    | nawk '{ print tolower($2) }'`
71fi
72
73# Enabling the YP client is not strictly necessary, but it is
74# traditional.
75state=`/usr/bin/svcprop -p restarter/state network/nis/client:default`
76
77[ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypbind`" ]; then
78	echo "ypstart: ypbind already running?"
79fi
80
81enable svc:/network/nis/client:default && echo " ypbind\c"
82
83# do a ypwhich to force ypbind to get bound
84ypwhich > /dev/null 2>&1
85
86if [ "$YP_SERVER" = TRUE ]; then
87	# Are we the master server?  If so, start the
88	# ypxfrd, rpc.yppasswdd and rpc.ypupdated daemons.
89	hostname=`uname -n | tr '[A-Z]' '[a-z]'`
90
91	if [ "$master" = "$hostname" ]; then
92		enable svc:/network/nis/xfr:default && echo " ypxfrd\c"
93		enable svc:/network/nis/passwd:default &&
94		    echo " rpc.yppasswdd\c"
95
96		if [ ! -f /var/yp/NISLDAPmapping -a -f /var/yp/updaters ]; then
97			enable svc:/network/nis/update:default &&
98			    echo " rpc.ypupdated\c"
99		fi
100	fi
101fi
102
103# As this operation is likely configuration changing, restart the
104# name-services milestone (such that configuration-sensitive services
105# are in turn restarted).
106/usr/sbin/svcadm restart milestone/name-services
107
108echo " done."
109