-
Notifications
You must be signed in to change notification settings - Fork 18
/
run
executable file
·93 lines (78 loc) · 2.65 KB
/
run
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
#!/bin/bash
# Executed by init script
TERM=${TERM:-linux}
INITHOOKS_DEFAULT=/etc/default/inithooks
. $INITHOOKS_DEFAULT
TKLINFO=/var/lib/turnkey-info
unset PID INITHOOKS_LOGFILE
REDIRECT_OUTPUT=$(echo $REDIRECT_OUTPUT | tr [A-Z] [a-z])
log() {
# log to journal as well as $INITHOOKS_LOGFILE
LEVEL=$1 # err|warn|info|debug
shift
logger -t inithooks -p $LEVEL "$@"
[[ -n "$INITHOOKS_LOGFILE" ]] \
&& echo "${LEVEL^^}: $@" >> "$INITHOOKS_LOGFILE"
}
if [[ "$REDIRECT_OUTPUT" == "true" ]]; then
# redirect stdout/stderr (use when preseeding headless deployments)
export INITHOOKS_LOGFILE=/var/log/inithooks.log
touch $INITHOOKS_LOGFILE
chmod 640 $INITHOOKS_LOGFILE
# on xen redirection is performed by the inithooks-xen service
# on lxc and other headless deployments, redirection is handled below
# otherwise redirection is handled by inithooks service and redirected to
# tty8
if [[ ! -f "$TKLINFO/xen" ]]; then
TTY=$(cat /sys/devices/virtual/tty/tty0/active)
[[ -z $TTY ]] && TTY=console
tail -f $INITHOOKS_LOGFILE > /dev/$TTY &
PID="$!"
fi
fi
exec_scripts() {
script_dir=$1
[[ -d "$script_dir" ]] || return 0
for SCRIPT in $(find $script_dir -type f -or -type l | sort); do
[[ -e $INITHOOKS_CONF ]] && . $INITHOOKS_CONF
script=$(basename $SCRIPT)
if [[ ! -x "$SCRIPT" ]]; then
log warn "[$script] skipping"
continue
fi
log info "[$script] running"
"$SCRIPT"
exit_code=$?
if [[ "$exit_code" -eq 0 ]]; then
log info "[$script] successfully completed"
elif [[ "$script" = "95secupdates" ]] && [[ "$exit_code" -eq 2 ]]; then
log info "[$script] detected live system - skipping"
elif [[ "$script" = "95secupdates" ]] && [[ "$exit_code" -eq 42 ]]; then
log warn "[$script] reboot is required"
log err 'Rebooting now!'
systemctl reboot
exit 0
else
log err "[$script] failed - exit code $exit_code"
fi
done
return 0
}
[[ -e $INITHOOKS_CONF ]] && . $INITHOOKS_CONF
export INITHOOKS_CONF=$INITHOOKS_CONF
if [[ "${RUN_FIRSTBOOT,,}" == "true" ]]; then
exec_scripts $INITHOOKS_PATH/firstboot.d
fi
exec_scripts $INITHOOKS_PATH/everyboot.d
if [[ -n "$PID" ]]; then
kill -9 $PID || true
fi
if [[ "${REDIRECT_OUTPUT,,}" == "true" ]]; then
log info "Inithook run completed, exiting."
else
log info "Inithook run completed, now starting confconsole"
sleep 2 # anyway to replace this?
confconsole --usage
log info "Confconsole started, inithooks exiting"
fi
exit 0