Cross Reference: /illumos-gate/usr/src/cmd/svc/milestone/manifest-import
manifest-import revision 7c478bd95313f5f23a4c958a745db2134aa03244
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (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 2005 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "%Z%%M% %I% %E% SMI"
# 0. Initialization.
[ -f /lib/svc/share/smf_include.sh ] || exit 1
activity=false
X=
while getopts n opt; do
case $opt in
n) X=echo;;
?) echo "Usage: /lib/svc/method/manifest-import [-n]\n"
exit 2;;
esac
done
svccfg_apply () {
$X /usr/sbin/svccfg apply $1
if [ $? -ne 0 ]; then
echo "WARNING: svccfg apply $1 failed" | tee /dev/msglog
fi
}
svccfg_import () {
$X /usr/sbin/svccfg import $1 2>>/tmp/manifest_import.$$
if [ $? -ne 0 ]; then
echo > /dev/msglog
echo "WARNING: svccfg import $1 failed" | tee /dev/msglog
fi
}
prophist_upgrade () {
#
# A property has changed in the manifest that we wish to propagate into
# the repository during manifest import. We don't want to pollute
# manifests with overrides, so handle explicitly here.
#
fmri=$1
pgrp=$2
prop=$3
nval=$4
shift 4
/lib/svc/bin/prophist upgrade -e $fmri -g $pgrp -p $prop -n "$nval" \
"$@"
[ $? = 0 ] && instance_refresh $fmri
}
prophist_override () {
#
# A property has changed in the manifest that we wish to propagate
# into the repository during manifest import.
#
fmri=$1
pgrp=$2
prop=$3
nval=$4
/lib/svc/bin/prophist overwrite -e $fmri -g $pgrp -p $prop -n "$nval"
[ $? = 0 ] && instance_refresh $fmri
}
prophist_delete_svc_pg () {
#
# Certain property groups have migrated from the service level to the
# instance level. We don't care if they are at both, as the instance
# level will trump. But having neither could be bad. So check and if
# the given pg exists at both levels, delete the service-level one only.
#
service=$1
instance=$2
property_group=$3
/usr/bin/svcprop -q -p $property_group $service
res1=$?
/usr/bin/svcprop -q -c -p $property_group $service:$instance
res2=$?
if [ $res1 -eq 0 -a $res2 -eq 0 ]; then
/lib/svc/bin/prophist delete -e $service -g $property_group
instance_refresh $service:$instance
fi
}
prophist_delete_dependency () {
#
# Some services have stale dependencies that need to be removed.
# This is done by removing the dependency property group.
#
fmri=$1
property_group=$2
/usr/bin/svcprop -q -c -p $property_group $fmri
if [ $? -eq 0 ]; then
/lib/svc/bin/prophist delete -e $fmri -g $property_group
else
[ -n "$_MFST_DEBUG" ] && \
echo "Dependency $property_group not defined on $fmri"
fi
}
prophist_delete_pg () {
# Delete obsolete property groups from old manifests. Instances
# should be refreshed for changes to take effect.
fmri=$1
pg=$2
/usr/bin/svcprop -Cqp $pg $fmri &&
/lib/svc/bin/prophist delete -e $fmri -g $pg
}
prophist_addprop () {
#
# If a property doesn't exist, create it. Instances should be
# refreshed for changes to take effect.
#
if [ $# -lt 6 ]; then
echo "prophist_addprop(): Insufficient arguments ($*)."
exit 1
fi
fmri=$1
/usr/bin/svcprop -q $fmri || return
pg=$2
pgtype=$3
prop=$4
/usr/bin/svcprop -Cqp $pg/$prop $fmri && return
shift 4
/usr/bin/svcprop -Cqp $pg $fmri || \
/usr/sbin/svccfg -s $fmri addpg $pg $pgtype
/usr/sbin/svccfg -s $fmri setprop $pg/$prop = $*
}
prophist_addmeth () {
#
# If a method doesn't exist, create it. Instances should be refreshed
# for changes to take effect.
#
if [ $# -ne 4 ]; then
echo "prophist_addmeth(): Insufficient arguments ($*)"
exit 1
fi
fmri=$1
/usr/bin/svcprop -q $fmri || return
name=$2
/usr/bin/svcprop -Cqp $name $fmri && return
exec=$3
to=$4
/usr/sbin/svccfg -s $fmri <<END
addpg $name method
setprop $name/type = astring: method
setprop $name/exec = astring: "$exec"
setprop $name/timeout_seconds = count: $to
END
}
prophist_adddep () {
#
# If a dependency doesn't exist, create it. Instances should be
# refreshed for changes to take effect.
#
if [ $# -lt 6 ]; then
echo "prophist_adddep(): Insufficient arguments ($*)"
exit 1
fi
fmri=$1
/usr/bin/svcprop -q $fmri || return
name=$2
/usr/bin/svcprop -Cqp $name $fmri && return
type=$3
group=$4
ro=$5
shift 5
/usr/sbin/svccfg -s $fmri <<END
addpg $name dependency
setprop $name/type = astring: $type
setprop $name/grouping = astring: $group
setprop $name/restart_on = astring: $ro
setprop $name/entities = fmri: $*
END
}
prophist_adddpt () {
#
# If a dependent doesn't exist, create it. Instances should be
# refresh for changes to take effect.
#
if [ $# -ne 5 ]; then
echo "prophist_adddpt(): Incorrect arguments ($*).\n"
exit 1
fi
fmri=$1
/usr/bin/svcprop -q $fmri || return
name=$2
/usr/bin/svcprop -Cqp dependents/$name $fmri && return
group=$3
ro=$4
target=$5
prophist_addprop $fmri dependents framework $name fmri: $target
prophist_adddep $target $name service $group $ro $fmri
}
instance_refresh () {
echo $1 >> /etc/svc/volatile/refreshes
}
refresh_instances () {
[ -r /etc/svc/volatile/refreshes ] && {
sort -u /etc/svc/volatile/refreshes | xargs -l svcadm refresh
}
}
instance_clear () {
echo $1 >> /etc/svc/volatile/clears
}
clear_conditionally () {
[ "`/usr/bin/svcprop -p restarter/state $1`" = "maintenance" ] && \
/usr/sbin/svcadm clear $1
}
clear_instances () {
[ -r /etc/svc/volatile/clears ] && {
for inst in `/usr/bin/sort -u /etc/svc/volatile/clears`; do
clear_conditionally $inst
done
}
}
prepare_last_import () {
# Preserve the five hashes for the profiles: generic (two
# cases), platform (uname -i, uname -m outputs), and site.
gn="var_svc_profile_generic_open_xml"
gh=`/usr/bin/svcprop -p ${gn}/md5sum smf/manifest 2>/dev/null`
[ $? = 0 ] || gh=""
gln="var_svc_profile_generic_limited_net_xml"
glh=`/usr/bin/svcprop -p ${gln}/md5sum smf/manifest 2>/dev/null`
[ $? = 0 ] || glh=""
LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _`
pln="var_svc_profile_platform_${pl}_xml"
plh=`/usr/bin/svcprop -p ${pln}/md5sum smf/manifest 2>/dev/null`
[ $? = 0 ] || plh=""
LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _`
if [ $plm != $pl ]; then
plmn="var_svc_profile_platform_${plm}_xml"
plmh=`/usr/bin/svcprop -p ${plmn}/md5sum smf/manifest \
2>/dev/null`
[ $? = 0 ] || plmh=""
else
plmh=""
fi
sn="var_svc_profile_site_xml"
sh=`/usr/bin/svcprop -p $sn/md5sum smf/manifest 2>/dev/null`
[ $? = 0 ] || sh=""
# Remove all manifest hashes.
/usr/sbin/svccfg delete smf/manifest
# Restore smf/manifest and hash values.
/usr/sbin/svccfg add smf/manifest
[ -n "$gh" ] && {
echo "Preserving generic hash ($gh)."
/usr/sbin/svccfg -s smf/manifest addpg ${gn} framework
/usr/sbin/svccfg -s smf/manifest setprop ${gn}/md5sum = \
opaque: $gh
}
[ -n "$glh" ] && {
echo "Preserving generic_limited hash ($glh)."
/usr/sbin/svccfg -s smf/manifest addpg ${gln} framework
/usr/sbin/svccfg -s smf/manifest setprop ${gln}/md5sum = \
opaque: $glh
}
[ -n "$plh" ] && {
echo "Preserving platform hash ($plh)."
/usr/sbin/svccfg -s smf/manifest addpg $pln framework
/usr/sbin/svccfg -s smf/manifest setprop $pln/md5sum = \
opaque: $plh
}
[ -n "$plmh" ] && {
echo "Preserving platform hash ($plmh)."
/usr/sbin/svccfg -s smf/manifest addpg $plmn framework
/usr/sbin/svccfg -s smf/manifest setprop $plmn/md5sum = \
opaque: $plmh
}
[ -n "$sh" ] && {
echo "Preserving site hash ($sh)."
/usr/sbin/svccfg -s smf/manifest addpg $sn framework
/usr/sbin/svccfg -s smf/manifest setprop $sn/md5sum = \
opaque: $sh
}
}
SVCCFG_CHECKHASH=1 export SVCCFG_CHECKHASH
#
# 0. Clean up repository
#
if [ -z "$X" ] && /usr/bin/svcprop smf/manifest 2>/dev/null |
/usr/bin/grep '^ar_svc_[^/]*/md5sum opaque ' >/dev/null
then
set -- `
/usr/bin/svcprop smf/manifest 2>/dev/null |
/usr/bin/grep '^ar_svc[^/]*/md5sum opaque ' |
/usr/bin/tr '/' ' ' |
while read pg prop type value; do
echo "$pg/$value"
done
`
backup=`echo "$#/$#" | sed 's/.//g'`
fwidth=`echo "$#\c" | wc -c`
echo "Converting obsolete repository entries: \c" > /dev/msglog
i=1; n=$#
while [ $# -gt 0 ]; do
printf "%${fwidth}s/%${fwidth}s" $i $n > /dev/msglog
echo $1 | sed 's:/: :' | (
read pg value
(echo "select /smf/manifest"; echo "delpg v$pg") |
/usr/sbin/svccfg 2>/dev/null >/dev/null
(echo "select /smf/manifest"; echo "delpg $pg") |
/usr/sbin/svccfg 2>/dev/null >/dev/null
(echo "select /smf/manifest";
echo "addpg v$pg framework") |
/usr/sbin/svccfg 2>/dev/null >/dev/null
(echo "select /smf/manifest";
echo "setprop v$pg/md5sum = opaque: $value") |
/usr/sbin/svccfg 2>/dev/null >/dev/null
)
i=`expr $i + 1`
shift
echo "$backup\c" > /dev/msglog
done
echo > /dev/msglog
echo "Converted $n obsolete repository entries"
activity=true
fi
#
# If no last-import snapshots are present on critical services, then we are
# creating the last-import snapshots for the first time post upgrade.
#
create_last_import=1
for svc in single-user multi-user multi-user-server; do
if /usr/bin/svcprop -s last-import svc:/milestone/$svc:default \
>/dev/null 2>&1
then
create_last_import=
break
fi
done
if [ $create_last_import ]; then
echo "Last import snapshots absent; preparing for re-import"
prepare_last_import
#
# Apply property history files.
#
echo "Upgrade detected; applying property history"
for phist in /var/svc/profile/prophist.*; do
/lib/svc/bin/prophist hash $phist
if [ $? = 3 ]; then
echo "Sourcing $phist"
. $phist
fi
done
/usr/bin/rm -f /var/svc/profile/.upgrade_prophist
fi
#
# 2. Manifest import. Application directories first, then
# site-specific manifests.
#
nonsite_dirs=`/usr/bin/find /var/svc/manifest/* -name site -prune -o -type d \
-print -prune`
nonsite_manifests=`/lib/svc/bin/mfstscan $nonsite_dirs`
site_manifests=`/lib/svc/bin/mfstscan /var/svc/manifest/site`
manifests="$nonsite_manifests $site_manifests"
[ -n "$_MFST_DEBUG" ] && {
echo "Changed manifests to import:"
for m in $manifests; do echo " $m"; done
}
#
# 2b. Import the manifests while giving a running display of imports on
# console, and a final count in the logfile.
#
if [ -n "$nonsite_manifests" -o -n "$site_manifests" ]; then
rm -f /tmp/manifest_import.$$
set -- $manifests
backup=`echo "$#/$#" | sed 's/.//g'`
fwidth=`echo "$#\c" | wc -c`
echo "Loading smf(5) service descriptions: \c" > /dev/msglog
i=1; n=$#
while [ $# -gt 0 ]; do
printf "%${fwidth}s/%${fwidth}s" $i $n > /dev/msglog
svccfg_import $1
i=`expr $i + 1`
shift
echo "$backup\c" > /dev/msglog
done
echo > /dev/msglog
echo "Loaded $n smf(5) service descriptions"
activity=true
if [ -s /tmp/manifest_import.$$ ]; then
echo "svccfg warnings:"
cat /tmp/manifest_import.$$
msg="svccfg import warnings. See"
msg="$msg /var/svc/log/system-manifest-import:default.log ."
echo $msg > /dev/msglog
fi
rm -f /tmp/manifest_import.$$
fi
#
# 3. Profile application. We must create the platform profile upon
# first boot, as we may be a diskless client of a platform or
# architecture distinct from our NFS server.
#
svccfg_apply /var/svc/profile/generic.xml
if [ ! -f /var/svc/profile/platform.xml ]; then
this_karch=`uname -m`
this_plat=`uname -i`
if [ -f /var/svc/profile/platform_$this_plat.xml ]; then
platform_profile=platform_$this_plat.xml
elif [ -f /var/svc/profile/platform_$this_karch.xml ]; then
platform_profile=platform_$this_karch.xml
else
platform_profile=platform_none.xml
fi
ln -s $platform_profile /var/svc/profile/platform.xml
fi
svccfg_apply /var/svc/profile/platform.xml
#
# 4. Upgrade handling. The upgrade file generally consists of a series
# of svcadm(1M) and svccfg(1M) commands.
#
(
unset SVCCFG_CHECKHASH
if [ -f /var/svc/profile/upgrade ]; then
. /var/svc/profile/upgrade
/usr/bin/mv /var/svc/profile/upgrade \
/var/svc/profile/upgrade.app.`date +\%Y\%m\%d\%H\%M\%S`
activity=true
fi
)
#
# 5. Site profile is applied last to give administrator the final say.
#
if [ -f /var/svc/profile/site.xml ]; then
svccfg_apply /var/svc/profile/site.xml
fi
#
# 6. Final actions.
#
refresh_instances
clear_instances
if $activity; then
svcadm _smf_backup "manifest_import" || true
fi
exit 0