#!/bin/ksh -p # # # # # # # # # # # # # # # # # # # # # Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. # # This script is only called by kz AI media install when the AI media has # image version >= 5.0. The auto-install-completion service is added to # the image at version 5.0 or above. . /usr/lib/brand/solaris-kz/common.ksh f_bad_opt=$(gettext "Option -%s is invalid. Usage: install_watcher -z zonename -R zonepath [-x no_auto_shutdown]") f_get_service_state=$(gettext "fail to get the state of service %s") f_install=$(gettext "Automated installation failed. Please use the option '-x no-auto-shutdown' during kernel zone install if you wish to leave the zone booted with the installation program attached to the console on failure. See more details in solaris-kz(5).") f_zone_path=$(gettext "No Zone path or name") function trap_exit { halt_zone vlog "Exiting with exit code $EXIT_CODE" finish_log zone exit $EXIT_CODE } function zlogin { /usr/sbin/zlogin -S "$@" } function copy_ai_install_log { vlog "==== Copying: AI Install Log: ====" zlogin "$ZONENAME" 'cat /system/volatile/install_log' 1>&2 vlog "==== Completed: AI Install Log ====" } function halt_zone { # If user specifies the 'no-auto-shutdown' option, # then leave the zone booted on console [[ -n $no_auto_shutdown ]] && return zoneadm -z "$ZONENAME" halt } # Used by start_log() set -A save_args "$0" "$@" ZONENAME="" ZONEPATH="" unset no_auto_shutdown # The arguments of this script are all set in media_install.ksh, # and media_install only sets the R, x, z options, so there will be # no other option cases while getopts "R:x:z:" opt; do case $opt in R) ZONEPATH="$OPTARG" ;; x) no_auto_shutdown="$OPTARG" ;; z) ZONENAME="$OPTARG" ;; *) fail_fatal "$f_bad_opt" "$opt" esac done shift $((OPTIND-1)) if [[ -z $ZONEPATH || -z $ZONENAME ]]; then fail_fatal "$f_zone_path" fi zone= init_zone zone "$ZONENAME" "$ZONEPATH" eval $(bind_legacy_zone_globals zone) start_log zone install "${save_args[@]}" trap trap_exit EXIT # Wait until the service instance's restarter is loaded and the state is updated. typeset -i timeleft for (( timeleft=300; timeleft > 0; timeleft-- )); do state=$(zlogin "$ZONENAME" \ 'svcs -H -o state svc:/application/auto-install-completion' \ 2>/dev/null) [[ $state == "disabled" ]] && break sleep 1 done [[ timeleft == 0 ]] && fail_fatal "$f_get_service_state" "svc:/application/auto-install-completion" # Enable auto-install-completion service with the -s and -t option. # -s option: block until the service instance enter the online or degraded state # -t option: temporarily enable the instance, prevent any writes to the disk zlogin "$ZONENAME" 'svcadm enable -st svc:/application/auto-install-completion' IFS="," set -A auxstates $(zoneadm -z "$ZONENAME" list -pa | awk -F: '{print $10}') unset IFS for s in "${auxstates[@]}"; do if [[ "$s" == "installed" ]]; then copy_ai_install_log break elif [[ "$s" == "install-failed" ]]; then copy_ai_install_log fail_fatal "$f_install" break fi done halt_zone finish_log zone trap - EXIT exit $ZONE_SUBPROC_OK