How to execute multiple box commands while opening the box environment only one time from a script?


I am deploying an application using lucee on Azure, using packer to create RHEL7 images containing our application code as well as the server and tools. Deploying new code requires the creation of a new image and deploying it.

I am using commandbox cfconfig to help with automation of lucee configurations. I have an init.d script which pulls values from azure key vault and sets up data sources and environment variables before starting up lucee.

In my init.d service script, I have lines such as

box cfconfig set adminPassword=$lucee_server_pwd to=/opt/lucee/tomcat/lucee-server
box cfconfig datasource save ...
/opt/lucee/lucee_ctl start

The problem is that each invocation of the box command takes about 12 seconds, which results in a really lengthy startup time as the CommandBox environment needs to load first every time.
Is there a way to send multiple commands into the box environment at once to reduce the duration of execution?

Yes. There are a few ways including piping text with line breaks to the shell. The easiest way to do it however would be with a recipe file, which is basically a text file with one line per command sort of like a Windows batch file.




Now run it

CommandBox> recipe myCommandsToRun.boxr

Thanks for the suggestion, recipes worked great for my use case.

1 Like