aws-samples / aws-opensource-mailserver

MIT No Attribution
8 stars 9 forks source link

Error while provisioning EC2 instance #1

Open rioastamal opened 1 year ago

rioastamal commented 1 year ago

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 uses sudo to run several commands.

Fixes

My fix is simple, I modify EC2 userdata on CloudFormation template and write the hostname to /etc/hosts file.

          # ...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...
FluffyCheeks commented 10 months ago

@rioastamal I'm facing the same issue when trying to provision the instance despite modifying adding the echo command. Any idea how I could further diagnose this? Your comment is the only info I could find regarding this issue...

image SCR-20230827-nhye
rioastamal commented 10 months ago

Hi @FluffyCheeks, my suggestion is during the CREATE_IN_PROGRESS of EC2Instance resource try to see on EC2 dashboard if the instance is in Running state. If it does just try to SSH in and do some quick debugging. To prevent the terminated by CloudFormation you can send signal to CloudFormation that the EC2 is fine and ready to use.

/usr/local/bin/cfn-signal --success true --stack CF_STACK_ID --resource EC2Instance --region REGION
FluffyCheeks commented 10 months ago

Hi @rioastamal, really appreciate your response, am new to this so knowing that the signal to stop the termination can be sent from the instance was really helpful. It appears to be issues with setup/nextcloud.sh failing to wget the installation package, which causes all subsequent steps to fail, specifically when it tries to run wget_verify https://download.nextcloud.com/server/releases/nextcloud-$version.zip $hash /tmp/nextcloud.zip. when running InstallNextcloud(). Will have to look into this further. Again thanks for pointing me in the right direction.

teckdev commented 2 months ago

I tried @rioastamal fix but it still fails to create the instance correclty. Anybody else got this working?

jimisens commented 1 month ago

Hello! I am trying to implement this solution following the steps described here: https://aws.amazon.com/es/blogs/opensource/fully-automated-deployment-of-an-open-source-mail-server-on-ay/ I need to migrate all my emails from Gandi, therefore I am not configuring my domain (DNS, Glue Records), I plan to do that later when the solution is active.

However, the CloudFormation stack fails to complete. I'm wondering if this is because my domain is not set up yet or is there some other reason it could be failing? Captura de pantalla 2024-05-15 a la(s) 10 35 22 a m I would appreciate if you could guide me to solve my problem, any ideas?

mmeidlinger commented 1 month ago

Did you use the most recent version of the CloudFormation template from my PR above (as opposed to the hitting the "Launch" Button from the Blogpost that still references the old version)?

jimisens commented 1 month ago

Thank you @mmeidlinger I did try to use your template. I downloaded it, then uploaded it to CloudFormation. Same situation, the process fails to complete. I have reviewed everything, static IP, buckets... The only thing I have not done is change the configuration of my domain. Do you think it has something to do with it ?