Configuration for grails-redis plugin - grails

I'm attempting to use the grails-redis plugin so that I can implement a distributed object cache. I've got both cache and cache-redis in my BuildConfig:
compile ':cache:1.1.8'
compile ":cache-redis:1.1.0"
And I have redis running locally. I know it is working because if I kill redis, the grails app can't connect to it. What I'm not finding is how to modify the configuration for redis when I'm not running locally.
There is nothing in the docs here. I also looked through the source here and found nothing of note.
How do I configure the redis settings (host, port, timeout, etc) ?

Take a closer look at the CacheRedisGrailsPlugin.groovy for the plugin itself. You will see that redis itself is configured in the doWithSpring phase of the plugin setup and reads from the redisCacheConfig configuration file for such things as host, port, etc.
Thus, adding something like the following to your Config.groovy would be perfectly acceptable:
grails {
cache {
redis {
hostName = 'localhost'
port = 6379
timeout = 2000
}
}
}

Related

Grails get stuck at "finished configuring Spring Security REST"

I type grails run-app and it begins to run, but it gets stuck on the message:
----------------------------------------
Current config:
baseDir: db/migration/global
env: DEVELOPMENT
dataSource: default
url: jdbc:postgresql://localhost:5432/mydbapp
username: postgres
schemas: public
----------------------------------------
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security REST ...
... finished configuring Spring Security REST
It used to run fine like an hour ago. No strange logs or anything. Also, when hit ctrl+c in the terminal, grails will close, but when I run-app again, it will say something like:
Error Server failed to start for port 8080: Address already in use (Use --stacktrace to see the full trace)
Indicating that grails wasn't really terminated. Of course, I kill the app occupying 8080 and run-app again, but it's still getting stuck.
The port 8080 is been used for another thread. Try to find a java thread in your system that you don't recognize and stop it.
How to on windows
How to on Linux
In BuildConfig.groovy, change your apps port. Example:
grails.server.port.http = 8003
If you still get port in use, exit IntelliJ, goto Task Manager, sort by memory used, end any processes with IntelliJ or Grails.
If you are using liquibase database migration tool and if you somehow stopped it before it finishes it will put a lock at DATABASECHANGELOGLOCK table. Change it to LOCKED = false and it will start.

3.0.0.M1 how to run on https connection

Trying Grails 3.0.0.M1, a lot has changed!
How would I run-app --https and how would I configure it that way also for the production-environment-war?
Many thanks!
First of all, Grails 3.0.0.M1 is not production ready, if thinking about making the move.
Major changes for Grails 3 include:
Built on top of Spring Boot
Introduction of Gradle as the build system
And many more (which is not relevant to this question)
In order to setup SSL for Spring Boot app, server.ssl.* setting has to be added to application.properties or application.yml file.
In Grails 3 it would correspond to application.yml under grails-app/conf. Below changes (as an example) would be required:
server:
port: 8443
ssl:
key-store: classpath:keystore.jks
key-store-password: secret
key-password: another-secret
which is equivalent to Configuring SSL in Spring Boot.
However, documentation is limited right now and is being worked on. So let Grails 3 brew more until its GA where it can be used in production environment.
Grails community will be more than happy if any issues/problems/enhancement is reported in Grails JIRA

Is there a way make a Grails app aware of changes in properties file without server restart?

I've externalized the properties file for my production Grails app running on Tomcat.
I'm wondering if there is a way the Grails app will read the configs from the config file in real time instead of having the changes take affect only after server restart.
For example, I'm using the LDAP plugin which has the following config:
grails.plugin.springsecurity.ldap.context.managerDn = 'somethinghere'
If I change the above setting in the external config file the server needs to be restarted for it to take effect.
I googled "grails external reload" and the first result was http://grails.org/plugin/external-config-reload

HTTPS Grails application URL

