src/util/distro-import/91/svc-coreadm
changeset 387 397177e3bf8d
parent 378 cff3113e592c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/util/distro-import/91/svc-coreadm	Fri Jun 13 13:58:32 2008 -0700
@@ -0,0 +1,128 @@
+#!/sbin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# ident	"@(#)svc-coreadm	1.4	08/04/25 SMI"
+#
+# Start/refresh method script for the coreadm service.
+#
+
+. /lib/svc/share/smf_include.sh
+
+FMRI=${SMF_FMRI:-svc:/system/coreadm:default}
+
+read_conf() {
+	preamble="svccfg -s $FMRI setprop config_params/"
+
+	< /etc/coreadm.conf sed -n -e "
+	/^COREADM/!d
+	s/^\([^=]*_ENABLED=\)yes/\1true/
+	s/^\([^=]*_ENABLED=\)no/\1false/
+	s,^,$preamble,
+	s/COREADM_GLOB_PATTERN=\(.*\)$/global_pattern = astring: '\"\1\"'/p
+	s/COREADM_GLOB_CONTENT=\(.*\)$/global_content = astring: '\"\1\"'/p
+	s/COREADM_INIT_PATTERN=\(.*\)$/init_pattern = astring: '\"\1\"'/p
+	s/COREADM_INIT_CONTENT=\(.*\)$/init_content = astring: '\"\1\"'/p
+	s/COREADM_GLOB_ENABLED=/global_enabled = boolean: /p
+	s/COREADM_PROC_ENABLED=/process_enabled = boolean: /p
+	s/COREADM_GLOB_SETID_ENABLED=/global_setid_enabled = boolean: /p
+	s/COREADM_PROC_SETID_ENABLED=/process_setid_enabled = boolean: /p
+	s/COREADM_GLOB_LOG_ENABLED=/global_log_enabled = boolean: /p" | sh
+	svcadm refresh $FMRI
+}
+
+getprop() {
+	svcprop -p config_params/$1 $FMRI
+}
+
+error() {
+	echo "Error reading property \"$1\"" 1>&2
+	exit $SMF_EXIT_ERR_CONFIG
+}
+
+set_string() {
+	value="`getprop $1`"
+	[ $? -ne 0 ] && error $1
+	[ "$value" = "\"\"" ] && value=""
+	coreadm $2 "$value"
+}
+
+set_boolean() {
+	enabled="`getprop $1`"
+	[ $? -ne 0 ] && error $1
+	if [ "$enabled" = "true" ]; then
+		coreadm -e $2
+	else
+		coreadm -d $2
+	fi
+}
+
+apply_conf() {
+	set_string global_content -G
+	set_string init_content -I
+	set_string global_pattern -g
+	set_string init_pattern -i
+
+	set_boolean global_log_enabled log
+	set_boolean global_enabled global
+	set_boolean global_setid_enabled global-setid
+	set_boolean process_enabled process
+	set_boolean process_setid_enabled proc-setid
+}
+
+case $1 in
+"start")
+	# By virtue of using coreadm to effect coreadm changes,
+	# coreadm.conf should always be up-to-date.  Treat it as
+	# authoritative on boot to a) handle upgrade, and b)
+	# handle the situation where administrators are using
+	# the command to make customizations.
+	#
+	# In the off chance there is no coreadm.conf, apply the
+	# the SMF configuration.
+
+	if [ -f /etc/coreadm.conf ]; then
+		read_conf
+		coreadm -u
+	else
+		apply_conf
+	fi
+	;;
+"refresh")
+	# Refresh implies someone wants to apply the configuration
+	# stored in the service.  Do so.
+	#
+	# It is possible for someone to use coreadm directly and
+	# subsequently issue a refresh, resulting in the initial
+	# changes being lost.  Given that a refresh will either be
+	# issued explicitly by the administrator or by a
+	# configuration activity that has made changes to the SMF
+	# configuration and expects those changes to be applied,
+	# this shouldn't be a big problem.
+
+	apply_conf
+	;;
+esac
+
+exit $SMF_EXIT_OK