How to auto-provision AMI gateway on Amazon

Document ID : KB000071459
Last Modified Date : 12/07/2018
Show Technical Document Details
APIM gateway supports headless configuration and Amazon AMI supports cloud-init script, but running headless configuration in cloud-init as per the product document will fail because the documentation assumes the gateway is up and running. When the cloud-init script is executed during the initialization of the AMI instance, the gateway and mysql are not yet started so it will fail.

Need to ensure the gateway is running before start headless config.
When EC2 instance is launched via the gateway AMI  a user-data script can be input in the Instance Details, Advanced Options section.
Here is an example of a user-data script (which connects to mysql locally) to start the mysql and gateway first.

service mysql start
service ssg start
sleep 2m
echo configure.db=true >
echo database.type=mysql >>
echo >>
echo database.port=3306 >>
echo >>
echo database.user=gateway >>
echo database.pass=7layer >>
echo database.admin.user=root >>
echo database.admin.pass=7layer  >>
echo node.enable=true >>
echo configure.node=true >>
echo admin.user=admin >>
echo admin.pass=7layer >>
echo`hostname` >> 
echo cluster.pass=7layer >>
cat | /opt/SecureSpan/Gateway/config/bin/ssgconfig-headless create
# end of script

The /var/log/cloud-init-output.log shows following,
Cloud-init v. 0.7.5 running 'modules:config' at Mon, 05 Feb 2018 23:17:45 +0000. Up 652.75 seconds.
Cloud-init v. 0.7.5 running 'modules:final' at Mon, 05 Feb 2018 23:17:52 +0000. Up 659.44 seconds.
Starting MySQL............. SUCCESS!
Starting Gateway Services: [  OK  ]
Configuration Successful
Additional Information:

Auto-Provision a Gateway Node