netservices.sh revision 2104:ce72b74b05fd
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# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23# Use is subject to license terms. 24# 25 26# ident "%Z%%M% %I% %E% SMI" 27 28DT_CHANGED=0 29 30LOG_FMRI=svc:/system/system-log 31CMSD_FMRI=svc:/network/rpc/cde-calendar-manager 32INETD_FMRI=svc:/network/inetd 33BIND_FMRI=svc:/network/rpc/bind 34XSERVER_FMRI=svc:/application/x11/x11-server 35SENDMAIL_FMRI=svc:/network/smtp:sendmail 36RFC1179_FMRI=svc:/application/print/rfc1179 37TTDB_FMRI=svc:/network/rpc/cde-ttdbserver 38DTLOGIN_FMRI=svc:/application/graphical-login/cde-login 39WEBCONSOLE_FMRI=svc:/system/webconsole 40SMCWBEM_FMRI=svc:/application/smcwbem 41 42usage() 43{ 44 prog=`basename $0` 45 echo "$prog: usage: $prog [ open | limited ]" >&2 46 exit 2 47} 48 49# 50# set_property fmri group property value 51# 52# sets the specified property in the specified property-group, creating 53# the group and or property if necessary. 54# 55set_property() 56{ 57 fmri=$1 58 group=$2 59 prop=$3 60 val=$4 61 62 if svcprop -qp $group $fmri; then :; else 63 if svccfg -s $fmri addpg $group application; then :; else 64 echo "Failed to create property group \"$group\" \c" 65 echo "for $fmri." 66 exit 1 67 fi 68 fi 69 70 if svccfg -s $fmri setprop $group/$prop = boolean: $val; then :; else 71 echo "Failed to set property $group/$prop for $fmri" 72 exit 1 73 fi 74} 75 76set_system_log() 77{ 78 svcprop -q $LOG_FMRI || return 79 if [ "$1" = "local" ]; then 80 val=false 81 else 82 val=true 83 fi 84 85 set_property $LOG_FMRI config log_from_remote $val 86 svcadm refresh $LOG_FMRI 87} 88 89set_cmsd() 90{ 91 svcprop -q $CMSD_FMRI:default || return 92 if [ "$1" = "local" ]; then 93 proto="ticlts" 94 else 95 proto="udp" 96 fi 97 98 inetadm -m $CMSD_FMRI:default proto=$proto 99 svcadm refresh $CMSD_FMRI:default 100} 101 102set_rpcbind() 103{ 104 svcprop -q $BIND_FMRI || return 105 if [ "$1" = "local" ]; then 106 val=true 107 else 108 val=false 109 fi 110 111 set_property $BIND_FMRI config local_only $val 112 svcadm refresh $BIND_FMRI 113} 114 115set_xserver() { 116 svcprop -q $XSERVER_FMRI || return 117 if [ "$1" = "local" ]; then 118 val=false 119 else 120 val=true 121 fi 122 123 set_property $XSERVER_FMRI options tcp_listen $val 124 # don't need refresh since x11-server is not an actual service 125} 126 127set_sendmail() 128{ 129 svcprop -q $SENDMAIL_FMRI || return 130 if [ "$1" = "local" ]; then 131 val=true 132 else 133 val=false 134 fi 135 136 set_property $SENDMAIL_FMRI config local_only $val 137 svcadm refresh $SENDMAIL_FMRI 138} 139 140set_rfc1179() 141{ 142 svcprop -q $RFC1179_FMRI:default || return 143 if [ "$1" = "local" ]; then 144 val=localhost 145 else 146 val= 147 fi 148 inetadm -m $RFC1179_FMRI:default bind_addr="$val" 2>/dev/null 149 svcadm refresh $RFC1179_FMRI:default 150} 151 152set_ttdbserver() 153{ 154 svcprop -q $TTDB_FMRI:tcp || return 155 if [ "$1" = "local" ]; then 156 val=ticotsord 157 else 158 val=tcp 159 fi 160 inetadm -m $TTDB_FMRI:tcp proto="$val" 161 svcadm refresh $TTDB_FMRI:tcp 162} 163 164set_dtlogin() 165{ 166 svcprop -q $DTLOGIN_FMRI || return 167 168 eval args=`svcprop -p dtlogin/args $DTLOGIN_FMRI` 169 170 if echo $args | egrep -s udpPort 171 then 172 old_port=`echo $args | 173 sed 's/.*-udpPort [ ]*\([0-9][0-9]*\).*/\1/'` 174 new_args=`echo $args | 175 sed 's/\(.*\)-udpPort [0-9][0-9]*\(.*\)/\1\2/'` 176 else 177 old_port=-1 178 new_args=$args 179 fi 180 181 if [ "$1" = "local" ]; then 182 args="$new_args -udpPort 0" 183 DT_CHANGED=1 184 else 185 # remove '-udpPort 0' argument. Leave intact if port != 0. 186 if [ $old_port -eq 0 ]; then 187 args="$new_args" 188 DT_CHANGED=1 189 fi 190 fi 191 192 svccfg -s $DTLOGIN_FMRI setprop dtlogin/args = "\"$args\"" 193 svcadm refresh $DTLOGIN_FMRI 194} 195 196set_webconsole() { 197 svcprop -q $WEBCONSOLE_FMRI:console || return 198 if [ "$1" = "local" ]; then 199 val=false 200 else 201 val=true 202 fi 203 204 set_property $WEBCONSOLE_FMRI options tcp_listen $val 205 svcadm refresh $WEBCONSOLE_FMRI 206} 207 208set_smcwbem() { 209 svcprop -q $SMCWBEM_FMRI:default || return 210 if [ "$1" = "local" ]; then 211 val=false 212 else 213 val=true 214 fi 215 216 set_property $SMCWBEM_FMRI options tcp_listen $val 217 svcadm refresh $SMCWBEM_FMRI 218} 219 220if [ $# -ne 1 ]; then 221 usage 222fi 223 224case $1 in 225 "open") 226 profile=generic_open.xml 227 keyword="open" 228 ;; 229 "limited") 230 profile=generic_limited_net.xml 231 keyword="local" 232 ;; 233 *) 234 usage 235 ;; 236esac 237 238if [ ! -f /var/svc/profile/$profile ]; then 239 echo "/var/svc/profile/$profile nonexistent. Exiting." 240 exit 1 241fi 242 243# 244# set services 245# 246set_system_log $keyword 247set_cmsd $keyword 248set_rpcbind $keyword 249set_xserver $keyword 250set_sendmail $keyword 251set_rfc1179 $keyword 252set_ttdbserver $keyword 253set_dtlogin $keyword 254set_webconsole $keyword 255set_smcwbem $keyword 256 257# 258# put the new profile into place, and apply it 259# 260ln -sf ./$profile /var/svc/profile/generic.xml 261svccfg apply /var/svc/profile/generic.xml 262 263# 264# Make the services aware of the new property values 265# 266if [ "`svcprop -p restarter/state $LOG_FMRI:default`" = "online" ] 267then 268 # need restart since refresh won't reread properties 269 echo "restarting syslogd" 270 svcadm restart $LOG_FMRI:default 271fi 272 273if [ "`svcprop -p restarter/state $SENDMAIL_FMRI`" = "online" ] 274then 275 # need restart since refresh won't pick up new command-line 276 echo "restarting sendmail" 277 svcadm restart $SENDMAIL_FMRI 278fi 279 280if [ "`svcprop -p restarter/state $BIND_FMRI:default`" = "online" ] 281then 282 # since inetd won't successfully re-register RPC-services after 283 # rpcbind restarts, we need to stop/start inetd too (and serialize 284 # these state-transitions) 285 svcadm disable -s $INETD_FMRI:default 286 svcadm disable -s $BIND_FMRI:default 287 echo "restarting rpcbind" 288 svcadm enable -s $BIND_FMRI:default 289 echo "restarting inetd" 290 svcadm enable -s $INETD_FMRI:default 291fi 292 293if [ $DT_CHANGED -eq 1 ]; then 294 if [ "`svcprop -p restarter/state $DTLOGIN_FMRI:default`" = "online" ] 295 then 296 r="y" 297 if tty -s ; then 298 printf \ 299 "dtlogin needs to be restarted. Restart now? [Y] " 300 read r 301 fi 302 if [ "$r" = "" -o "$r" = "y" -o "$r" = "Y" ]; then 303 # Make sure we survive killing dtlogin... 304 trap "" 15 305 svcadm restart $DTLOGIN_FMRI 306 echo "restarting dtlogin" 307 else 308 printf "dtlogin not restarted. " 309 printf "Restart it to put it in ${keyword}-mode.\n" 310 fi 311 fi 312fi 313