通过Ruby连接到HSQL并关闭服务器

时间:2012-03-07 22:38:00

标签: ruby hsqldb

我正在尝试编写一个Ruby脚本来杀死我的localhost上的数据库服务器。

当我运行'ant hsql'时,它启动数据库(下面的输出),我必须保持该终端窗口打开。     构建文件:/Users/cparaiso/dev/src/testproject-src/build.xml

hsql:

install-parent-pom:
[artifact:install] [INFO] Installing /Users/cparaiso/dev/src/testproject-src/pom.xml to /Users/cparaiso/.m2/repository/org/jasig/portal/uportal-parent/4.0.3/uportal-parent-4.0.3.pom
    [touch] Creating /var/folders/8v/1k2gkj412q1_8084x6lvtbqr0000gn/T/jasig/uportal-parent.pom-110044247-marker
     [echo] Starting HSQL on 8887
     [echo] Using: file:/Users/cparaiso/dev/src/testproject-src/data/uPortal
     [java] [Server@6f507fb2]: [Thread[main,5,main]]: checkRunning(false) entered
     [java] [Server@6f507fb2]: [Thread[main,5,main]]: checkRunning(false) exited
     [java] [Server@6f507fb2]: Startup sequence initiated from main() method
     [java] [Server@6f507fb2]: Could not load properties from file
     [java] [Server@6f507fb2]: Using cli/default properties only
     [java] [Server@6f507fb2]: Initiating startup sequence...
     [java] [Server@6f507fb2]: Server socket opened successfully in 10 ms.
     [java] [Server@6f507fb2]: Database [index=0, id=0, db=file:/Users/cparaiso/dev/src/testproject-src/data/uPortal, alias=uportal] opened sucessfully in 377 ms.
     [java] [Server@6f507fb2]: Startup sequence completed in 388 ms.
     [java] [Server@6f507fb2]: 2012-03-07 15:32:25.198 HSQLDB server 2.2.8 is online on port 8887
     [java] [Server@6f507fb2]: To close normally, connect and execute SHUTDOWN SQL
     [java] [Server@6f507fb2]: From command line, use [Ctrl]+[C] to abort abruptly

我的问题是如何在Ruby中不使用kill命令来关闭服务器以终止进程?

如果我尝试通过kill命令终止进程,我会'BUILD FAILED'并且它会一直卡住,直到我按Ctrl + C.这不是我想要的。有任何想法吗? TIA

1 个答案:

答案 0 :(得分:1)

我不知道如何在Ruby中发出SQL语句,但如果连接到数据库服务器并发出SQL语句SHUTDOWN,它将关闭服务器进程。