Repository navigation
Expand file tree
/
Copy pathzoneinit
More file actions
executable file
·82 lines (61 loc) · 1.86 KB
/
Copy pathzoneinit
File metadata and controls
executable file
·82 lines (61 loc) · 1.86 KB
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
#!/bin/bash
# Copyright 2013, Joyent. Inc. All rights reserved.
PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
export PATH
set -o errexit
set -o xtrace
. /lib/svc/share/smf_include.sh
smf_is_globalzone && exit ${SMF_EXIT_OK}
# Set basedir and default config file
ZONEINIT_INCLUDES=@ZONEINIT_DIR@/includes
ZONECONFIG=/root/zoneconfig
# This script should only continue if
#
# 1) executed as a SMF start method; and
# 2) /var/svc/provisioning exist.
#
# Otherwise, pretend success but do nothing
#
# Pre-create /var/svc/provisioning if /root/zoneconfig exists
# to stay backwards compatible.
[ -e ${ZONECONFIG} ] && touch /var/svc/provisioning
# Do nothing if not under SMF, not provisioning, or already done.
if [[ ! "${SMF_METHOD}" == "start" ]] || \
[[ ! -e /var/svc/provisioning ]] || \
[[ $(svcprop -p application/done zoneinit) =~ true ]]; then
exit ${SMF_EXIT_OK}
fi
function log {
local WHERE=$(basename ${INC-zoneinit})
echo "${WHERE}: $1"
}
function exit_handler {
local WHERE=$(basename ${INC-zoneinit})
local EXITCODE=${2:-95}
if [ ${EXITCODE} -gt 0 ]; then
echo "${WHERE}: $1 ${EXITCODE}"
# Renaming 'provisioning' to 'provision_failure' tells the provisioner
# that we failed and the machine is no good
[ -e /var/svc/provisioning ] && mv /var/svc/provision{ing,_failure}
# Status 95 tells the SMF restarter to fail fatally (not try again)
exit ${SMF_EXIT_ERR_FATAL}
fi
}
trap 'exit_handler "received exit status" $?' EXIT
START_TIME=$(date +%s)
log "(start)"
# Pull in and execute all operations from the 'includes' directory
for INC in ${ZONEINIT_INCLUDES}/*.sh
do
log "(start)"
source ${INC}
done
unset INC
END_TIME=$(date +%s)
RUN_TIME=$((END_TIME-START_TIME))
if [ ${RUN_TIME} -gt 0 ]; then
log "total runtime ${RUN_TIME} seconds"
fi
# provisioner takes over
log "(finish)"
exit ${SMF_EXIT_OK}