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