-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathprovision.sh
More file actions
executable file
·123 lines (101 loc) · 3.35 KB
/
Copy pathprovision.sh
File metadata and controls
executable file
·123 lines (101 loc) · 3.35 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
set -e
install_systemd_unit() {
while [[ $# -ge 2 ]]; do
case $1 in
--workdir)
shift
workdir="WorkingDirectory=$1"
shift
;;
*)
break
;;
esac
done
name=$1
command=$2
port=$3
extraenv=$4
# Build environment variables section
env_section="Environment=\"PORT=${port}\"\nEnvironment=\"NODE_VERSION=20\""
# Split extraenv and add each variable as a separate Environment line
if [[ -n "${extraenv}" ]]; then
while IFS= read -r -d ' ' env_var; do
if [[ -n "${env_var}" ]]; then
env_section="${env_section}\nEnvironment=\"${env_var}\""
fi
done <<< "${extraenv} "
fi
# The start limit is left enabled on purpose. These services are
# Restart=always with RestartSec=1, so one which fails immediately restarts
# forever: it stays in "activating (auto-restart)" and never reaches "failed",
# which makes a broken fixture look like a service the Agent failed to
# discover rather than a service that is not running. Letting the limit stop
# it turns that into a failed unit instead. The counter is reset by an
# explicit systemctl stop, so the start/stop cycles the tests do between
# subtests never accumulate towards it.
cat > "/etc/systemd/system/${name}.service" <<- EOM
[Unit]
Description=${name}
After=network.target
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=${command}
$(echo -e "${env_section}")
${workdir}
[Install]
WantedBy=multi-user.target
EOM
}
apt-get update
apt-get install -y \
ca-certificates \
curl \
gnupg \
python3 \
python3-pip \
# Install Python deps
pip install ddtrace==4.7.1
# Install Node
if [ ! -d "${HOME}/.nvm" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
fi
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
source "${NVM_DIR}/nvm.sh"
# Retry a few times since occasional failures have been seen
nvm install 20.20.1 || nvm install 20.20.1 || nvm install 20.20.1
npm install json-server@1.0.0-beta.15 || npm install json-server@1.0.0-beta.15
npm install /home/ubuntu/e2e-test/node/instrumented
# Install Ruby
## Packages
apt-get install -y \
ruby \
ruby-dev \
sqlite3 \
pkg-config \
libyaml-dev \
gem install rails -v 7.1.5.1
## Create new Rails project
pushd /home/ubuntu
rails new rails-hello --minimal
popd
# Install our own services
## Node
install_systemd_unit "node-json-server" "$NVM_DIR/nvm-exec npx json-server --port 8084 /home/ubuntu/e2e-test/node/json-server/db.json" "8084" ""
install_systemd_unit "node-instrumented" "$NVM_DIR/nvm-exec node /home/ubuntu/e2e-test/node/instrumented/server.js" "8085" ""
## Python
install_systemd_unit "python-svc" "/usr/bin/python3 /home/ubuntu/e2e-test/python/server.py" "8082" "DD_SERVICE=python-svc-dd DD_VERSION=2.1 DD_ENV=prod"
install_systemd_unit "python-instrumented" "/usr/bin/python3 /home/ubuntu/e2e-test/python/instrumented.py" "8083" "DD_SERVICE=python-instrumented-dd"
install_systemd_unit "python-restricted" "/usr/bin/python3 /home/ubuntu/e2e-test/python/server.py" "8086" "DD_SERVICE=python-restricted-dd"
## Ruby
install_systemd_unit --workdir "/home/ubuntu/rails-hello" "rails-svc" "rails server" "7777" ""
systemctl daemon-reload
## leave them stopped
systemctl stop python-svc