xref: /onnv-gate/usr/src/cmd/svc/shell/netservices.sh (revision 11996:91b62f7b8186)
12104Sjjj#!/bin/sh
22104Sjjj#
32104Sjjj# CDDL HEADER START
42104Sjjj#
52104Sjjj# The contents of this file are subject to the terms of the
62104Sjjj# Common Development and Distribution License (the "License").
72104Sjjj# You may not use this file except in compliance with the License.
82104Sjjj#
92104Sjjj# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102104Sjjj# or http://www.opensolaris.org/os/licensing.
112104Sjjj# See the License for the specific language governing permissions
122104Sjjj# and limitations under the License.
132104Sjjj#
142104Sjjj# When distributing Covered Code, include this CDDL HEADER in each
152104Sjjj# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162104Sjjj# If applicable, add the following below this CDDL HEADER, with the
172104Sjjj# fields enclosed by brackets "[]" replaced with your own identifying
182104Sjjj# information: Portions Copyright [yyyy] [name of copyright owner]
192104Sjjj#
202104Sjjj# CDDL HEADER END
212104Sjjj#
22*11996SThomas.Whitten@Sun.COM# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
232104Sjjj# Use is subject to license terms.
242104Sjjj#
252104Sjjj
262104SjjjDT_CHANGED=0
272104Sjjj
282104SjjjLOG_FMRI=svc:/system/system-log
292104SjjjCMSD_FMRI=svc:/network/rpc/cde-calendar-manager
302104SjjjBIND_FMRI=svc:/network/rpc/bind
312104SjjjXSERVER_FMRI=svc:/application/x11/x11-server
322104SjjjSENDMAIL_FMRI=svc:/network/smtp:sendmail
333781SceasthaPRINTSERVER_FMRI=svc:/application/print/server
342104SjjjRFC1179_FMRI=svc:/application/print/rfc1179
356237SjacobsCUPSSERVER_FMRI=svc:/application/cups/scheduler
366237SjacobsCUPSRFC1179_FMRI=svc:/application/cups/in-lpd
373781SceasthaIPPLISTENER_FMRI=svc:/application/print/ipp-listener
382104SjjjTTDB_FMRI=svc:/network/rpc/cde-ttdbserver
392104SjjjDTLOGIN_FMRI=svc:/application/graphical-login/cde-login
402104SjjjWEBCONSOLE_FMRI=svc:/system/webconsole
412238SrotondoSMCWBEM_FMRI=svc:/application/management/wbem
422104Sjjj
432104Sjjjusage()
442104Sjjj{
452104Sjjj	prog=`basename $0`
462104Sjjj	echo "$prog: usage: $prog [ open | limited ]" >&2
472104Sjjj	exit 2
482104Sjjj}
492104Sjjj
502104Sjjj#
512104Sjjj# set_property fmri group property value
522104Sjjj#
532104Sjjj# sets the specified property in the specified property-group, creating
542104Sjjj# the group and or property if necessary.
552104Sjjj#
562104Sjjjset_property()
572104Sjjj{
582104Sjjj	fmri=$1
592104Sjjj	group=$2
602104Sjjj	prop=$3
612104Sjjj	val=$4
622104Sjjj
632104Sjjj	if svcprop -qp $group $fmri; then :; else
642104Sjjj		if svccfg -s $fmri addpg $group application; then :; else
652104Sjjj			echo "Failed to create property group \"$group\" \c"
662104Sjjj			echo "for $fmri."
672104Sjjj			exit 1
682104Sjjj		fi
692104Sjjj	fi
702104Sjjj
712104Sjjj	if svccfg -s $fmri setprop $group/$prop = boolean: $val; then :; else
722104Sjjj		echo "Failed to set property $group/$prop for $fmri"
732104Sjjj		exit 1
742104Sjjj	fi
752104Sjjj}
762104Sjjj
772104Sjjjset_system_log()
782104Sjjj{
792104Sjjj	svcprop -q $LOG_FMRI || return
802104Sjjj	if [ "$1" = "local" ]; then
812104Sjjj		val=false
822104Sjjj	else
832104Sjjj		val=true
842104Sjjj	fi
852104Sjjj
862104Sjjj	set_property $LOG_FMRI config log_from_remote $val
872104Sjjj	svcadm refresh $LOG_FMRI
882104Sjjj}
892104Sjjj
902104Sjjjset_cmsd()
912104Sjjj{
922104Sjjj	svcprop -q $CMSD_FMRI:default || return
932104Sjjj	if [ "$1" = "local" ]; then
942104Sjjj		proto="ticlts"
952104Sjjj	else
962104Sjjj		proto="udp"
972104Sjjj	fi
982104Sjjj
992104Sjjj	inetadm -m $CMSD_FMRI:default proto=$proto
1002104Sjjj	svcadm refresh $CMSD_FMRI:default
1012104Sjjj}
1022104Sjjj
1032104Sjjjset_rpcbind()
1042104Sjjj{
1052104Sjjj	svcprop -q $BIND_FMRI || return
1062104Sjjj	if [ "$1" = "local" ]; then
1072104Sjjj		val=true
1082104Sjjj	else
1092104Sjjj		val=false
1102104Sjjj	fi
1112104Sjjj
1122104Sjjj	set_property $BIND_FMRI config local_only $val
1132104Sjjj	svcadm refresh $BIND_FMRI
1142104Sjjj}
1152104Sjjj
1162104Sjjjset_xserver() {
1172104Sjjj	svcprop -q $XSERVER_FMRI || return
1182104Sjjj	if [ "$1" = "local" ]; then
1192104Sjjj		val=false
1202104Sjjj	else
1212104Sjjj		val=true
1222104Sjjj	fi
1232104Sjjj
1242104Sjjj	set_property $XSERVER_FMRI options tcp_listen $val
1252104Sjjj	# don't need refresh since x11-server is not an actual service
1262104Sjjj}
1272104Sjjj
1282104Sjjjset_sendmail()
1292104Sjjj{
1302104Sjjj	svcprop -q $SENDMAIL_FMRI || return
1312104Sjjj	if [ "$1" = "local" ]; then
1322104Sjjj		val=true
1332104Sjjj	else
1342104Sjjj		val=false
1352104Sjjj	fi
1362104Sjjj
1372104Sjjj	set_property $SENDMAIL_FMRI config local_only $val
1382104Sjjj	svcadm refresh $SENDMAIL_FMRI
1392104Sjjj}
1402104Sjjj
1412104Sjjjset_ttdbserver()
1422104Sjjj{
1432104Sjjj	svcprop -q $TTDB_FMRI:tcp || return
1442104Sjjj	if [ "$1" = "local" ]; then
1452104Sjjj		val=ticotsord
1462104Sjjj	else
1472104Sjjj		val=tcp
1482104Sjjj	fi
1492104Sjjj	inetadm -m $TTDB_FMRI:tcp proto="$val"
1502104Sjjj	svcadm refresh $TTDB_FMRI:tcp
1512104Sjjj}
1522104Sjjj
1532104Sjjjset_dtlogin()
1542104Sjjj{
1552104Sjjj	svcprop -q $DTLOGIN_FMRI || return
1562104Sjjj
1572104Sjjj	eval args=`svcprop -p dtlogin/args $DTLOGIN_FMRI`
1582104Sjjj
1592104Sjjj	if echo $args | egrep -s udpPort
1602104Sjjj	then
1612104Sjjj		old_port=`echo $args |
1622104Sjjj		    sed 's/.*-udpPort [ ]*\([0-9][0-9]*\).*/\1/'`
1632104Sjjj		new_args=`echo $args |
1642104Sjjj		    sed 's/\(.*\)-udpPort [0-9][0-9]*\(.*\)/\1\2/'`
1652104Sjjj	else
1662104Sjjj		old_port=-1
1672104Sjjj		new_args=$args
1682104Sjjj	fi
1692104Sjjj
1702104Sjjj	if [ "$1" = "local" ]; then
1712104Sjjj		args="$new_args -udpPort 0"
1722104Sjjj		DT_CHANGED=1
1732104Sjjj	else
1742104Sjjj		# remove '-udpPort 0' argument. Leave intact if port != 0.
1752104Sjjj		if [ $old_port -eq 0 ]; then
1762104Sjjj			args="$new_args"
1772104Sjjj			DT_CHANGED=1
1782104Sjjj		fi
1792104Sjjj	fi
1802104Sjjj
1812104Sjjj	svccfg -s $DTLOGIN_FMRI setprop dtlogin/args = "\"$args\""
1822104Sjjj	svcadm refresh $DTLOGIN_FMRI
1832104Sjjj}
1842104Sjjj
1852104Sjjjset_webconsole() {
1862104Sjjj	svcprop -q $WEBCONSOLE_FMRI:console || return
1872104Sjjj	if [ "$1" = "local" ]; then
1882104Sjjj		val=false
1892104Sjjj	else
1902104Sjjj		val=true
1912104Sjjj	fi
1922104Sjjj
1932104Sjjj	set_property $WEBCONSOLE_FMRI options tcp_listen $val
1942104Sjjj	svcadm refresh $WEBCONSOLE_FMRI
1952104Sjjj}
1962104Sjjj
1972104Sjjjset_smcwbem() {
1982104Sjjj	svcprop -q $SMCWBEM_FMRI:default || return
1992104Sjjj	if [ "$1" = "local" ]; then
2002104Sjjj		val=false
2012104Sjjj	else
2022104Sjjj		val=true
2032104Sjjj	fi
2042104Sjjj
2052104Sjjj	set_property $SMCWBEM_FMRI options tcp_listen $val
2062104Sjjj	svcadm refresh $SMCWBEM_FMRI
2072104Sjjj}
2082104Sjjj
2096237Sjacobsset_printing() {
2106237Sjacobs	use_cups=`svcprop -C -p general/active $CUPSSERVER_FMRI:default \
2116237Sjacobs		  2>/dev/null`
2126237Sjacobs
2136237Sjacobs	case "$1" in
2146237Sjacobs	"open")
2156237Sjacobs		cups_options="--remote-admin --remote-printers"
2166237Sjacobs		cups_options="$cups_options --share-printers --remote-any"
2176237Sjacobs		svc_operation="enable"
2186237Sjacobs		;;
2196237Sjacobs	"local")
2206237Sjacobs		cups_options="--no-remote-admin --no-remote-printers"
2216237Sjacobs		cups_options="$cups_options --no-share-printers --no-remote-any"
2226237Sjacobs		svc_operation="disable"
2236237Sjacobs		;;
2246237Sjacobs	esac
2256237Sjacobs
2266237Sjacobs	case "$use_cups" in
2276237Sjacobs	"true")
2286237Sjacobs		if [ -x /usr/sbin/cupsctl ] ; then
2296237Sjacobs			# only run cupsctl with elevated privilege to avoid
2306237Sjacobs			# being prompted for a password
2316237Sjacobs			[ `/usr/bin/id -u` = 0 ] &&
2326237Sjacobs				/usr/sbin/cupsctl $cups_options
2336237Sjacobs		fi
2346237Sjacobs		svcadm $svc_operation $CUPSRFC1179_FMRI
2356237Sjacobs		;;
2366237Sjacobs	*)
2376237Sjacobs		if [ "`svcprop -p restarter/state $PRINTSERVER_FMRI:default`" \
2386237Sjacobs		     != "disabled" ] ; then
2396237Sjacobs			svcadm $svc_operation $RFC1179_FMRI:default
2406237Sjacobs			svcadm $svc_operation $IPPLISTENER_FMRI:default
2416237Sjacobs		fi
2426237Sjacobs		;;
2436237Sjacobs	esac
2446237Sjacobs}
2456237Sjacobs
2462104Sjjjif [ $# -ne 1 ]; then
2472104Sjjj	usage
2482104Sjjjfi
2492104Sjjj
2502104Sjjjcase $1 in
2512104Sjjj	"open")
2522104Sjjj		profile=generic_open.xml
2532104Sjjj		keyword="open"
2542104Sjjj		;;
2552104Sjjj	"limited")
2562104Sjjj		profile=generic_limited_net.xml
2572104Sjjj		keyword="local"
2582104Sjjj		;;
2592104Sjjj	*)
2602104Sjjj		usage
2612104Sjjj		;;
2622104Sjjjesac
2632104Sjjj
264*11996SThomas.Whitten@Sun.COMif [ ! -f /etc/svc/profile/$profile ]; then
265*11996SThomas.Whitten@Sun.COM	echo "/etc/svc/profile/$profile nonexistent. Exiting."
2662104Sjjj	exit 1
2672104Sjjjfi
2682104Sjjj
2692104Sjjj#
2702104Sjjj# set services
2712104Sjjj#
2722104Sjjjset_system_log $keyword
2732104Sjjjset_cmsd $keyword
2742104Sjjjset_rpcbind $keyword
2752104Sjjjset_xserver $keyword
2762104Sjjjset_sendmail $keyword
2772104Sjjjset_ttdbserver $keyword
2782104Sjjjset_dtlogin $keyword
2792104Sjjjset_webconsole $keyword
2802104Sjjjset_smcwbem $keyword
2816237Sjacobsset_printing $keyword
2822104Sjjj
2832104Sjjj#
2842104Sjjj# put the new profile into place, and apply it
2852104Sjjj#
2869765SSean.Wilcox@Sun.COM# Create a hash entry so that manifest_import is aware of the
2879765SSean.Wilcox@Sun.COM# profile being applied and does not reapply the profile on reboot.
2889765SSean.Wilcox@Sun.COM#
289*11996SThomas.Whitten@Sun.COMln -sf ./$profile /etc/svc/profile/generic.xml
290*11996SThomas.Whitten@Sun.COMsvccfg delhash /etc/svc/profile/generic.xml > /dev/null 2>&1
291*11996SThomas.Whitten@Sun.COMSVCCFG_CHECKHASH="TRUE" svccfg apply /etc/svc/profile/generic.xml
292*11996SThomas.Whitten@Sun.COM
293*11996SThomas.Whitten@Sun.COM#
294*11996SThomas.Whitten@Sun.COM# generic_open may not start inetd services on upgraded systems
295*11996SThomas.Whitten@Sun.COM#
2962261Srotondoif [ $profile = "generic_open.xml" ]
2972261Srotondothen
298*11996SThomas.Whitten@Sun.COM	svccfg apply /etc/svc/profile/inetd_generic.xml
2992261Srotondofi
3002104Sjjj
3012104Sjjj#
3022104Sjjj# Make the services aware of the new property values
3032104Sjjj#
3042104Sjjjif [ "`svcprop -p restarter/state $LOG_FMRI:default`" = "online" ]
3052104Sjjjthen
3062104Sjjj	# need restart since refresh won't reread properties
3072104Sjjj	echo "restarting syslogd"
3082104Sjjj	svcadm restart $LOG_FMRI:default
3092104Sjjjfi
3102104Sjjj
3112104Sjjjif [ "`svcprop -p restarter/state $SENDMAIL_FMRI`" = "online" ]
3122104Sjjjthen
3132104Sjjj	# need restart since refresh won't pick up new command-line
3142104Sjjj	echo "restarting sendmail"
3152104Sjjj	svcadm restart $SENDMAIL_FMRI
3162104Sjjjfi
3172104Sjjj
3182238Srotondoif [ "`svcprop -p restarter/state $SMCWBEM_FMRI:default`" = "online" ]
3192238Srotondothen
3202238Srotondo	# need restart since refresh won't pick up new command-line
3212238Srotondo	echo "restarting wbem"
3222238Srotondo	svcadm restart $SMCWBEM_FMRI:default
3232238Srotondofi
3242238Srotondo
3252104Sjjjif [ $DT_CHANGED -eq 1 ]; then
3262104Sjjj	if [ "`svcprop -p restarter/state $DTLOGIN_FMRI:default`" = "online" ]
3272104Sjjj	then
3282104Sjjj		r="y"
3292104Sjjj		if tty -s ; then
3302104Sjjj			printf \
3312104Sjjj			    "dtlogin needs to be restarted. Restart now? [Y] "
3322104Sjjj			read r
3332104Sjjj		fi
3342104Sjjj		if [ "$r" = "" -o "$r" = "y" -o "$r" = "Y" ]; then
3352104Sjjj			# Make sure we survive killing dtlogin...
3362104Sjjj			trap "" 15
3372104Sjjj			svcadm restart $DTLOGIN_FMRI
3382104Sjjj			echo "restarting dtlogin"
3392104Sjjj		else
3402104Sjjj			printf "dtlogin not restarted. "
3412104Sjjj			printf "Restart it to put it in ${keyword}-mode.\n"
3422104Sjjj		fi
3432104Sjjj	fi
3442104Sjjjfi
345