|
root / base / usr / src / zyginit / services / zones / stop.sh
stop.sh Bash 32 lines 1013 B
 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
#!/bin/sh
# Halt running non-global zones. Tries init 0 first (graceful, 60s),
# then `zoneadm halt` (forced).
#
# zyginit spawns services with an empty PATH — set one explicitly so
# the wait-loop's `sleep 1` actually delays.  See swap/start.sh for
# the same fix and the 2026-06-01 root-cause notes.
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH

[ -x /usr/sbin/zoneadm ] || exit 0
zonelist=$(/usr/sbin/zoneadm list -p | /bin/nawk -F: '$2!="global"{print $2}')
[ -z "$zonelist" ] && exit 0

for z in $zonelist; do
    /usr/sbin/zlogin "$z" /sbin/init 0 2>/dev/null || true
done

# Wait up to 60s for zones to settle, then halt the remainder.
i=0
while [ $i -lt 60 ]; do
    remaining=$(/usr/sbin/zoneadm list -p | /bin/nawk -F: '$2!="global"&&$3=="running"{print $2}')
    [ -z "$remaining" ] && exit 0
    i=$((i + 1))
    /bin/sleep 1
done

for z in $(/usr/sbin/zoneadm list -p | /bin/nawk -F: '$2!="global"&&$3=="running"{print $2}'); do
    /usr/sbin/zoneadm -z "$z" halt 2>/dev/null || true
done
exit 0