aws-samples / aws-samples/aws-opensource-mailserver
Error while provisioning EC2 instance
- Dominant language
- No language data
- Stars
- 17
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
### Issue
CloudFormation always fail when provisioning EC2 instance.
### Expected
CloudFormation should be able to provision all the resources.
### Details
I've tried the steps found at https://aws.amazon.com/blogs/opensource/fully-automated-deployment-of-an-open-source-mail-server-on-aws/.
It turn out caused by the installation script issuing `sudo` command which took long and caused CloudFormation to timed-out. The sudo trying to resolve the hostname but it does not written on `/etc/hosts`. So to execute a singgle command it took ages to complete and gives warning:
```
sudo: unable to resolve host (MY_HOST_NAME)
```
Several script such as [setup/nextcloud.sh](https://github.com/mail-in-a-box/mailinabox/blob/8b19d157359e402f751c86f7e0a1276011277648/setup/nextcloud.sh#L320) uses sudo to run several commands.
### Fixes
My fix is simple, I modify EC2 userdata on [CloudFormation template](https://github.com/aws-samples/aws-opensource-mailserver/blob/main/template.yaml) and write the hostname to `/etc/hosts` file.
```bash
# ...cut...
export PRIMARY_HOSTNAME="${InstanceDns}.${MailInABoxDomain}"
if [[ -z "${InstanceEIP}" ]]; then
export PUBLIC_IP=$(ec2metadata --public-ipv4)
else
export PUBLIC_IP="${InstanceEIP}"
fi
echo "$PUBLIC_IP $PRIMARY_HOSTNAME" >> /etc/hosts
# ...cut...
```
Contributor guide
Assessment
This issue has not been assessed yet.