Skip to content

Commit e469787

Browse files
Fix race condition on deployment creation (#979)
* Run the provisioner scripts as the base AMI user * Stop processes before removing directory
1 parent 841f485 commit e469787

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

deployment/terraform/agent.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ func (t *Terraform) configureAndRunAgents(extAgent *ssh.ExtAgent) error {
6363
}
6464

6565
commands := []string{
66-
"rm -rf mattermost-load-test-ng*",
66+
// Stop and remove are joined with ; so the rm still runs on the first deploy when the services don't exist yet.
67+
// The services must be stopped before removing the directory to avoid a race condition with ltbrowserapi
68+
// writing to browser/node_modules, which causes rm to fail with "Directory not empty".
69+
"sudo systemctl stop ltapi ltbrowserapi 2>/dev/null; sudo rm -rf mattermost-load-test-ng*",
6770
"tar xzf tmp.tar.gz",
6871
"mv mattermost-load-test-ng* mattermost-load-test-ng",
6972
"rm tmp.tar.gz",

deployment/terraform/assets/user_data.sh.tpl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ PROVEOF
1212
chmod +x /tmp/provisioner.sh
1313

1414
# Cloud-init runs user_data as root with a minimal environment.
15-
# Set HOME to the AMI user's home directory since provisioner scripts
16-
# (e.g. nvm) install to $HOME and other code expects files there.
17-
export HOME="/home/${ami_user}"
18-
export USER="${ami_user}"
19-
15+
# Use runuser -l to execute the provisioner as the AMI user with a full
16+
# login shell so that tools like nvm (sourced via ~/.bashrc) are available.
2017
cd /tmp
2118
rc=0
22-
/tmp/provisioner.sh || rc=$?
19+
runuser -l "${ami_user}" -c /tmp/provisioner.sh || rc=$?
2320
if [ $rc -eq 0 ]; then
2421
touch /var/lib/cloud/instance/provisioning-done
2522
else

0 commit comments

Comments
 (0)