0
votes

When provisioning an instance, I am using "remote-exec" to execute some commands and then start up a tomcat instance through terraform. It looks something like this:

resource "null_resource" "mount_fss_on_DFSrvr" {
depends_on = ["oci_core_instance.DFSrvr",
  "oci_file_storage_export.export_FileListener_FileListenerMount",
]

count = "${var.proddfsrvr_count}"

provisioner "remote-exec" {
  connection {
    agent       = false
    timeout     = "15m"
    host        = "${oci_core_instance.DFSrvr.*.public_ip[count.index % var.proddfsrvr_count]}"
    user        = "opc"
    private_key = "${file(var.ssh_private_key)}"
  }

  inline = [
   "some commands",
    "./catalina.sh start",
    "exit"
  ]
}

}

The output shows that tomcat was started, but when I look on the instance, the logs show that it hasn't been started(there is no logging). I can ssh into the instance and run "./catalina.sh start" and it works fine. I have also tried creating a service and running "sudo service tomee start" instead of "./catalina.sh start" in the remote-exec inline command, and that doesn't work either. What am I doing wrong here?

  null_resource.mount_fss_on_DFSrvr[1] (remote-exec): Using CATALINA_BASE:   /apache-tomee-plus-7.0.4
null_resource.mount_fss_on_DFSrvr[1] (remote-exec): Using CATALINA_HOME:   /apache-tomee-plus-7.0.4
null_resource.mount_fss_on_DFSrvr[1] (remote-exec): Using CATALINA_TMPDIR: /apache-tomee-plus-7.0.4/temp
null_resource.mount_fss_on_DFSrvr[1] (remote-exec): Using JRE_HOME:        /usr
null_resource.mount_fss_on_DFSrvr[1] (remote-exec): Using CLASSPATH:       /apache-tomee-plus-7.0.4/bin/bootstrap.jar:/apache-tomee-plus-7.0.4/bin/tomcat-juli.jar
null_resource.mount_fss_on_DFSrvr[1] (remote-exec): Tomcat started.
2
is "catalina.sh" has executable bit? maybe you can try "sh catalina.sh start". seems that you shoul add parameters to "remote-exec" [link] (terraform.io/docs/provisioners/remote-exec.html) - Aleksei Kurepin
@Aleksei Kurepin Yes, it is executable. I can ssh into the instance after and run it just fine. And the output that I posted shows that it ran successfully and Tomcat started. "sh catalina.sh start" does not work either. Thank you for your response. - Justin

2 Answers

2
votes

I had the same problem but while running a python web app. I guess the issue here is when you run the commands through remote-exec, it exits out of the shell once completed. So when you ssh into the machine it opens through a new shell, you should prefix nohup to your command and I believe that should do the trick. That did it for me though. Use & if you want it to run on background and come out of remote-exec. Also, you might want to add a "sleep 20" to the inline commands, this would give tomcat time to startup before the provisioner exits.

inline = [ "some commands", "nohup ./catalina.sh start &", "sleep 20", ]

1
votes

Try giving it the absolute path rather than ./ something like source ~/tmp/catalina.sh. It might not start where you think.

Second remove the exit line. It might be exiting before the installation is complete. Some things finish before writing to the disk. You could also try source ~/path/catalina; sync

Also, does this need sudo permissions at all?