Rundeck組み込みDBから外部DBを利用するように変更

## 環境
OS : Red Hat Enterprise Linux Server release 7.3
Rundeck : 2.9.3
DB : Oracle Database 11g

## 前提
DBにユーザが作成済であること

## jdbcDriverのインストール
jdbcDriverのインストール
[ojdbc14.jar](http://www.oracle.com/technetwork/apps-tech/jdbc-10201-088211.html) を入手する
```$ sudo cp ./ojdbc14.jar /var/lib/rundeck/exp/webapp/WEB-INF/lib```
権限変更
```$ sudo chown rundeck:rundeck ojdbc14.jar```

## job定義export
http://rundeck.example.jp:4440

## Rundeck停止
```$ sudo systemctl stop rundeckd.service```

## 接続先変更
組み込みDBから外部DBに変更する
```$ sudo view /etc/rundeck/rundeck-config.groovy```

```rundeck-config.groovy
dataSource {
     url = "jdbc:oracle:thin:@localhost:1521:ORCL"
     driverClassName = "oracle.jdbc.driver.OracleDriver"
     username = "rundeckuser"
     password = "password"
     dialect = "org.hibernate.dialect.Oracle10gDialect"
}
```

## rundeck起動
```$ sudo systemctl start rundeckd.service```

## (起動時にエラーが出る場合)

```
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
        at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:754)
        at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219)
        at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:813)
        at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1051)
        at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:854)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1156)
        at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
        at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3460)
        ... 25 more
```

[rundeck-oracle-dialect.jar](https://github.com/jquick/rundeck_oracle_dialect)
を落として配置

```$ cp ./rundeck-oracle-dialect.jar /var/lib/rundeck/exp/webapp/WEB-INF/lib```
```$ sudo chown rundeck:rundeck /var/lib/rundeck/exp/webapp/WEB-INF/lib/rundeck-oracle-dialect.jar```

設定修正
```$ sudo view /etc/rundeck/rundeck-config.groovy```

```rundeck-config.groovy
dataSource {
     url = "jdbc:oracle:thin:@localhost:1521:ORCL"
     driverClassName = "oracle.jdbc.driver.OracleDriver"
     username = "rundeckuser"
     password = "password"
     // dialect = "org.hibernate.dialect.Oracle10gDialect"
     dialect = "com.rundeck.hibernate.RundeckOracleDialect" ← こちらに変更
}
```

## rundeck再起動
```$ sudo systemctl restart rundeckd.service```

## (ログイン時にエラーが出る場合)
An Error Occurred
getGeneratedKeys() support is not enabled
![rundeckerror.png](https://qiita-image-store.s3.amazonaws.com/0/39442/0421611d-7194-0142-b0ed-0fafbccd4d89.png)


```
2018-04-20 06:35:03,541 [qtp81628611-18] ERROR org.hibernate.AssertionFailure - HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
2018-04-20 06:35:03,576 [qtp81628611-18] ERROR org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver - AssertionFailure occurred when processing request: [GET] /menu/jobs
getGeneratedKeys() support is not enabled. Stacktrace follows:
org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
        at rundeck.services.UserService.findOrCreateUser(UserService.groovy:31)
        at rundeck.controllers.MenuController.jobs(MenuController.groovy:253)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1515)
        at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
        at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:519)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:582)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:448)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
        at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:261)
        at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at com.codahale.metrics.servlet.AbstractInstrumentedFilter.doFilter(AbstractInstrumentedFilter.java:97)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at com.dtolabs.rundeck.server.filters.AuthFilter.doFilter(AuthFilter.java:74)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:519)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:529)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:448)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:446)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:271)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:246)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
        at java.lang.Thread.run(Thread.java:748)
```

設定修正
```$ sudo view /etc/rundeck/rundeck-config.groovy```

```rundeck-config.groovy
dataSource {
     url = "jdbc:oracle:thin:@localhost:1521:ORCL"
     driverClassName = "oracle.jdbc.driver.OracleDriver"
     username = "rundeckuser"
     password = "password"
     // dialect = "org.hibernate.dialect.Oracle10gDialect"
     dialect = "com.rundeck.hibernate.RundeckOracleDialect"
}
hibernate.jdbc.use_get_generated_keys = "true" ← 追加
```

## rundeck再起動
```$ sudo systemctl restart rundeckd.service```

## ログイン
http://rundeck.example.jp:4440

## job定義import
起動させて様子を見る...