Ask Your Question
0

Running my own Java app at startup with Heat template

asked 2016-05-12 05:42:02 -0500

serranossi94 gravatar image

I am developing a cloud-based service and I'd like to automatize it as much as I can. So, I've created my own image with all the software required, including Java. The stand-alone program works perfectly, so I'm now writing a HOT template to create everything at once.

Right now, I'm testing with some pretty simple templates to see if it actually works. However, although my script runs, it doesn't keep my Java program running.

Can someone explain me how to achieve this? I have tried to run the program with nohup in case it was close when cloud-init finished, as well as running as a regular user of the instance.

I attach the test template I'm actually using

heat_template_version: 2015-04-30

description: Definition of the server configuration

parameters:
  flavor:
    type: string
    label: Flavor used by the instances
    description: Flavor used by the instances
  key:
    type: string
    label: SSH key
    description: SSH key
  private_network:
    type: string
    label: Network to connect the instances
    description: Network to connect the instances

resources:
  server:
    type: OS::Nova::Server
    properties:
        image: dnse3-0504
        key_name: {get_param: key}
        flavor: {get_param: flavor}
        networks:
          - network: {get_param: private_network}
        user_data: |
            #!/bin/bash
            echo "Running Server"
            cd /home/user/
            echo $(pwd)
            su ubuntu
            nohup java -jar /home/user/myapp.jar > output.log &
            echo "Server booted"
        user_data_format: RAW
edit retag flag offensive close merge delete

Comments

Is it possible to deploy your Java App to GlassFish 4.1 and run as ServerSide Java Apps ?

dbaxps gravatar imagedbaxps ( 2016-05-12 09:16:30 -0500 )edit

I haven't started jet with Java EE. My app is a server developed with Java SE and Restlet FrameWork. I'll have to find a way to port it, but anyway, thanks.

serranossi94 gravatar imageserranossi94 ( 2016-05-13 03:03:52 -0500 )edit

What I mean , Nova-Docker light weight VM runs fine Glassfish 4.1 ( derby database running ). Docker Image for deployment here http://bderzhavets.blogspot.com/2015/.... Nova-Docker Containers serve much better for Java Servers, the KVM guests in general.

dbaxps gravatar imagedbaxps ( 2016-05-13 03:57:42 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-05-13 04:30:10 -0500

dbaxps gravatar image

updated 2016-05-13 05:09:34 -0500

Using field as comment
Nova-Docker light weight VM runs fine Glassfish 4.1 ( derby database running ). Docker Image for deployment here http://bderzhavets.blogspot.com/2016/...
Nova-Docker Containers serve much better for Java Servers, then KVM guests, in general. What I mean, for almost any Java Server ( GF 4.X,5.X, Jboss, Tomcat ) there are pre-built docker images, which may be used as glance images for creating Nova-Docker Containers ( light weight VMs). Recently been tested with Nova-Docker Mitaka driver (stable release) :-
http://bderzhavets.blogspot.com/2016/...

edit flag offensive delete link more
0

answered 2016-05-19 13:34:50 -0500

zaneb gravatar image

I don't know what's specifically the problem here (probably that nohup is insufficient to properly daemonise your process), but in general just randomly running commands and hoping they stay alive for exactly the amount of time you want them to isn't a great strategy. You'd be much better off creating a systemd unit file (or upstart script, depending on your version of Ubuntu) and just starting the service from the user_data script.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-05-12 05:42:02 -0500

Seen: 308 times

Last updated: May 19 '16