title: User data bash script to start services in EC2 instance not executing
body: <p>I'm having difficulty getting certain services running within my EC2 instance. I'm using an Amazon Linux AMI, and would like to start <code>neo4j</code>, the graphical database, as a service when my instance first launches. </p>
  
  <p>However, I've been having trouble getting anything start, let alone <code>neo4j</code>. I can't even get the basic <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html" rel="nofollow noreferrer">tutorial user data script</a> provided by Amazon working. I copied and pasted the below code:</p>
  
  <pre><code>#!/bin/bash
  yum update -y
  yum install -y httpd24 php56 mysql55-server php56-mysqlnd
  service httpd start
  chkconfig httpd on
  </code></pre>
  
  <p>into the User Data section of my EC2 instance, and then started up my EC2 instance. Theoretically, since <code>httpd</code> is started, I should be able to navigate to the IP address of my instance in a browser and see the default Apache web page (I have allowed inbound HTTP at port 80 for security group settings). However, I get a <code>Connection refused</code> error. </p>
  
  <p>This is confirmed when I issue the following commands after SSH-ing into my instance:</p>
  
  <p><code>sudo su
  service httpd status</code></p>
  
  <p>The response is <code>httpd is stopped</code>, when clearly the user data script is supposed to start it. Amazon recommends to debug that I check <code>/var/log/cloud-init-output.log</code> for error messages, but I don't see any when I inspect the log:</p>
  
  <pre><code>Cloud-init v. 0.7.6 running 'init-local' at Sun, 12 Nov 2017 16:41:03 +0000. Up 5.73 seconds.
  Cloud-init v. 0.7.6 running 'init' at Sun, 12 Nov 2017 16:41:03 +0000. Up 5.91 seconds.
  ci-info: +++++++++++++++++++++++Net device info+++++++++++++++++++++++
  ci-info:  Device   Up     Address         Mask          Hw-Address    
  ci-info:    lo    True   127.0.0.1     255.0.0.0            .         
  ci-info:   eth0   True  172.31.7.27  255.255.240.0  0a:8c:a2:67:1f:46 
  ci-info: ++++++++++++++++++++++++++++++Route info+++++++++++++++++++++++++++++++
  ci-info:  Route    Destination     Gateway        Genmask      Interface  Flags 
  ci-info:    0        0.0.0.0      172.31.0.1      0.0.0.0         eth0      UG  
  ci-info:    1    169.254.169.254   0.0.0.0    255.255.255.255     eth0      UH  
  ci-info:    2       172.31.0.0     0.0.0.0     255.255.240.0      eth0      U   
  Generating public/private rsa key pair.
  Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
  Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
  The key fingerprint is:
  ...
  The key's randomart image is:
  +---[RSA 2048]----+
  [RANDOM ART]
  +----[SHA256]-----+
  Generating public/private dsa key pair.
  Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
  Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
  The key fingerprint is:
  ...
  The key's randomart image is:
  +---[DSA 1024]----+
  +----[SHA256]-----+
  Generating public/private ecdsa key pair.
  Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
  Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
  The key fingerprint is:
  ...
  The key's randomart image is:
  ... [RANDOMART IMAGE]
  Cloud-init v. 0.7.6 running 'modules:config' at Sun, 12 Nov 2017 16:41:04 +0000. Up 6.70 seconds.
  Loaded plugins: priorities, update-motd, upgrade-helper
  No packages needed for security; 0 packages available
  No packages marked for update
  Cloud-init v. 0.7.6 running 'modules:final' at Sun, 12 Nov 2017 16:41:08 +0000. Up 10.93 seconds.
  Cloud-init v. 0.7.6 finished at Sun, 12 Nov 2017 16:41:08 +0000. Datasource DataSourceEc2.  Up 11.04 seconds
  Cloud-init v. 0.7.6 running 'init-local' at Sun, 12 Nov 2017 17:10:45 +0000. Up 5.85 seconds.
  Cloud-init v. 0.7.6 running 'init' at Sun, 12 Nov 2017 17:10:46 +0000. Up 6.04 seconds.
  ci-info: +++++++++++++++++++++++Net device info+++++++++++++++++++++++
  ci-info:  Device   Up     Address         Mask          Hw-Address    
  ci-info:    lo    True   127.0.0.1     255.0.0.0            .         
  ci-info:   eth0   True  172.31.7.27  255.255.240.0  0a:8c:a2:67:1f:46 
  ci-info: ++++++++++++++++++++++++++++++Route info+++++++++++++++++++++++++++++++
  ci-info:  Route    Destination     Gateway        Genmask      Interface  Flags 
  ci-info:    0        0.0.0.0      172.31.0.1      0.0.0.0         eth0      UG  
  ci-info:    1    169.254.169.254   0.0.0.0    255.255.255.255     eth0      UH  
  ci-info:    2       172.31.0.0     0.0.0.0     255.255.240.0      eth0      U   
  Cloud-init v. 0.7.6 running 'modules:config' at Sun, 12 Nov 2017 17:10:46 +0000. Up 6.61 seconds.
  Cloud-init v. 0.7.6 running 'modules:final' at Sun, 12 Nov 2017 17:10:47 +0000. Up 7.03 seconds.
  Cloud-init v. 0.7.6 finished at Sun, 12 Nov 2017 17:10:47 +0000. Datasource DataSourceEc2.  Up 7.11 seconds
  Cloud-init v. 0.7.6 running 'init-local' at Sun, 12 Nov 2017 17:18:25 +0000. Up 5.60 seconds.
  Cloud-init v. 0.7.6 running 'init' at Sun, 12 Nov 2017 17:18:25 +0000. Up 5.79 seconds.
  ci-info: +++++++++++++++++++++++Net device info+++++++++++++++++++++++
  ci-info:  Device   Up     Address         Mask          Hw-Address    
  ci-info:    lo    True   127.0.0.1     255.0.0.0            .         
  ci-info:   eth0   True  172.31.7.27  255.255.240.0  0a:8c:a2:67:1f:46 
  ci-info: ++++++++++++++++++++++++++++++Route info+++++++++++++++++++++++++++++++
  ci-info:  Route    Destination     Gateway        Genmask      Interface  Flags 
  ci-info:    0        0.0.0.0      172.31.0.1      0.0.0.0         eth0      UG  
  ci-info:    1    169.254.169.254   0.0.0.0    255.255.255.255     eth0      UH  
  ci-info:    2       172.31.0.0     0.0.0.0     255.255.240.0      eth0      U   
  Cloud-init v. 0.7.6 running 'modules:config' at Sun, 12 Nov 2017 17:18:26 +0000. Up 6.41 seconds.
  Cloud-init v. 0.7.6 running 'modules:final' at Sun, 12 Nov 2017 17:18:26 +0000. Up 6.84 seconds.
  Cloud-init v. 0.7.6 finished at Sun, 12 Nov 2017 17:18:26 +0000. Datasource DataSourceEc2.  Up 6.93 seconds
  </code></pre>
  
  <p>I looked on StackOverflow for similar posts, and found this: <a href="https://stackoverflow.com/questions/44055897/user-data-script-doenst-launch-with-ec2-instance?rq=1">user data script doesn't launch with ec2 instance</a>. The accepted answer says that user data scripts only execute on the first boot cycle- does that mean I need to terminate my instance and launch a completely fresh instance in order to execute my script? In which case, I feel like that defeats the whole purpose of a startup script to begin with!</p>
  
  <p>EDIT: I added in a few <code>echo</code> test statements to see if they were being printed out in the logs- nope!</p>
  
  <p>However, I did try <code>curl http://169.254.169.254/latest/meta-data</code> from my EC2 instance, and got back this output:</p>
  
  <pre><code>#!/bin/bash
  echo "Testing 1"
  yum update -y
  echo "Testing 2"
  yum install -y httpd24 php56 mysql55-server php56-mysqlnd
  echo "Testing 3"
  service httpd start
  chkconfig httpd on
  </code></pre>
  
  <p>So it's definitely loading my user data... just not executing it.</p>