Contents
Ops Center scripts
Script to keep ZFS datatset while zone failover
The below steps will keep a zone ZFS dataset by a zone – server-pool fialover.
Create the directory
/var/opt/sun/oc/public
1 |
mkdir -p /var/opt/sun/oc/public |
Add the below script
Copy the below shell script as this file /var/opt/sun/oc/public/guest-operations.
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 |
#!/bin/bash # # /var/opt/sun/oc/public/guest-operations # # This script must be placed on all Global Zones and can be used for customizing zone migrations # ZONEADM=/usr/sbin/zoneadm ZONECFG=/usr/sbin/zonecfg ZPOOL=/sbin/zpool AWK=/usr/bin/nawk PREFIX=/var/mnt/virtlibs SHARED_DIR=$(dirname $(grep -l "<guestName>${OEMOC_ZONENAME}</guestName>" ${PREFIX}/*/*/servercfg.xml 2>/dev/null | head -1) ) SHARED_FILE=${SHARED_DIR}/guest-operations_shared_data LOGFILE=${SHARED_DIR}/guest-operations.log log(){ echo "OK: $1" | tee -a $LOGFILE } errorlog(){ echo "ERROR: $1" | tee -a $LOGFILE >&2 exit 1 } if $ZONECFG -z ${OEMOC_ZONENAME} info >/dev/null 2>&1 then ZONE_EXISTS=true else ZONE_EXISTS=false fi ################################################################################## phase_verify() { if $ZONE_EXISTS then # test if the source GZ can use the zone VSI directory for exchanging data if touch $SHARED_FILE 2>/dev/null then log "Successfully created testfile $SHARED_FILE from source GZ" else errorlog "Unable to create testfile $SHARED_FILE" fi else # test if we can see and delete the shared file from the target GZ if [ -f $SHARED_FILE ] then if rm $SHARED_FILE 2>/dev/null then log "Successfully deleted the testfile $SHARED_FILE" else errorlog "Unable to delete the testfile $SHARED_FILE" fi else errorlog "Testfile $SHARED_FILE is not visible from target GZ" fi fi } phase_preoperation_running() { # collect all info about used datasets $ZONECFG -z "$OEMOC_ZONENAME" info dataset 2>/dev/null | $AWK '$1 == "name:" {print $2}' > $SHARED_FILE while read DATASET do log "Found dataset: $DATASET" done < $SHARED_FILE } phase_preoperation_notrunning() { # we have to remove the datasets and export the zpools while read DATASET do log "Running command: $ZONECFG -z $OEMOC_ZONENAME remove dataset name=$DATASET" $ZONECFG -z $OEMOC_ZONENAME remove dataset name=$DATASET done < $SHARED_FILE for zpoolname in $(cut -d/ -f1 $SHARED_FILE |sort -u) do log "Running command: $ZPOOL export $zpoolname" $ZPOOL export $zpoolname done } phase_postoperation_notrunning() { # import zpools but zone does not yet exists for zpoolname in $(cut -d/ -f1 $SHARED_FILE |sort -u) do log "Running command: $ZPOOL import $zpoolname" $ZPOOL import $zpoolname done } phase_postoperation_running() { # # this should no longer be required, with 12c Update2, we are calling the script # when the zone has been created but has not been bootet. There should be no longer # the need to halt the zone first to add the dataset # # halt zone $ZONEADM -z $OEMOC_ZONENAME halt # add datasets to zone config while read DATASET do log "adding dataset $DATASET" echo "add dataset; set name=$DATASET; end" | $ZONECFG -z $OEMOC_ZONENAME done < $SHARED_FILE # boot zone $ZONEADM -z $OEMOC_ZONENAME boot # cleanup rm $SHARED_FILE } phase_prerollback_running() { log "nothing to do" } phase_prerollback_notrunning() { log "nothing to do" } phase_postrollback_notrunning() { log "nothing to do" } phase_postrollback_running() { log "nothing to do" } ################################################################################## case "$OEMOC_PHASE" in 'VERIFY') phase_verify ;; 'PREOPERATION_RUNNING') phase_preoperation_running ;; 'PREOPERATION_NOTRUNNING') phase_preoperation_notrunning ;; 'POSTOPERATION_NOTRUNNING') phase_postoperation_notrunning ;; 'POSTOPERATION_RUNNING') phase_postoperation_running ;; 'PREROLLBACK_RUNNING') phase_prerollback_running ;; 'PREROLLBACK_NOTRUNNING') phase_prerollback_notrunning ;; 'POSTROLLBACK_NOTRUNNING') phase_postrollback_notrunning ;; 'POSTROLLBACK_RUNNING') phase_postrollback_running ;; esac exit 0 |
Script to keep a device while zone failover
The below steps will keep a zone device, by a zone – server-pool fialover.
Create the directory
/var/opt/sun/oc/public
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 |
#!/bin/bash # # /var/opt/sun/oc/public/guest-operations # # This script must be placed on all Global Zones and can be used for customizing zone migrations # ZONEADM=/usr/sbin/zoneadm ZONECFG=/usr/sbin/zonecfg ZPOOL=/sbin/zpool AWK=/usr/bin/nawk PREFIX=/var/mnt/virtlibs SHARED_DIR=$(dirname $(grep -l "<guestName>${OEMOC_ZONENAME}</guestName>" ${PREFIX}/*/*/servercfg.xml 2>/dev/null | head -1) ) SHARED_FILE=${SHARED_DIR}/guest-operations_shared_data LOGFILE=${SHARED_DIR}/guest-operations.log log(){ echo "OK: $1" | tee -a $LOGFILE } errorlog(){ echo "ERROR: $1" | tee -a $LOGFILE >&2 exit 1 } if $ZONECFG -z ${OEMOC_ZONENAME} info >/dev/null 2>&1 then ZONE_EXISTS=true else ZONE_EXISTS=false fi ################################################################################## phase_verify() { if $ZONE_EXISTS then # test if the source GZ can use the zone VSI directory for exchanging data if touch $SHARED_FILE 2>/dev/null then log "Successfully created testfile $SHARED_FILE from source GZ" else errorlog "Unable to create testfile $SHARED_FILE" fi else # test if we can see and delete the shared file from the target GZ if [ -f $SHARED_FILE ] then if rm $SHARED_FILE 2>/dev/null then log "Successfully deleted the testfile $SHARED_FILE" else errorlog "Unable to delete the testfile $SHARED_FILE" fi else errorlog "Testfile $SHARED_FILE is not visible from target GZ" fi fi } phase_preoperation_running() { # collect all info about used device $ZONECFG -z "$OEMOC_ZONENAME" info device 2>/dev/null | $AWK '$1 == "match:" {print $2}' > $SHARED_FILE while read DATASET do log "Found device: $DATASET" done < $SHARED_FILE } phase_preoperation_notrunning() { # we have to remove the device and export the zpools while read DATASET do log "Running command: $ZONECFG -z $OEMOC_ZONENAME remove device name=$DATASET" $ZONECFG -z $OEMOC_ZONENAME remove device match=$DATASET done < $SHARED_FILE for zpoolname in $(cut -d/ -f1 $SHARED_FILE |sort -u) do log "Running command: $ZPOOL export $zpoolname" $ZPOOL export $zpoolname done } phase_postoperation_notrunning() { # import zpools but zone does not yet exists for zpoolname in $(cut -d/ -f1 $SHARED_FILE |sort -u) do log "Running command: $ZPOOL import $zpoolname" $ZPOOL import $zpoolname done } phase_postoperation_running() { # # this should no longer be required, with 12c Update2, we are calling the script # when the zone has been created but has not been bootet. There should be no longer # the need to halt the zone first to add the device # # halt zone $ZONEADM -z $OEMOC_ZONENAME halt # add device to zone config while read DATASET do log "adding device $DATASET" $ZONECFG -z $OEMOC_ZONENAME "add device; set match=$DATASET;set allow-raw-io=true;set allow-partition=true;end;commit;exit" done < $SHARED_FILE # boot zone $ZONEADM -z $OEMOC_ZONENAME boot # cleanup rm $SHARED_FILE } phase_prerollback_running() { log "nothing to do" } phase_prerollback_notrunning() { log "nothing to do" } phase_postrollback_notrunning() { log "nothing to do" } phase_postrollback_running() { log "nothing to do" } ################################################################################## case "$OEMOC_PHASE" in 'VERIFY') phase_verify ;; 'PREOPERATION_RUNNING') phase_preoperation_running ;; 'PREOPERATION_NOTRUNNING') phase_preoperation_notrunning ;; 'POSTOPERATION_NOTRUNNING') phase_postoperation_notrunning ;; 'POSTOPERATION_RUNNING') phase_postoperation_running ;; 'PREROLLBACK_RUNNING') phase_prerollback_running ;; 'PREROLLBACK_NOTRUNNING') phase_prerollback_notrunning ;; 'POSTROLLBACK_NOTRUNNING') phase_postrollback_notrunning ;; 'POSTROLLBACK_RUNNING') phase_postrollback_running ;; esac exit 0 |
You might also like this. Oracle Ops Center ASR Blacklist Bug Workaround
Leave a Reply