Skip to content

Instantly share code, notes, and snippets.

@quchie
Last active June 14, 2018 00:37
Show Gist options
  • Save quchie/b9091321a79abe26f53297ba7af593f7 to your computer and use it in GitHub Desktop.
Save quchie/b9091321a79abe26f53297ba7af593f7 to your computer and use it in GitHub Desktop.
Grails 3 Deployment as a service and fat jar

Add to build.gradle (!IMPORTANT, add probably at the end of the file, after 'apply'):

springBoot {
    // Enable the creation of a fully
    // executable archive file.
    executable = true
}

start build the war:

$ grails assemble
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:findMainClass
:buildProperties UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileGsonViews UP-TO-DATE
:war
:bootRepackage
:assemble

BUILD SUCCESSFUL

Total time: 12.852 secs
| Built application to build/libs using environment: production

Then, create a new file in the same folder, with the same name as the war but give it .conf extension:

$ echo "" > myapp.conf

Open the newly created file and add this config Reference :

The MODE parameter is important! this config will allow our app to run on port 9999 and different environment. Change as you like.

MODE=service
JAVA_OPTS=-Dgrails.env=prod
RUN_ARGS=--server.port=9999
LOG_FOLDER=logs
PID_FOLDER=pid

Change the .war to .jar (Optional)

mv myaspp.war myaspp.jar

Create 2 new folder, 'pid' and 'logs' (Optional, just remove in parameters in conf file to leave it to default)

mkdir pid
mkdir logs

Now, Copy all the files and folders to your target server / destination. make sure the folder structure is like below:

myapp-folder/ 
    /myapp.jar
    /myapp.conf
    /pid
    /logs

then, in your server, cd to the folder and start the app

./myapp.jar start

you can check for available commands:

./myapp.jar
Usage: ./myapp.jar {start|stop|force-stop|restart|force-reload|status|run}

Thank you for reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment