StartScript customization

am working on java project that we use gradle to build and deploy our
software. I would like to add sub-script to the start script that gradle
produces. For example if I wanted to make my java application not start if
another instance of that application is running.

I would like to do the following to be added just before the JVM command

        exec 200>/tmp/myTestAppLock.tmp

        if ! flock -n 200 ; then

            echo "Another Instance of this application is running now,

wait for it to complete and try again."


         exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH"

“$applicationMain” “$@”

What is the most simple way to do that:
Do I need to modify the default CreateStartScripts class in gradle source?,
or should I use a new CustomLinuxStartScript.text, and if yes , how one would make new template that defaultStartScripts understands?, or maybe I should utilize another gradle nlugin/task to modify the generated startscript after it get produced by gradle?


The preferred method here would be to use a custom script template. The templates use the Groovy simple template engine. You can take a look at the templates used to generate the default start scripts as an example.