8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / ypcmd / ypstart.sh
blob69630911ebb48eef2f57b7264663a2827737ffb0
1 #!/bin/sh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # ident "%Z%%M% %I% %E% SMI"
28 # Enable appropriate NIS daemons based on the current configuration.
30 enable () {
31 /usr/sbin/svcadm enable -t $1
32 [ $? = 0 ] || echo "ypstart: unable to enable $1"
34 if [ "`/usr/bin/svcprop -p restarter/state $1`" = "maintenance" ]; then
35 echo "ypstart: unable to enable $1; in maintenance"
40 domain=`domainname`
41 if [ -z "$domain" ]; then
42 echo "ERROR: Default domain is not defined. \c"
43 echo "Use \"domainname\" to set the domain."
44 exit 1
47 echo "starting NIS (YP server) services:\c"
49 zone=`/sbin/zonename`
51 if [ -d /var/yp/$domain ]; then
52 state=`/usr/bin/svcprop -p restarter/state network/nis/server:default`
54 [ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypserv`" ]; then
55 echo "ypstart: ypserv already running?"
58 enable svc:/network/nis/server:default && echo " ypserv\c"
60 YP_SERVER=TRUE # remember we're a server for later
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
68 master=`/usr/sbin/makedbm -u $passwdfile | grep YP_MASTER_NAME \
69 | nawk '{ print tolower($2) }'`
72 # Enabling the YP client is not strictly necessary, but it is
73 # traditional.
74 state=`/usr/bin/svcprop -p restarter/state network/nis/client:default`
76 [ "$state" = "disabled" ] && if [ -n "`pgrep -z $zone ypbind`" ]; then
77 echo "ypstart: ypbind already running?"
80 enable svc:/network/nis/client:default && echo " ypbind\c"
82 # do a ypwhich to force ypbind to get bound
83 ypwhich > /dev/null 2>&1
85 if [ "$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]'`
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"
95 if [ ! -f /var/yp/NISLDAPmapping -a -f /var/yp/updaters ]; then
96 enable svc:/network/nis/update:default &&
97 echo " rpc.ypupdated\c"
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
107 echo " done."