问题
I have a grail-2.4.5 based application. The artifact, a WAR file, is deployed to production; the application runs great. Now I would like to run some grails commands related to the database-migration plugins: specifically grails dbm-tag
and grails dbm-rollback
. I'm at a loss at how to do this. Any suggestions would be very welcome; is there a better way to do this?
Versions:
- Grails 2.4.5
- Tomcat 8.0.24
Constraints:
- This is a 12 Factor style application so no configs are stored in the application or source; they are pulled from the environment. So must be run from the environment.
- Even if the configs for production were stored in the source; the production environment is locked down and I cannot connect to it externally to run
grails production ...
- Ideally, this would be do-able via the command line as all these servers are managed by
salt
. - Finally, only the artifact produced from our CI server (the WAR file) is allowed to be promoted to upstream environments like stable, staging, and production to ensure that versions tested and run are consistent through the release process.
Things I'm looking at:
- Have the generated WAR file modified to include manifest information pointing to the grails command line app.
- Seeing if this can be handled through the tomcat manager somehow.
回答1:
Basically, you need a way to run grails code on a production machine. Options are - remote control plugin, console plugin, your custom controller with a secured endpoint that triggers the action or even a custom Quartz job that you can start manually with a Quartz monitor plugin.
The problems with all these is that you are opening a potential vulnerability in your production environment.
Since you are talking about operations on database, you might as well have an unpackaged grails app that connects to the production database and run those commands from there.
回答2:
I don't see any built-in method for connecting to a remote Grails instance. Take a look at the grails remote control plugin.
来源:https://stackoverflow.com/questions/32153380/how-to-run-grails-commands-after-deploying-war-to-tomcat-in-production