This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
run-in-background.sh
executable file
·61 lines (54 loc) · 2.06 KB
/
run-in-background.sh
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
#!/bin/bash
set -eu
readonly SCRIPT_DIR=$(dirname $0)
# Script logs its output (stdout/stderr) simultaneously to a file
# as waagent does not capture output of processes it starts.
exec > >(tee -ia /var/log/azure-docker-extension-enable.log)
exec 2>&1
# This script kicks off the ./bin/docker-extension in the
# background and disowns it with nohup. This is a workaround
# for the 5-minute time limit for 'enable' step and 15-minute
# time limit for 'install' step of the Windows Azure VM Extension
# model which exists by design. By forking and running in the
# background, the process does not get killed after the timeout
# and yet still reports its progress through '.status' files to
# the extension system.
# First, report "transitioning" status through .status file before
# returning from this script so that agent can see the file before
# the main extension executable starts. Another workaround really.
# status_file returns the .status file path we are supposed to write
# by determining the highest sequence number from .settings files.
status_file_path() {
# normally we'd need to find this config_dir by parsing the
# HandlerEnvironment.json, but hey we're in a bash script here,
# so assume it's at ../config/.
local config_dir=$(readlink -f "${SCRIPT_DIR}/../config")
local status_dir=$(readlink -f "${SCRIPT_DIR}/../status")
config_file=$(ls $config_dir | grep -E ^[0-9]+.settings$ | sort -n | tail -n 1)
status_file=$(echo $config_file | sed s/settings/status/)
readlink -f "$status_dir/$status_file"
}
write_status() {
local timestamp="$(date --utc --iso-8601=seconds)"
local status_file=$(status_file_path)
echo "Writing status to $status_file."
cat > "$status_file" <<- EOF
[
{
"version": 1,
"timestampUTC": "$timestamp",
"status": {
"operation": "Enable Docker",
"status": "transitioning",
"formattedMessage": {
"lang": "en",
"message": "Enabling Docker"
}
}
}
]
EOF
}
write_status
set -x
nohup $(readlink -f "$SCRIPT_DIR/../bin/docker-extension") $@ &