manifest-import: do not use uname -i
[unleashed.git] / usr / src / cmd / svc / milestone / manifest-import
blob5dc5e6786c9ec7f42707c5e64417488bd2edca09
1 #!/bin/ksh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
22 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 # Copyright 2017 RackTop Systems.
26 # 0a Initialization.
28 [ -f /lib/svc/share/smf_include.sh ] || exit 1
30 . /lib/svc/share/smf_include.sh
32 activity=false
34 EMI_SERVICE="svc:/system/early-manifest-import:default"
35 PROFILE_DIR_SITE="/etc/svc/profile/site"
38 ALT_REPOSITORY=
39 ALT_MFST_DIR=
40 early=false
41 [ "$SMF_FMRI" == "$EMI_SERVICE" ] && early=true
43 usage()
45 echo "Usage: /lib/svc/method/manifest-import [-n]" \
46 "[-f repository-file -d manifest-directory]"
47 echo "\nOptions:"
48 echo "-n dryrun"
49 echo "-f and -d specify alternate repository and" \
50 "manifest directory for import\n"
51 exit 2
54 while getopts "nd:f:" opt; do
55 case $opt in
56 n) X=echo;;
57 d) ALT_MFST_DIR=$OPTARG;;
58 f) ALT_REPOSITORY=$OPTARG;;
59 ?) usage;;
60 esac
61 done
64 # Both -f and -d options must be specified together or not specified at all
66 [ -n "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ] && usage
67 [ -n "$ALT_MFST_DIR" -a -z "$ALT_REPOSITORY" ] && usage
69 function svccfg_apply {
70 $X /usr/sbin/svccfg apply $1
71 if [ $? -ne 0 ]; then
72 echo "WARNING: svccfg apply $1 failed" | tee /dev/msglog
77 # If the smf repository has file entries that are missing
78 # then there is work to be done by the cleanup process.
80 function cleanup_needwork {
81 smfmfiles=`svcprop -p manifestfiles '*' 2>/dev/null |
82 nawk -v early="$early" '$2 == "astring" &&
83 (early != "true" || $3 ~ "^/lib/") { print $3 }'`
85 nw=`/lib/svc/bin/mfstscan $smfmfiles 2>&1 1>/dev/null`
86 [ "$nw" ] && return 1
88 return 0
92 # Upon upgrading to early manifest import code, preserve hashes of system
93 # profiles which lived under /var/svc/profile so that svccfg apply would
94 # not re-apply the profiles and overwrite user customizations. Simply
95 # migrate manifestfile and hash values to new property groups named after
96 # profiles under /etc/svc/profile. If the profiles don't really exist,
97 # svccfg cleanup will remove the property groups in a later step.
99 # Existing generic.xml, inetd_services.xml, and name_service.xml symlinks
100 # need to be preserved.
102 # Don't process site.xml profile since it is still supported under
103 # /var/svc/profile directory.
105 function preserve_system_profiles {
108 # If /var is a separate fs, return and let Late Import
109 # preserves the hashes.
111 [ -d "/var/svc/profile" ] || return 1
114 # Preserve hashes for the following profiles: generic (two
115 # cases) and platform (uname -m output).
117 gn="var_svc_profile_generic_open_xml"
118 gh=`/usr/bin/svcprop -p ${gn}/md5sum smf/manifest 2>/dev/null`
119 [ $? = 0 ] || gh=""
120 gn="etc_svc_profile_generic_open_xml"
122 gln="var_svc_profile_generic_limited_net_xml"
123 glh=`/usr/bin/svcprop -p ${gln}/md5sum smf/manifest 2>/dev/null`
124 [ $? = 0 ] || glh=""
125 gln="etc_svc_profile_generic_limited_net_xml"
127 LC_ALL=C pl=`/usr/bin/uname -m | /usr/bin/tr , _`
128 pln="var_svc_profile_platform_${pl}_xml"
129 plh=`/usr/bin/svcprop -p ${pln}/md5sum smf/manifest 2>/dev/null`
130 [ $? = 0 ] || plh=""
131 pln="etc_svc_profile_platform_${pl}_xml"
133 [ -n "$gh" ] && {
134 echo "Preserving generic hash ($gh)."
135 /usr/sbin/svccfg -s smf/manifest addpg ${gn} framework
136 /usr/sbin/svccfg -s smf/manifest setprop ${gn}/md5sum = \
137 opaque: $gh
138 /usr/sbin/svccfg -s smf/manifest setprop ${gn}/manifestfile = \
139 astring: "/etc/svc/profile/generic.xml"
141 [ -n "$glh" ] && {
142 echo "Preserving generic_limited hash ($glh)."
143 /usr/sbin/svccfg -s smf/manifest addpg ${gln} framework
144 /usr/sbin/svccfg -s smf/manifest setprop ${gln}/md5sum = \
145 opaque: $glh
146 /usr/sbin/svccfg -s smf/manifest setprop ${gln}/manifestfile = \
147 astring: "/etc/svc/profile/generic.xml"
149 [ -n "$plh" ] && {
150 echo "Preserving platform hash ($plh)."
151 /usr/sbin/svccfg -s smf/manifest addpg $pln framework
152 /usr/sbin/svccfg -s smf/manifest setprop $pln/md5sum = \
153 opaque: $plh
154 /usr/sbin/svccfg -s smf/manifest setprop ${pln}/manifestfile = \
155 astring: "/etc/svc/profile/platform_${pl}_xml"
159 # Move symlinks from /var/svc/profile to /etc/svc/profile
161 generic_prof="/var/svc/profile/generic.xml"
162 ns_prof="/var/svc/profile/name_service.xml"
163 inetd_prof="/var/svc/profile/inetd_services.xml"
164 platform_prof="/var/svc/profile/platform.xml"
165 [ -L "$generic_prof" ] && mv $generic_prof /etc/svc/profile/
166 [ -L "$ns_prof" ] && mv $ns_prof /etc/svc/profile/
167 [ -L "$inetd_prof" ] && mv $inetd_prof /etc/svc/profile/
168 [ -L "$platform_prof" ] && mv $platform_prof /etc/svc/profile/
170 return 0
174 # 2. Manifest import. Application directories first, then
175 # site-specific manifests.
177 function import_manifests {
178 typeset basedir=$1
179 typeset console_print=$2
180 typeset logf="/etc/svc/volatile/manifest_import.$$"
182 rm -f $logf
184 nonsite_dirs=`/usr/bin/find $basedir/* -name site \
185 -prune -o -type d -print -prune`
187 if [ -n "$_MFST_DEBUG" ]; then
188 nonsite_manifests=`/lib/svc/bin/mfstscan $nonsite_dirs`
189 site_manifests=`/lib/svc/bin/mfstscan $basedir/site`
191 manifests="$nonsite_manifests $site_manifests"
193 echo "Changed manifests to import:"
194 for m in $manifests; do echo " $m"; done
198 # Upon boot, attempt to move the repository to tmpfs.
200 if [ -z "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ]; then
201 /usr/sbin/svcadm _smf_repository_switch fast
205 # Import the manifests while giving a running display of imports on
206 # console, and a final count in the logfile.
208 dirs="$nonsite_dirs"
209 [ -d "$basedir/site" ] && dirs="$dirs $basedir/site"
211 if [ "$console_print" = "true" ]; then
212 $X /usr/sbin/svccfg import -p /dev/msglog $dirs > $logf 2>&1
213 else
214 $X /usr/sbin/svccfg import $dirs > $logf 2>&1
217 grep "Loaded .*. smf(5) service descriptions" $logf > /dev/null 2>&1
218 if [ $? -eq 0 ]; then
219 activity=true
222 if [ -s $logf ]; then
223 grep "smf(5) service descriptions failed to load" $logf > /dev/null 2>&1
224 failures=$?
225 if [ $failures -eq 0 ]; then
226 echo "svccfg warnings:"
228 cat $logf
230 if [ $failures -eq 0 -a "$console_print" = "true" ]; then
231 msg="svccfg import warnings. See"
232 msg="$msg /var/svc/log/system-manifest-import:default.log ."
233 echo $msg > /dev/msglog
236 rm -f $logf
240 # 3. Profile application. We must create the platform profile upon
241 # first boot, as we may be a diskless client of a platform or
242 # architecture distinct from our NFS server.
244 # Generic and platform profiles are only supported in /etc.
246 function apply_profile {
248 # If smf/manifest doesn't have any profile under /etc/var/profile,
249 # this is very likely an import after upgrade so call
250 # preserve_system_profiles in that case.
252 LC_ALL=C pl=`/usr/bin/uname -m | /usr/bin/tr , _`
253 pln="etc_svc_profile_platform_${pl}_xml"
255 preserve_profiles=1
256 for prof in $pln etc_svc_profile_platform_none_xml \
257 etc_svc_profile_generic_limited_net_xml \
258 etc_svc_profile_generic_open_xml; do
259 if /usr/bin/svcprop -p $prof smf/manifest >/dev/null 2>&1
260 then
261 preserve_profiles=0
262 break
264 done
266 if [ $preserve_profiles -eq 1 ]; then
267 echo "/etc/svc system profiles not found: upgrade system profiles"
268 preserve_system_profiles || return
271 typeset prefix="/etc/svc/profile"
272 svccfg_apply $prefix/generic.xml
273 if [ ! -f $prefix/platform.xml ]; then
274 this_karch=`uname -m`
276 if [ -f $prefix/platform_$this_karch.xml ]; then
277 platform_profile=platform_$this_karch.xml
278 else
279 platform_profile=platform_none.xml
282 ln -s $platform_profile $prefix/platform.xml
285 svccfg_apply $prefix/platform.xml
289 # 4. Upgrade handling. The upgrade file generally consists of a series
290 # of svcadm(8) and svccfg(8) commands.
292 function handle_upgrade {
294 [ -f /var/svc/profile/upgrade ] && activity=true
297 unset SVCCFG_CHECKHASH
299 if [ -f /var/svc/profile/upgrade ]; then
300 . /var/svc/profile/upgrade
302 /usr/bin/mv /var/svc/profile/upgrade \
303 /var/svc/profile/upgrade.app.`date +\%Y\%m\%d\%H\%M\%S`
307 # Rename the datalink upgrade script file. This script is used in the
308 # network/physical service to upgrade datalink configuration, but
309 # the file cannot be renamed until now (when the file system becomes
310 # read-write).
312 datalink_script=/var/svc/profile/upgrade_datalink
313 if [ -f "${datalink_script}" ]; then
314 /usr/bin/mv "${datalink_script}" \
315 "${datalink_script}".app.`date +\%Y\%m\%d\%H\%M\%S`
321 # 5. Giving administrator the final say, apply site.xml profile and profiles
322 # under /etc/svc/profile/site directory.
324 function apply_site_profile {
325 typeset prefix="$1"
326 [ -f $prefix/site.xml ] && svccfg_apply $prefix/site.xml
328 if [ -d $PROFILE_DIR_SITE -a "$1" = "/etc/svc/profile" ]; then
329 svccfg_apply $PROFILE_DIR_SITE
334 # 0b Cleanup deathrow
336 if [ "$early" = "false" ];then
337 deathrow=/etc/svc/deathrow
338 if [ -s $deathrow ];then
340 # svc.startd has unconfigured the services found in deathrow,
341 # clean them now.
343 while read fmri mfst pkgname; do
344 # Delete services and instances from the deathrow file.
345 /usr/sbin/svccfg delete -f $fmri >/dev/null 2>&1
346 # Remove deathrow manifest hash.
347 /usr/sbin/svccfg delhash -d $mfst >/dev/null 2>&1
348 done < $deathrow
349 /usr/bin/mv $deathrow $deathrow.old
353 SVCCFG_CHECKHASH=1 export SVCCFG_CHECKHASH
356 # 0c Clean up repository
358 if [ "$early" = "false" ]; then
359 if [ -z "$X" ] && /usr/bin/svcprop smf/manifest 2>/dev/null |
360 /usr/bin/grep '^ar_svc_[^/]*/md5sum opaque ' >/dev/null
361 then
362 set -- `
363 /usr/bin/svcprop smf/manifest 2>/dev/null |
364 /usr/bin/grep '^ar_svc[^/]*/md5sum opaque ' |
365 /usr/bin/tr '/' ' ' |
366 while read pg prop type value; do
367 echo "$pg/$value"
368 done
370 backup=`echo "$#/$#" | sed 's/./\b/g'`
371 fwidth=`echo "$#\c" | wc -c`
373 echo "Converting obsolete repository entries: \c" > /dev/msglog
374 i=1; n=$#
375 while [ $# -gt 0 ]; do
376 printf "%${fwidth}s/%${fwidth}s" $i $n > /dev/msglog
377 echo $1 | sed 's:/: :' | (
378 read pg value
380 (echo "select /smf/manifest"; echo "delpg v$pg") |
381 /usr/sbin/svccfg 2>/dev/null >/dev/null
382 (echo "select /smf/manifest"; echo "delpg $pg") |
383 /usr/sbin/svccfg 2>/dev/null >/dev/null
384 (echo "select /smf/manifest";
385 echo "addpg v$pg framework") |
386 /usr/sbin/svccfg 2>/dev/null >/dev/null
387 (echo "select /smf/manifest";
388 echo "setprop v$pg/md5sum = opaque: $value") |
389 /usr/sbin/svccfg 2>/dev/null >/dev/null
391 i=`expr $i + 1`
392 shift
393 echo "$backup\c" > /dev/msglog
394 done
395 echo > /dev/msglog
396 echo "Converted $n obsolete repository entries"
397 activity=true
403 # If the alternate repository and directory are specified, simply set
404 # SVCCFG_REPOSITORY env, run svccfg import on the given directory, and
405 # exit.
407 if [ -n "$ALT_REPOSITORY" -a -n "$ALT_MFST_DIR" ]; then
408 SVCCFG_REPOSITORY=$ALT_REPOSITORY export SVCCFG_REPOSITORY
409 import_manifests "$ALT_MFST_DIR" false
410 unset SVCCFG_REPOSITORY
411 exit 0
415 # Call import and apply profiles here
417 if [ "$early" = "true" ]; then
418 import_manifests "/lib/svc/manifest" true
419 apply_profile
420 apply_site_profile "/etc/svc/profile"
421 else
423 # Process both /lib/svc/manifest and /var/svc/manifest
424 # during late manifest-import
426 # First import the manifests
428 import_manifests "/lib/svc/manifest" true
429 import_manifests "/var/svc/manifest" true
432 # Apply profiles
434 apply_profile
435 apply_site_profile "/etc/svc/profile"
438 # Run the upgrade script
440 handle_upgrade
441 apply_site_profile "/var/svc/profile"
446 # 6. Final actions.
449 if $activity; then
450 /usr/sbin/svcadm _smf_backup "manifest_import" || true
454 # If the filesystem is NOT read only then move the repo back to perm
455 # There is no care wether the switch was made or not, but just want
456 # to move it. If it is already perm this does not affect anything
457 # at least on the surface. REALLY want to improve on this...
459 touch /etc/svc/smf_rwtest.$$ > /dev/null 2>&1
460 if [ $? -eq 0 ]; then
461 rm -f /etc/svc/smf_rwtest.$$
462 /usr/sbin/svcadm _smf_repository_switch perm || { \
463 echo "Repository switch back operation failed, \c"
464 echo "please check the system log for the"
465 echo "possible fatal error messages."
466 exit $SMF_EXIT_ERR_FATAL
470 if $activity; then
471 /usr/sbin/svccfg cleanup | /usr/bin/tee /dev/msglog
472 else
473 cleanup_needwork
474 if [ $? -ne 0 ]; then
475 /usr/sbin/svccfg cleanup -a | /usr/bin/tee /dev/msglog
479 exit 0