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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
|
#!/usr/bin/ksh
# 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 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
typeset -r PROG=$(basename $0)
typeset -r CTAG_NULL="-"
#
# help message
#
help()
{
$xopt
cluster_configured
CLUSTER_CONFIGURED=$?
echo "\
usage:
$PROG
$PROG -i
$PROG -e [-r][-p]
$PROG -d [-r]" >&2
if [ $CLUSTER_CONFIGURED -eq 1 ]; then
echo "\
$PROG -s" >&2
fi
echo "\
-i : display information on the Availability Suite services
-e : enable Availability Suite services (all, by default)
-d : disable Availability Suite services (all, by default)
-r : enable/disable Remote Mirror
-p : enable Point in Time Copy" >&2
if [ $CLUSTER_CONFIGURED -eq 1 ]; then
echo "\
-s : set the location of the cluster configuration database" >&2
fi
echo "\
-x : turn on script debugging (may be used with any valid option)
When executed with no options or with nothing but -x, $PROG runs in
interactive fashion, allowing the user to initialize the local (and
if applicable, the cluster) configuration database, and to start the
Availability Suite services." >&2
exit 2
}
########################## SET GLOBAL VARIABLES ######################
# root directory
PKG_INSTALL_ROOT=""
export PKG_INSTALL_ROOT
# set lib path
LD_LIBRARY_PATH=/usr/lib:/usr/lib
export LD_LIBRARY_PATH
# set dscfg
DSCFG="/usr/sbin/dscfg"
export DSCFG
# set parser config location
PCONFIG="/etc/dscfg_format"
export PCONFIG
# set local dscfg location
export LOCAL_DSCFG="/etc/dscfg_local"
# set cluster dscfg reference file
export CLUSTER_REF="/etc/dscfg_cluster"
# a service that has a dependency on us
FS_LOCAL_SVC="svc:/system/filesystem/local"
NODELIST="/tmp/nodelist"
DSCFGLOCKDCF="/etc/dscfg_lockdb"
DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
# SMF defines
MANIFEST_PATH=/lib/svc/manifest/system
# SMF services (enable and disable)
SMF_ENABLE="nws_scm nws_sv nws_ii nws_rdc nws_rdcsyncd"
SMF_DISABLE="nws_rdcsyncd nws_rdc nws_ii nws_sv nws_scm"
# state of each service
nws_scm_enabled=0
nws_sv_enabled=0
nws_ii_enabled=0
nws_rdc_enabled=0
nws_rdcsyncd_enabled=0
# set path
PATH=/usr/bin:/usr/sbin:/sbin/sh
export PATH
# set architecture
ARCH=`uname -p`
export ARCH
OS_MINOR=`uname -r | cut -d '.' -f2`
# number of sectors required for database
# 1024*1024*5.5/512
REQUIRED=11264
# must set here, else seen as null in MAIN
VALID_DB_ENTERED=0
NO_ARGS=0
# for debugging
xopt=
# set lengthy message here
CLUST_LOC_MESS="The current location is invalid for a Sun StorageTek \
Data Services configuration database. Once a valid location is \
entered (raw slice on \"did\" device), you may upgrade the existing \
database to this new location - following the procedure outlined \
in the Installation and Configuration Guide."
########################## SET GLOBAL VARIABLES ######################
########################## ERROR ####################################
# called with optional error msg $1
# prints basic guidelines for configuration of the database location
error()
{
$xopt
echo >&2
echo "INSTALLATION ERROR" >&2
echo "Error: $1" >&2
echo >&2
in_cluster
if [ $? -eq 1 ]; then
echo "GENERAL INSTALLATION RULES:" >&2
echo "\tBecause you are installing on a cluster," >&2
echo "\tthe database must be located on a raw slice of a did device.">&2
echo "\t e.g. /dev/did/rdsk/d17s1" >&2
fi
# let?
MB=`expr $REQUIRED / 2 / 1024`
echo "\t$REQUIRED sectors ($MB MBs) are required for the database." >&2
}
########################## ERROR ####################################
########################## ALL LOCATION TESTS ########################
# sets numerous environment variables describing the state of the system
get_system_state()
{
$xopt
valid_local_dscfg_exists
VALID_LOCAL_DB=$?
OLD_VALID_LOCAL_DB=$VALID_LOCAL_DB
in_cluster
IN_CLUSTER=$?
cluster_configured
CLUSTER_CONFIGURED=$?
if [ $IN_CLUSTER = 1 ]; then
valid_cluster_dscfg_exists
VALID_CLUSTER_DB=$?
OLD_VALID_CLUSTER_DB=$VALID_CLUSTER_DB
else
VALID_CLUSTER_DB=0
fi
}
# Checks if in cluster
# returns 1 if in cluster, else 0
#
in_cluster()
{
$xopt
if [ -x /usr/sbin/clinfo ]; then
clinfo
if [ $? -eq 0 ]; then
return 1
else
return 0
fi
else
return 0
fi
}
# checks if a system is configured as a cluster
# returns 1 if configured as a cluster, 0 if not
#
cluster_configured()
{
$xopt
if [ -f /etc/cluster/nodeid ]; then
return 1
else
return 0
fi
}
# Check the list of Sun Cluster device groups known in the dscfg, determing
# if they are currently enabled on this Sun Cluster node. If so, fail allowing
# the system administator to scswitch them elsewhere.
#
check_device_groups()
{
$xopt
if [ $VALID_CLUSTER_DB == 1 ]; then
DEVICE_GROUPS=`$DSCFG -s $FILE_LOC -l 2>/dev/null | \
grep "^dsvol:" | cut -d' ' -f3 | sort | uniq | xargs`
for x in $DEVICE_GROUPS
do
$DSCFG -D $x 2>/dev/null
if [ $? -eq 1 ]
then
IN_USE="$IN_USE $x"
fi
done
if [ -n "$IN_USE" ]
then
print "The following Sun Cluster device groups are in use "
print "by Availability Suite on this node."
print ""
print "$IN_USE"
print ""
print "'scswitch' them to another Sun Cluster node before "
print "attempting to disable any data services."
return 1
else
return 0
fi
fi
return 0
}
# checks to see if this is a char device in the
# /dev/did/rdsk directory returns 1 if so.
#
is_did_device()
{
$xopt
DID=`echo $1 | awk -F/ '{print $3}'`
RDSK=`echo $1 | awk -F/ '{print $4}'`
if [ "did" = $DID -a "rdsk" = $RDSK -a -c $1 ]; then
return 1
else
return 0
fi
}
#
# checks size of area for db location
#
check_size()
{
$xopt
# if in cluster look for d*s*
SLICE=`echo $1 | sed -n 's/.*d.*s\(.*\)/\1/p'`
SECTORS=`prtvtoc $1 | tr -s ' '| grep "^ $SLICE " | awk '{print $5}'`
if [ -z "$SECTORS" ]; then
echo "SLICE at $1 not found on this device"
return 0
fi
# if required size is greater than space available, then fail
if [ $REQUIRED -gt $SECTORS ]; then
return 0
else
return 1
fi
}
# looks in dscfg_cluster reference file. if a location is configured,
# tests to see if it is a valid database. if so, returns 1
#
valid_cluster_dscfg_exists()
{
$xopt
if [ -s $CLUSTER_REF ]; then
FILE_LOC=`head -1 $CLUSTER_REF`
contains_data $FILE_LOC
return $?
else
return 0
fi
}
# checks for the existence of dscfg_local database, and if it exists,
# tests to see if it is a valid database. if so, returns 1
#
valid_local_dscfg_exists()
{
$xopt
if [ -s $LOCAL_DSCFG ]; then
contains_data $LOCAL_DSCFG
return $?
else
return 0
fi
}
# used to test if a valid DS config database exists on machine already
# MAGIC_STRING is the top line in the config used in v3.1 & v3.2
#
contains_data()
{
$xopt
# dscfg distinct strings, varies on the architecture
if [ $ARCH = "sparc" ]
then
MAGIC_STRING="MAGI"
elif [ $ARCH = "i386" ]
then
MAGIC_STRING="IGAM"
fi
# Create a PID unique temporary file
TMP_FILE=/tmp/$$
# Write the first or 16th block (skipping over VTOC) to
# the TMP_FILE, then scan for the presence of the "MAGI"
#
for offset in 0 16
do
if [ ! -z "$1" ]; then
dd if=$1 of=$TMP_FILE count=1 iseek=$offset 2>/dev/null
FILECONTENTS=`strings $TMP_FILE | head -1 2>/dev/null`
if [ `echo $FILECONTENTS | grep -c "$MAGIC_STRING"` -gt 0 ]; then
rm $TMP_FILE
return 1
fi
fi
done
rm $TMP_FILE
return 0
}
########################## ALL LOCATION TESTS ########################
########################## MAIN FUNCTIONS ############################
# since location already has been set, asks what to do now? keeping
# it still checks the size (since an upgrade from 3.0 may still be
# occuring) and also checks if was an old cluster config on disallowed
# /dev/did/dsk directory
#
# returns:
# 0 if cluster location is invalid or the user does not want to keep it
# 1 if the location is valid and the user wants to keep it.
#
keep_it()
{
$xopt
NOTE="\nThe Sun StorageTek Data Services database configuration"
NOTE="$NOTE location has already been set."
echo $NOTE
echo "\nCurrent location: $PKG_INSTALL_ROOT$FILE_LOC"
QUEST="Would you like to preserve the existing configuration"
QUEST="$QUEST information at its current location? "
ANS=`ckyorn -Qd n -p "$QUEST"`
case $ANS in
y|Y|yes|YES|Yes)
#Since the user has said "yes I want to keep this current one"
#it may actually be a 3.x database, which only required 4.5mb
#space, so now will check that there is room to grow another 1mb"
check_location $FILE_LOC
if [ $? = 0 ]; then
error "$CLUST_LOC_MESS"
return 0
else
OLD_FILE_LOC=$FILE_LOC
FILE_LOC=$NULL
return 1
fi
;;
*)
return 0
;;
esac
}
#
# asks if user wants to keep existing db information, overwrite with
# a new db, or view the contents, and be asked again...
# returns:
# 0 if old location is bad
# 1 if old location is good
#
preserve_overwrite_maybe()
{
$xopt
echo "\nIt appears a valid database configuration exists here already."
while true
do
SAFE_LOC=$FILE_LOC
echo "\nWould you like to preserve this information and continue?"
echo "\ty - preserve current configuration"
echo "\tn - overwrite with new configuration"
echo "\tmaybe - view contents of current configuration"
ANS=`ckkeywd -Q y n maybe`
case $ANS in
y)
check_location $FILE_LOC
if [ $? = 0 ]; then
error "$CLUST_LOC_MESS"
return 0
else
$DSCFG -s "$FILE_LOC" -C $CTAG_NULL >/dev/null 2>&1
OLD_FILE_LOC=$FILE_LOC
FILE_LOC=$NULL
return 1
fi
;;
n)
check_location $FILE_LOC
if [ $? = 0 ]; then
error "$CLUST_LOC_MESS"
return 0
else
return 1
fi
;;
maybe)
# print contents of this db config.
echo "\nContents of database configuration found at $SAFE_LOC are:"
$DSCFG -l -s "$FILE_LOC" | more
FILE_LOC=$SAFE_LOC
continue
;;
esac
done
}
# gets location from user
#
get_location()
{
$xopt
#Checks for absolute path name, and if file name and file doesn't
#exist, creates it.
echo "\n\n----------ENTER DATABASE CONFIGURATION LOCATION-----------------"
echo "Note: Please ensure this location meets all requirements specified"
echo "in the Availability Suite Installation Guide."
FILE_LOC=`ckpath -artwQ -p "Enter location:"`
if [ $? = 1 ]
then
exit 1
fi
# allow non-root user to access for least privileges
chmod 666 $FILE_LOC
}
#
# tests for proper config
#
# returns:
# 0 if bad location
# 1 if good location
#
check_location()
{
$xopt
# set to FILE_LOC
LOCATION=$1
did_clust_msg="You are in cluster and $LOCATION is not valid DID device"
# Set "actual file location" variable here to equal file location
# entered by user because getting here means contains_data was already
# successfully called before and now the two can equal each other for
# future testing.
SAFE_LOC=$FILE_LOC
if [ $IN_CLUSTER = 1 -o $CLUSTER_CONFIGURED = 1 ]; then
if [ -b "$LOCATION" ] || [ -c "$LOCATION" ]; then
is_did_device $LOCATION
if [ $? = 0 ]; then
error "$did_clust_msg"
return 0
fi
else
error "$did_clust_msg"
return 0
fi
else
echo "Location may not be changed in a non Sun Cluster OE." 2>&1
return 0
fi
check_size $LOCATION
if [ $? != 1 ]; then
error "$LOCATION does not meet minimum space requirement."
return 0
else
return 1
fi
}
#
# Notifies the user that the SMF services are online,
# and gives him the option to disable the services before proceeding. If
# the services are not disabled, the program cannot proceed with setting
# a new dscfg location.
#
ask_to_disable()
{
$xopt
echo "\
\nYour services must be disabled before a new configuration location is set.\n"
QUEST="Would you like to disable the services now and continue with the"
QUEST="$QUEST Availability Suite setup? "
ANS=`ckyorn -Qd n -p "$QUEST"`
case $ANS
in y|Y|yes|YES|Yes)
return 1
;;
*)
return 0
;;
esac
}
#
# Asks the user if he would like to enable the services now. If so,
# import them (if necessary) and enable them.
#
ask_to_enable()
{
$xopt
echo "\
\nIf you would like to start using the Availability Suite immediately, you may
start the SMF services now. You may also choose to start the services later
using the $PROG -e command."
QUEST="Would you like to start the services now? "
ANS=`ckyorn -Qd n -p "$QUEST"`
case $ANS
in y|Y|yes|YES|Yes)
return 1
;;
*)
return 0
;;
esac
}
#
# display information about the system
#
display_info()
{
$xopt
typeset grp_error_flg=0
typeset -L15 svc state en SVC="SERVICE" STATE="STATE" EN="ENABLED"
echo "$SVC\t$STATE\t$EN"
for i in $SMF_ENABLE
do
is_imported $i
if [ $? = 1 ]
then
state=`svcprop -c -p restarter/state \
svc:/system/${i}:default`
en=`svcprop -c -p general/enabled \
svc:/system/${i}:default`
check_fs_local_grouping $i
if [ $? -ne 0 ]
then
svc="${i}***"
grp_error_flg=$((grp_error_flg + 1))
else
svc=$i
fi
echo "$svc\t$state\t$en"
fi
done
print "\nAvailability Suite Configuration:"
printf "Local configuration database: "
if [ $VALID_LOCAL_DB = 1 ]
then
print "valid"
else
print "invalid"
fi
if [ $CLUSTER_CONFIGURED = 1 ]
then
printf "cluster configuration database: "
if [ $VALID_CLUSTER_DB = 1 ]
then
print "valid"
print "cluster configuration location: ${FILE_LOC}"
else
print "invalid"
fi
fi
if [ $grp_error_flg -gt 0 ]
then
typeset p
typeset p_has
if [ $grp_error_flg -gt 1 ]
then
p="s"
p_has="have"
else
p=""
p_has="has"
fi
printf "\n*** Warning: The service$p above $p_has an incorrect "
printf "dependency. To repair the\n"
printf "problem, run \"dscfgadm\".\n"
fi
}
#
# initialize the local configuration database (only called if none exists)
# returns 0 if successful, 1 if failed
#
initialize_local_db()
{
$xopt
echo "Could not find a valid local configuration database."
echo "Initializing local configuration database..."
echo y | ${DSCFG} -i > /dev/null 2>&1
${DSCFG} -i -p ${PCONFIG} > /dev/null 2>&1
# Make sure the new location is initialized properly
valid_local_dscfg_exists
VALID_LOCAL_DB=$?
if [ $VALID_LOCAL_DB != 1 ]
then
echo "Unable to initialize local configuration database" >&2
return 1
else
echo "Successfully initialized local configuration database"
fi
return 0
}
#
# initialize the cluster configuration database, if necessary
# returns 0 if successful, 1 if failed
#
initialize_cluster_db()
{
$xopt
if [ ! -n "$FILE_LOC" ]
then
return 0
fi
echo "Initializing cluster configuration database..."
${DSCFG} -s ${FILE_LOC} -C $CTAG_NULL > /dev/null 2>&1
echo y | ${DSCFG} -i -C $CTAG_NULL > /dev/null 2>&1
${DSCFG} -i -p ${PCONFIG} -C $CTAG_NULL > /dev/null 2>&1
# make sure the cluster db is valid now
valid_cluster_dscfg_exists
VALID_CLUSTER_DB=$?
if [ $VALID_CLUSTER_DB != 1 ]
then
echo "Unable to initialize cluster configuration database" >&2
return 1
else
echo "Successfully initialized cluster configuration database"
fi
return 0
}
#
# prompt the user for a config location and set AVS to use that location
#
set_cluster_config()
{
$xopt
REPEAT=0
while [ $REPEAT -eq 0 ]; do
# See if user has entered location already, and it was an existing
# db. Retruns FILE_LOC value
if [ $VALID_DB_ENTERED = 1 ]; then
# reset
VALID_DB_ENTERED=0
preserve_overwrite_maybe
# if 1, location passes, and FILE_LOC being passed to end, else
# set VALID_CLUSTER_DB to 0 since the "valid one" isn't valid anymore
# (bad size, etc) thereby when looping go straight to get_location
if [ $? = 1 ]; then
REPEAT=1
continue
else
VALID_CLUSTER_DB=0
continue
fi
fi
# if 1, then valid db exists, now see what user wants to do
if [ $VALID_CLUSTER_DB = 1 ]; then
SAFE_LOC=$FILE_LOC
keep_it
# if 0, then user can't or won't keep location. set PROMPT
# so we will get new location from user.
if [ $? = 0 ]; then
PROMPT=0
else
PROMPT=1
fi
fi
# if either are 0, then user wants or needs new db as outlined in
# earlier comments
if [ $VALID_CLUSTER_DB = 0 ] || [ $PROMPT = 0 ]; then
#
# We cannot proceed if the services are running. Give the user
# a chance to stop the services. If he chooses not to, bail.
#
check_enabled
if [ $? = 1 ]
then
show_enabled
ask_to_disable
if [ $? = 0 ]
then
echo "A new configuration location was not set."
exit 1
else
disable_services
if [ $? != 0 ]
then
exit 1
fi
fi
fi
get_location
contains_data $FILE_LOC
# if 1, then user entered an existsing db location, loop
# back to ask what to do with it
if [ $? = 1 ]; then
VALID_DB_ENTERED=1
continue
else
check_location $FILE_LOC
# if 0, that means location has failed, loop and
# get_location again
if [ $? = 0 ]; then
VALID_CLUSTER_DB=0
continue
fi
# entered location passes tests
REPEAT=1
continue
fi
else
# user wants to leave location where and how it is
# FILE_LOC being passed all the way to end
REPEAT=1
continue
fi
done
}
########################## MAIN FUNCTIONS ############################
######################## SMF HELPER FUNCTIONS ########################
#
# check if any SMF service is online (enabled)
#
check_enabled()
{
$xopt
typeset ret=0
typeset svc
for svc in $SMF_ENABLE
do
is_enabled $svc
eval ${svc}_enabled=$?
ret=$((ret | ${svc}_enabled))
done
return $ret
}
#
# Display which services are enabled. (Must be called after check_enabled)
#
show_enabled()
{
$xopt
typeset svc
echo "\nThe following Availability Suite services are enabled:"
for svc in $SMF_ENABLE
do
if (( ${svc}_enabled == 1 ))
then
printf "$svc "
fi
done
echo ""
}
#
# check if the given SMF service is online (enabled)
#
# $1: service name to check for
#
is_enabled()
{
$xopt
typeset en
is_imported $1
if [ $? = 1 ]
then
en=`svcprop -c -p general/enabled svc:/system/${1}:default`
if [ $en = "true" ]
then
return 1
fi
fi
return 0
}
#
# If necessary, flag no dependency check
#
no_depend_check()
{
$xopt
typeset pid
typeset msg=0
if [ $OS_MINOR -lt 11 ]
then
if [ -f $DSCFG_DEPEND_NOCHK ]
then
pid=`cat $DSCFG_DEPEND_NOCHK`
echo "Another dscfgadm disable is in progress."
echo "Waiting for pid: $pid to terminate..."
while [ -f $DSCFG_DEPEND_NOCHK ]
do
if (( msg && (msg % 6 == 0)))
then
printf "\nAnother dscfgadm disable "
printf "(pid: $pid) still appears to "
printf " be in progress.\n"
printf "If this is not the case, you "
printf "may remove "
printf "$DSCFG_DEPEND_NOCHK.\n"
fi
sleep 5
msg=$((msg + 1))
done
fi
touch $DSCFG_DEPEND_NOCHK
echo $$ >> $DSCFG_DEPEND_NOCHK
fi
}
#
# If necessary, remove the no dependency check flag
#
rm_no_depend_check()
{
$xopt
if [ $OS_MINOR -lt 11 ]
then
rm -f $DSCFG_DEPEND_NOCHK
fi
}
#
# set the filesystem/local dependency type and refresh
#
# $1: service name
# $2: either "require_all" or "optional_all"
#
set_fs_local_grouping()
{
$xopt
typeset svc=$1
typeset dep_group=$2
# set proper dependency type for fs-local
if [ $svc != nws_rdcsyncd ]; then
svccfg -s $FS_LOCAL_SVC setprop \
${svc}-local-fs/grouping=$dep_group
if [ $? -ne 0 ]
then
printf "command failed: svccfg -s $FS_LOCAL_SVC "
printf "setprop ${svc}-local-fs/grouping=$dep_group "
printf ">&2\n"
return 1
fi
# we need local-fs to know about the new grouping attributes
svcadm refresh ${FS_LOCAL_SVC}:default
if [ $? -ne 0 ]
then
print "Failed to refresh ${FS_LOCAL_SVC} >&2"
return 1
fi
fi
return 0
}
#
# check if the grouping dependency type for filesystem/local is correct
#
# input:
# $1: service name
#
# returns:
# 0 if the setting is correct
# 1 if the setting is incorrect
# outputs: sets CORRECT_GROUPING with the value of what the grouping should be.
#
check_fs_local_grouping()
{
$xopt
typeset svc=$1
typeset cur_grouping
if [ $svc = nws_rdcsyncd ]
then
return 0
fi
# If it's not imported, we just return success, since we don't want
# further processing
is_imported $svc
if [ $? = 0 ]
then
return 0
fi
# get the current grouping value from the repository
cur_grouping=`svcprop -c -p ${svc}-local-fs/grouping $FS_LOCAL_SVC`
# Figure out what the grouping should be (based on enabled status)
is_enabled $svc
if [ $? = 1 ]
then
CORRECT_GROUPING="require_all"
else
CORRECT_GROUPING="optional_all"
fi
if [ "$cur_grouping" != "$CORRECT_GROUPING" ]
then
# grouping is incorrect
return 1
else
# grouping is just fine
return 0
fi
}
#
# enable/disable the given SMF service. Also, update the filesystem-local
# dependency, if appropriate.
#
# $1: service name to check for
# $2: "enable" or "disable"
#
svc_operation()
{
$xopt
typeset svc=$1
typeset command=$2
typeset enable_state
typeset dep_group
# If disabling, then enable_state better be true, and we are
# transitioning to "option_all" grouping
if [ $command = "disable" ]
then
enable_state=1
dep_group="optional_all"
# If enabling, then enable_state better be false, and we are
# transitioning to "require_all" grouping
elif [ $command = "enable" ]
then
enable_state=0
dep_group="require_all"
else
echo "invalid command: $command" >&2
fi
is_imported $svc
if [ $? = 1 ]
then
is_enabled $svc
if [ $? = $enable_state ]
then
if [ $enable_state -eq 1 ]
then
# we're doing a disable--remove hard dependency
set_fs_local_grouping $svc $dep_group
if [ $? -ne 0 ]
then
return 1
fi
fi
svcadm $command -s svc:/system/$svc
if [ $? != 0 ]
then
echo "$svc failed to $command" >&2
return 1
fi
if [ $enable_state -eq 0 ]
then
# we just did an enable--create hard dependency
set_fs_local_grouping $svc $dep_group
if [ $? -ne 0 ]
then
return 1
fi
fi
else
echo "$svc service already ${command}d... skipping"
fi
fi
return 0
}
#
# This chart summarizes the behavior of the -r and -p sub-options for the
# -e and -d options.
# There are 5 possible states, and 5 transitions out of each state.
#
# states: (vertical axis)
# -------
# 0: no services enabled
# C: one or both core services enabled (illegal state)
# R: both core services and RM services enabled
# P: both core services and PITC service enabled
# A: all services enabled
#
# transitions: (horizontal axis)
# ------------
# +/-a: enable/disable, respectively, with neither -r nor -p
# +/-r: enable/disable, respectively, with -r flag
# +p: enable with -p flag
#
# The result of the function is the next state after the action has been
# successfully performed.
#
# +a | -a | +r | -r | +p |
# ++----+----+----+----+----+
# ++----+----+----+----+----+
# 0 || A | 0* | R | 0* | P |
# --++----+----+----+----+----+
# C || A* | 0* | R | 0 | P |
# --++----+----+----+----+----+
# R || A* | 0* | R* | 0 | A |
# --++----+----+----+----+----+
# P || A* | 0* | A* | P* | P* |
# --++----+----+----+----+----+
# A || A* | 0 | A* | P | A* |
# --++----+----+----+----+----+
#
# *: warning message is displayed, stating that a service is already
# enabled/disabled.
#
# enable the SMF services needed for the Availability Suite
#
enable_services()
{
$xopt
typeset svc
# first, import them if they have not yet been imported
import_services
# if neither r_flag nor p_flag is set, enable all services
if (( (r_flag | p_flag) == 0 ))
then
for svc in $SMF_ENABLE
do
if ! svc_operation $svc enable
then
return 1
fi
done
else
# figure out which services are enabled
check_enabled
# First, make sure both core services are enabled
for svc in nws_scm nws_sv
do
if (( ${svc}_enabled == 0 )) && \
! svc_operation $svc enable
then
return 1
fi
done
if ((p_flag))
then
if ! svc_operation nws_ii enable
then
return 1
fi
fi
if ((r_flag))
then
for svc in nws_rdc nws_rdcsyncd
do
if ! svc_operation $svc enable
then
return 1
fi
done
fi
fi
return 0
}
#
# disable the SMF services needed for the Availability Suite
#
disable_services()
{
$xopt
typeset svc
check_device_groups
if [ $? == 1 ]
then
return 1
fi
# This flags the shutdown scripts to not check to make sure the
# services' dependents have been disabled. The flag must be removed
# before returning from this function.
no_depend_check
# NB: p_flag is not allowed for disables. II should not be
# disabled if sndr is enabled. If rdc is not enabled, disabling just
# II is equivalent to disabling all the remaining services.
# If no flags passed in, just disable everything
if (( r_flag == 0 ))
then
for svc in $SMF_DISABLE
do
if ! svc_operation $svc disable
then
rm_no_depend_check
return 1
fi
done
# Now that we've disable the services, lets unload them
# from the Solaris kernel
#
modinfo | grep '(nws:' | grep -v "kRPC Stub" | sort -r | cut -d' ' -f1 | xargs -l modunload -i 2>/dev/null
modinfo | grep '(nws:' | grep -v "kRPC Stub" | sort -r | cut -d' ' -f1 | xargs -l modunload -i 2>/dev/null
else
# we're disabling just rdc. If II is not already enabled,
# we disable core services, as well.
# figure out which services are enabled
check_enabled
for svc in nws_rdcsyncd nws_rdc
do
if ! svc_operation $svc disable
then
rm_no_depend_check
return 1
fi
done
if (( nws_ii_enabled == 0 ))
then
for svc in nws_sv nws_scm
do
if ((${svc}_enabled)) && \
! svc_operation $svc disable
then
rm_no_depend_check
return 1
fi
done
fi
fi
rm_no_depend_check
return 0
}
#
# check if a service has been imported into the repository
# $1: service to check
# returns 1 if it is imported, 0 if it is not
#
is_imported()
{
$xopt
typeset svc=$1
svcprop -q -p general/entity_stability svc:/system/${svc}
if [ $? = 1 ]
then
return 0
else
return 1
fi
}
#
# import the SMF services into the repository, if necessary
#
import_services()
{
$xopt
typeset svc
for svc in $SMF_ENABLE
do
import_service $svc
done
}
#
# check to see if an SMF service is in the repository. If it is not,
# import it in.
# $1: name of service to import
#
import_service()
{
$xopt
typeset svc=$1
is_imported $svc
if [ $? = 0 ]
then
if [ -f $PKG_INSTALL_ROOT/$MANIFEST_PATH/$svc.xml ]
then
svccfg import $PKG_INSTALL_ROOT/$MANIFEST_PATH/$svc.xml
if [ $OS_MINOR -lt 11 ]
then
# workaround for 6221374--let local-fs know
# that it depends on us.
svcadm refresh ${FS_LOCAL_SVC}:default
fi
fi
fi
}
########################## MAIN ######################################
# getopt processing
enable=0
disable=0
set_location=0
get_info=0
r_flag=0
p_flag=0
while getopts "xedsirp" opt 2>/dev/null
do
case $opt in
\?)
help
;;
e)
enable=1
;;
d)
disable=1
;;
x)
xopt="set -x"
set -x
;;
s)
set_location=1
;;
i)
get_info=1
;;
r)
r_flag=1
;;
p)
p_flag=1
;;
esac
done
# at most one option (besides -x) may be specified at a time
options_count=$((enable + disable + set_location + get_info))
if [ $options_count -gt 1 ]
then
help
elif [ $options_count = 0 ]
then
NO_ARGS=1
fi
if (( ((r_flag + p_flag) > 0) && ((enable | disable) == 0) ))
then
echo "-r and -p options may only be used with -d or -e options" >&2
return 1
elif (( p_flag && disable ))
then
echo "The -p option may not be used with the -d option" >&2
return 1
fi
# set all the system information variables
get_system_state
# if we're enabling, we need to make sure we have a valid dscfg out there.
if [ $enable = 1 -a $VALID_LOCAL_DB != 1 ]
then
echo "Cannot find a valid configuration database" >&2
return 1
fi
if [ $NO_ARGS = 1 ]
then
# only initialize the database if necessary
if [ $VALID_LOCAL_DB = 1 ]; then
echo "Local configuration database is already initialized."
else
initialize_local_db
if [ $? != 0 ]; then
return 1
fi
fi
if [ $CLUSTER_CONFIGURED = 1 ]
then
if [ $VALID_CLUSTER_DB = 1 ]; then
printf "Cluster configuration database is already "
printf "initialized.\n"
else
# ask the user for a cluster database location
set_cluster_config
# initialize the new db
initialize_cluster_db
if [ $? != 0 ]; then
return 1
fi
fi
fi
# make sure that the local filesystem dependency type is correct
for svc in $SMF_ENABLE
do
check_fs_local_grouping $svc
if [ $? -ne 0 ]
then
# NOTE: check_fs_local_grouping sets CORRECT_GROUPING
# To avoid this issue in the future, always administer
# the services using dscfgadm.
printf "Warning: Fixing dependency for $svc.\n"
set_fs_local_grouping $svc $CORRECT_GROUPING
if [ $? -ne 0 ]
then
return 1
fi
fi
done
# give the user the chance to startup AVS services, if not started
check_enabled
if [ $? = 1 ]; then
if [ $OLD_VALID_LOCAL_DB = 0 ]; then
printf "WARNING: AVS services are running on a system "
printf "which had no valid configuration\ndatabase\n"
fi
show_enabled
else
ask_to_enable
if [ $? = 1 ]; then
enable_services
if [ $? != 0 ]
then
return 1
fi
fi
fi
elif [ $enable = 1 ]
then
enable_services
if [ $? != 0 ]
then
return 1
fi
elif [ $disable = 1 ]
then
disable_services
if [ $? != 0 ]
then
return 1
fi
elif [ $get_info = 1 ]
then
display_info
elif [ $set_location = 1 ]
then
if [ $CLUSTER_CONFIGURED = 1 ]
then
# ask the user for a cluster database location
set_cluster_config
# initialize the new db
initialize_cluster_db
if [ $? != 0 ]; then
return 1
fi
else
echo "$PROG -s is only available on Sun Cluster OE systems" >&2
return 1
fi
fi
return 0
########################## MAIN ######################################
|