author | David.Comay@Sun.COM |
Fri, 13 Jun 2008 13:58:32 -0700 | |
changeset 387 | 397177e3bf8d |
parent 378 | src/util/distro-import/90/svc-coreadm@cff3113e592c |
permissions | -rw-r--r-- |
345
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
1 |
#!/sbin/sh |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
2 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
4 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
8 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
13 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
19 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
21 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
22 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
23 |
# Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
24 |
# Use is subject to license terms. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
25 |
# |
358
c4384faec98d
1613 svc-coreadm maps an empty pattern or content string to "astring:"
David Powell <David.Powell@sun.com>
parents:
345
diff
changeset
|
26 |
# ident "@(#)svc-coreadm 1.4 08/04/25 SMI" |
345
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
27 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
28 |
# Start/refresh method script for the coreadm service. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
29 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
30 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
31 |
. /lib/svc/share/smf_include.sh |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
32 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
33 |
FMRI=${SMF_FMRI:-svc:/system/coreadm:default} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
34 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
35 |
read_conf() { |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
36 |
preamble="svccfg -s $FMRI setprop config_params/" |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
37 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
38 |
< /etc/coreadm.conf sed -n -e " |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
39 |
/^COREADM/!d |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
40 |
s/^\([^=]*_ENABLED=\)yes/\1true/ |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
41 |
s/^\([^=]*_ENABLED=\)no/\1false/ |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
42 |
s,^,$preamble, |
358
c4384faec98d
1613 svc-coreadm maps an empty pattern or content string to "astring:"
David Powell <David.Powell@sun.com>
parents:
345
diff
changeset
|
43 |
s/COREADM_GLOB_PATTERN=\(.*\)$/global_pattern = astring: '\"\1\"'/p |
c4384faec98d
1613 svc-coreadm maps an empty pattern or content string to "astring:"
David Powell <David.Powell@sun.com>
parents:
345
diff
changeset
|
44 |
s/COREADM_GLOB_CONTENT=\(.*\)$/global_content = astring: '\"\1\"'/p |
c4384faec98d
1613 svc-coreadm maps an empty pattern or content string to "astring:"
David Powell <David.Powell@sun.com>
parents:
345
diff
changeset
|
45 |
s/COREADM_INIT_PATTERN=\(.*\)$/init_pattern = astring: '\"\1\"'/p |
c4384faec98d
1613 svc-coreadm maps an empty pattern or content string to "astring:"
David Powell <David.Powell@sun.com>
parents:
345
diff
changeset
|
46 |
s/COREADM_INIT_CONTENT=\(.*\)$/init_content = astring: '\"\1\"'/p |
345
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
47 |
s/COREADM_GLOB_ENABLED=/global_enabled = boolean: /p |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
48 |
s/COREADM_PROC_ENABLED=/process_enabled = boolean: /p |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
49 |
s/COREADM_GLOB_SETID_ENABLED=/global_setid_enabled = boolean: /p |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
50 |
s/COREADM_PROC_SETID_ENABLED=/process_setid_enabled = boolean: /p |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
51 |
s/COREADM_GLOB_LOG_ENABLED=/global_log_enabled = boolean: /p" | sh |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
52 |
svcadm refresh $FMRI |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
53 |
} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
54 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
55 |
getprop() { |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
56 |
svcprop -p config_params/$1 $FMRI |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
57 |
} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
58 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
59 |
error() { |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
60 |
echo "Error reading property \"$1\"" 1>&2 |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
61 |
exit $SMF_EXIT_ERR_CONFIG |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
62 |
} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
63 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
64 |
set_string() { |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
65 |
value="`getprop $1`" |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
66 |
[ $? -ne 0 ] && error $1 |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
67 |
[ "$value" = "\"\"" ] && value="" |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
68 |
coreadm $2 "$value" |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
69 |
} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
70 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
71 |
set_boolean() { |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
72 |
enabled="`getprop $1`" |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
73 |
[ $? -ne 0 ] && error $1 |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
74 |
if [ "$enabled" = "true" ]; then |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
75 |
coreadm -e $2 |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
76 |
else |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
77 |
coreadm -d $2 |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
78 |
fi |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
79 |
} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
80 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
81 |
apply_conf() { |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
82 |
set_string global_content -G |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
83 |
set_string init_content -I |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
84 |
set_string global_pattern -g |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
85 |
set_string init_pattern -i |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
86 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
87 |
set_boolean global_log_enabled log |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
88 |
set_boolean global_enabled global |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
89 |
set_boolean global_setid_enabled global-setid |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
90 |
set_boolean process_enabled process |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
91 |
set_boolean process_setid_enabled proc-setid |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
92 |
} |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
93 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
94 |
case $1 in |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
95 |
"start") |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
96 |
# By virtue of using coreadm to effect coreadm changes, |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
97 |
# coreadm.conf should always be up-to-date. Treat it as |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
98 |
# authoritative on boot to a) handle upgrade, and b) |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
99 |
# handle the situation where administrators are using |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
100 |
# the command to make customizations. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
101 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
102 |
# In the off chance there is no coreadm.conf, apply the |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
103 |
# the SMF configuration. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
104 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
105 |
if [ -f /etc/coreadm.conf ]; then |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
106 |
read_conf |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
107 |
coreadm -u |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
108 |
else |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
109 |
apply_conf |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
110 |
fi |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
111 |
;; |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
112 |
"refresh") |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
113 |
# Refresh implies someone wants to apply the configuration |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
114 |
# stored in the service. Do so. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
115 |
# |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
116 |
# It is possible for someone to use coreadm directly and |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
117 |
# subsequently issue a refresh, resulting in the initial |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
118 |
# changes being lost. Given that a refresh will either be |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
119 |
# issued explicitly by the administrator or by a |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
120 |
# configuration activity that has made changes to the SMF |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
121 |
# configuration and expects those changes to be applied, |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
122 |
# this shouldn't be a big problem. |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
123 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
124 |
apply_conf |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
125 |
;; |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
126 |
esac |
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
127 |
|
98b9538bfe3f
1387 Create hooks for Visual Panels
David Powell <David.Powell@sun.com>
parents:
diff
changeset
|
128 |
exit $SMF_EXIT_OK |