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