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
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.
#!/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 "${OEMOC_ZONENAME} " ${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
#!/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 "${OEMOC_ZONENAME} " ${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