【发布时间】:2016-06-08 04:36:23
【问题描述】:
我正在使用部署到 Amazon AWS 的 Grails 2 应用程序,该应用程序使用软件负载均衡器 (ELB)。我们遇到的问题是 grails 应用程序实例在应用程序完全初始化之前被添加到负载均衡器中。它是 resources 插件,专门提供静态资源,如 javascript、css、图像等。
负载平衡器向“健康检查”URL 发出 http 请求。
GET '/myapp/lbcheck'
LoadBalancerController.groovy:
package myapp
class LoadBalancerController {
def healthService
def healthcheck() {
response.contentType = 'text/plain'
try {
healthService.checkDatabase()
render(status: 200, text: "Up")
}
catch(Exception ex) {
log.error("Error with database healthcheck " + ex)
render(status: 503, text: "Down")
}
}
}
HealthService.groovy
package myapp
import groovy.sql.Sql
class HealthService {
def dataSource
// Either returns true, or throws an Exception
def checkDatabase() {
Sql sql = new Sql(dataSource)
sql.rows("SELECT 429")
sql.close()
return true
}
}
SQL 查询显然是不够的。似乎我们需要检查框架中的其他类型的属性以确定它已被初始化。
【问题讨论】:
标签: grails load-balancing