My Grails app runs over HTTPS and in Config.groovy I've set:
environments {
development {
grails.serverURL = "https://localhost:8443/foo"
}
}
When I execute grails run-app to start the app in dev mode, the last message printed on the console is:
Server running. Browse to http://localhost:8082/foo
If I accidentally click on this URL to access the application, I get various errors due to the same-origin security policy (because https://localhost:8443 is a different host to http://localhost:8082).
Why is Grails prompting me to access my app via http://localhost:8082/foo when I've set grails.serverURL = "https://localhost:8443/foo"
Update
I changed the startup command to grails run-app -https and the last message printed on the console is now:
Server running. Browse to http://localhost:8082/foo or https://localhost:8443/foo
Why am I given the option of either HTTP or HTTPS, rather than just the latter? Also, I get this exception during startup:
http11.Http11Protocol Failed to initialize end point associated with ProtocolHandler ["http-bio-8443"]
java.net.BindException: Address already in use <null>:8443
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:407)
I've checked if port 8443 is in use before I run this command (it isn't), but the server seems to startup despite this exception, so this is not a major concern.
Replace grails.serverURL with the code below.
Its possible to set the port with the following system properties:
grails.server.port = 8082
That should work for both http and https. To configure for just one:
grails.server.port.https = 8082
You need to use the --https parameter to run-app for Grails to respond to HTTPS and HTTP in development mode. At least according to the documentation.
Try using
grails run-app --https
Further more, the grails.serverURL is typically used by taglibs and plugins, and not the launching process as far as I can tell.
You can set the ssl port you want to run you application on via https in BuildConfig.groovy. You can add the following to your BuildConfig.groovy
//You can specify another port here to get rid of your startup exception
grails.server.port.https="8443"
grails.server.host="localhost"
Then try grails run-app -https and you should be able to run your app on the ssl port you defined or the default 8080 port

grails 2.0 - deploying WAR to remote server (Tomcat), not connecting

I generally run Grails 2.0 from my IDE but have been seeking to deploy an app to a remote Virtual Private Server (linux) where I installed Tomcat and Mysql. I create a production WAR file and copy it to the Tomcat webapps dir, where I can see Tomcat restart and after some "fixing" I see the application come up, adding minimal bootstrap entries into the MySql database fine.
However, I cannot connect to the Grails app (remotely). If I specify www.mydomain.com, I am (finally) able to reach the main Tomcat server "welcome page". I also reach Tomcat if I add a "/" at the end, not my grails app.
As such I'm tried putting in full controller paths that I know work on my dev machine, and then accessing them on the remote machine (note grails.serverURL is configured as http://www.mydomain.com). Doing this, I get
HTTP Status 404 -- The requested resource (/BareBones/bare/create) is not available.
This error is from a BareBones application I created, as I was having some problems with VPS available memory. In any case, on my dev machine I can reach the this BareBones app URL
http://localhost:8080/BareBones/bare/create
as expected. When I deploy, I get the same HTTP Status 404 error (resource not available) when I do:
http://www.mydomain.com/bare/create
In Config.groovy, in this BareBones app I've got the minimal change:
environments {
development {
grails.logging.jul.usebridge = true
}
production {
grails.logging.jul.usebridge = false
grails.serverURL = "http://www.mydomain.com"
}
}
In my Tomcat server.xml file I changed over from the default 8080/8443 ports to 80/443, but using either either set results in the same problem.
I'm probably missing an easy step, just don't know what it is.
P.S. When I deploy the sample.war file that comes with Tomcat (isn't Grails, just a hello-world servlet), it works. I'm able to access that at
www.mydomain.com/sample
Since I FTP'd sample.war from my computer to the server, it would appear to indicate my FTPs are good, and the routing to the server is right, narrowing this down to Grails & Tomcat.
Usually in dev mode Grails mounts, as you pointed out, the context of appName, i.e. http://localhost:8080/BareBones/ here.
But the path it mounts on tomcat is not up to Grails itself, it is wholly dependent on the Tomcat configuration and primarily the name of the WAR file.
Even if you have BareBones as your appName and you deploy it as ROOT.war then it will mount the root "/" context. If you deploy it as BareBones.war then it should mount the same dir as in dev mode.
Because sites are usually mounted as ROOT.war "/", I can recommend setting
grails.app.context = "/"
in your Config.groovy file which will make it so that you will use the root context path also in dev, i.e. http://localhost:8080/
This makes it simpler since both dev and production will now have identical relative paths to everywhere and only the hostname:port will change.

Resources