FR/Documentation/HSQLDB Guide/ch03

From Apache OpenOffice Wiki
Jump to: navigation, search

Chapter 3. Démarrage rapide sous UNIX

Comment installer et utiliser rapidement Hsqldb sous UNIX et Mac OS X

Blaine Simpson

HSQLDB Development Group

<blaine.simpson@admc.com>

$Date: 2005/07/25 23:20:53 $


But de ce chapitre

Ce chapitre explique comment installer, exécuter et utiliser rapidement Hsqldb sous UNIX.

HSQLDB a beaucoup de fonctionnalités optionnelles puissantes. Je n'en couvrirais que très peu. Ce chapitre couvre ce que je pense être l'installation la plus commune sous UNIX : Exécuter une base de données multi-utilisateurs dotée d'une persistance des données permanente. (Par la suite j'explique que les données sont stockées sur disque pour être persistantes durant les fermetures et démarrages successifs de la base de données). J'explique également comment exécuter Hsqldb comme un démon du système. (system daemon)

Installation

Allez à la page http://sourceforge.net/projects/hsqldb et suivez le lien ("files") "Download". Vous voulez la dernière version. Celle-ci portera le numéro de version le plus élevé sous le titre "Hsqldb". Vérifiez s'il existe la distribution de la version courante dans le format que vous souhaitez.

Si vous voulez un rpm, vous devez trouver la version en cours de HSQLDB comme décrit dans le paragraphe précédent. Ensuite, sur la page http://www.jpackage.org/ cliquez sur "hsqldb" dans "free section" et vérifiez si ils ont déjà construit la version courante de HSQLDB. Hopefully, the JPackage folk will document what JVM versions their rpm will support (currently they document this neither on their site nor within the package itself). (Je ne peux vraiment pas documenter comment télécharger d'un site complètement hors de mon contrôle).

Template:Documentation/Note

L'installation binaire dépend du format de paquets que vous avez téléchargé.


Installation depuis un fichier .pkg.Z

L'utilisation de ce paquetage est réservé à un administrateur Solaris. C'est un paquet System V. Téléchargez puis décompressez ce paquet avec uncompress ou gunzip.

uncompress filename.pkg.Z

Vous pouvez lire à propos de ce paquet en exécutant :

pkginfo -l -d filename.pkg

Connectez vous comme administrateur et exécutez pkgadd pour installer :

pkgadd -d filename.pkg


Installation depuis un fichier .rpm

C'est un paquet Linux rpm. Après que vous ayez téléchargé le rpm, vous obtenez de l'information en exécutant :

rpm -qip /path/to/file.rpm

Vous pouvez installer ou mettre à jour les rpm's en exécutant :

rpm -Uvh /path/to/file.rpm

Commande Administrateur. Les utilisateurs de Suze voudront préserver Yast des paquets installés en exécutant le rpm à partir de Yast : yast2 -i /path/to/file.rpm.


Installation depuis un fichier .zip

Vous devez extraire le fichier zip dans le dossier parent du nouveau dossier racine de HSQLDB. (Vous n'avez pas besoin de créer le dossier HSQLDB_HOME, le processus d'extraction le fera correctement pour vous)

cd parent/of/new/hsqldb/home
unzip /path/to/file.zip

Tous les fichiers de l'archive zip seront extraits dans les sous-répertoires du nouveau dossier hsqldb.


Parcourez les fichiers installés. (Dans le dossier hsqldb issue du zip. Ou bien avec les utilitaires de votre distribution) (Under hsqldb for zip file installations. Otherwise, use the utilities for your packaging system). Le fichier le plus important du système hsqldb est hsqldb.jar, situé dans le dossier lib.

Important.png Important

Pour le propos de ce chapitre, on admet HSQLDB_HOME comme étant le dossier parent du répertoire lib contenant hsqldb.jar. C'est à dire que si votre chemin vers hsqldb.jar est /a/b/hsqldb/lib/hsqldb.jar, celle de HSQLDB_HOME est /a/b/hsqldb.

Si la description de votre distribution précise que le fichier hsqldb.jar fonctionne avec votre version de Java, l'installation est finie. Sinon vous devez construire un nouveau fichier hsqldb.jar.

Si vous avez suivi les instructions ci dessus et ne savez toujours pas quelle version de Java supporte votre hsqldb.jar, lisez HSQLDB_HOME/readme.txt et HSQLDB_HOME/index.html. Si malgré tout vous n'avez pas trouvé vous pouvez tester votre hsqldb.jar et voir s'il fonctionne, ou bien construire le votre.

Pour utiliser le fichier hsqldb.jar fourni, passez directement à la prochaine section de ce document. Ou alors construisez un nouveau fichier hsqldb.jar.


Procédure 3.1. Construire hsqldb.jar

1.
Si Ant n'est pas déjà installé, téléchargez la dernière version binaire stable à http://ant.apache.org . Placez vous dans le dossier pour l'installation et extrayez l'archive avec :
unzip /path/to/file.zip

ou

tar -xzf /path/to/file.tar.gz

ou

bunzip2 -c /path/to/file.tar.bz2 | tar -xzf -

Tous les fichiers seront installés dans un nouveau sous-dossier nommé named apache-ant- + version. Si vous le souhaitez vous pouvez renommer ce dossier après l'extraction.

2.
Définissez la variable d'environnement JAVA_HOME sur votre dossier racine de votre distribution Java JRE ou SDK, comme :
export JAVA_HOME; JAVA_HOME=/usr/java/j2sdk1.4.0

Le chemin est complètement dépendant de la distribution UNIX / Linux. Les distributions Java au format rpm de Sun s'installent normalement dans /usr/java/quelquechose. Les distributions Java de Sun en paquets System V (incluant celles de Solaris) s'installent normalement dans /usr/quelquechose, avec un lien symbolique de /usr/java vers la version par défaut (donc pour Solaris l'adresse de JAVA_HOME est courament /usr/java).

3.
Supprimez le fichier existant HSQLDB_HOME/lib/hsqldb.jar.
4.
Placez vous dans le dossier HSQLDB_HOME/build. Assurez vous que le sous-dossier bin de la racine de Ant soit dans votre recherche de chemins. Exécutez la commande suivante :
ant hsqldb

Ceci construira une nouvelle archive HSQLDB_HOME/lib/hsqldb.jar.

Voir l'annexe A : Construire HSQLDB si vous voulez construire quelque chose d'autre qu'une archive hsqldb.jar avec tous les réglages par défaut.

Setting up a Hsqldb Persistent Database Instance and a Hsqldb Server

If you installed from an OS-specific package, you may already have a database instance and server pre-configured. See if your package includes a file named server.properties (make use of your packaging utilities). If you do, then I suggest that you still read this section while you poke around, in order to understand your setup.

  1.
     Select a UNIX user to run the database as. If this database is for the use of multiple users, or is a production system (or to emulate a production system), you should dedicate a UNIX user for this purpose. In my examples, I use the user name hsqldb. In this chapter, I refer to this user as the HSQLDB_OWNER, since that user will own the database instance files and processes.
     If the account doesn't exist, then create it. On all system-5 UNIXes and most hybrids (including Linux), you can run (as root) something like
         useradd -c 'HSQLDB Database Owner' -s /bin/bash -m hsqldb
     (BSD-variant users can use a similar pw useradd hsqldb... command).
  2.
     Become the HSQLDB_OWNER. Copy the sample file HSQLDB_HOME/src/org/hsqldb/sample/sample-server.properties to the HSQLDB_OWNER's home directory and rename it to server.properties.
     # Hsqldb Server cfg file.
     # See the Advanced Topics chapter of the Hsqldb User Guide.
     server.database.0   file:db0/db0
     # I suggest that, for every file: database you define, you add the
     # connection property "ifexists=true" after the database instance
     # is created (which happens simply by starting the Server one time).
     # Just append ";ifexists=true" to the file: URL, like so:
     # server.database.0   file:db0/db0;ifexists=true
     Since the value of the first database (server.database.0) begins with file:, the database instance will be persisted to a set of files in the specified directory with names beginning with the specified name. Set the path to whatever you want (relative paths will be relative to the directory containing the properties file). You can read about how to specify other database instances of various types, and how to make settings for the listen port and many other things, in the Advanced Topics chapter.
  3.
     Set and export the environmental variable CLASSPATH to the value of HSQLDB_HOME (as described above) plus "/lib/hsqldb.jar", like
         export CLASSPATH; CLASSPATH=/path/to/hsqldb/lib/hsqldb.jar
     In HSQLDB_OWNER's home directory, run
         nohup java org.hsqldb.Server &
     This will start the Server process in the background, and will create your new database instance "db0". Continue on when you see the message containing HSQLDB server... is online. nohup just makes sure that the command will not quit when you exit the current shell (omit it if that's what you want to do). 

Accessing your Database

Copy the file HSQLDB_HOME/src/org/hsqldb/sample/sqltool.rc to the HSQLDB_OWNER's home directory. Use chmod to make the file readable and writable only to HSQLDB_OWNER.

  1. $Id: sqltool.rc,v 1.22 2007/08/09 03:22:21 unsaved Exp $
  1. This is a sample RC configuration file used by SqlTool, DatabaseManager,
  2. and any other program that uses the org.hsqldb.util.RCData class.
  1. You can run SqlTool right now by copying this file to your home directory
  2. and running
  3. java -jar /path/to/hsqldb.jar mem
  4. This will access the first urlid definition below in order to use a
  5. personal Memory-Only database.
  6. "url" values may, of course, contain JDBC connection properties, delimited
  7. with semicolons.
  1. If you have the least concerns about security, then secure access to
  2. your RC file.
  3. See the documentation for SqlTool for various ways to use this file.
  1. A personal Memory-Only (non-persistent) database.

urlid mem url jdbc:hsqldb:mem:memdbid username sa password

  1. A personal, local, persistent database.

urlid personal url jdbc:hsqldb:file:${user.home}/db/personal;shutdown=true username sa password

  1. When connecting directly to a file database like this, you should
  2. use the shutdown connection property like this to shut down the DB
  3. properly when you exit the JVM.
  1. This is for a hsqldb Server running with default settings on your local
  2. computer (and for which you have not changed the password for "sa").

urlid localhost-sa url jdbc:hsqldb:hsql://localhost username sa password


  1. Template for a urlid for an Oracle database.
  2. You will need to put the oracle.jdbc.OracleDriver class into your
  3. classpath.
  4. In the great majority of cases, you want to use the file classes12.zip
  5. (which you can get from the directory $ORACLE_HOME/jdbc/lib of any
  6. Oracle installation compatible with your server).
  7. Since you need to add to the classpath, you can't invoke SqlTool with
  8. the jar switch, like "java -jar .../hsqldb.jar..." or
  9. "java -jar .../hsqlsqltool.jar...".
  10. Put both the HSQLDB jar and classes12.zip in your classpath (and export!)
  11. and run something like "java org.hsqldb.util.SqlTool...".
  1. urlid cardiff2
  2. url jdbc:oracle:thin:@aegir.admc.com:1522:TRAFFIC_SID
  3. username blaine
  4. password secretpassword
  5. driver oracle.jdbc.OracleDriver


  1. Template for a TLS-encrypted HSQLDB Server.
  2. Remember that the hostname in hsqls (and https) JDBC URLs must match the
  3. CN of the server certificate (the port and instance alias that follows
  4. are not part of the certificate at all).
  5. You only need to set "truststore" if the server cert is not approved by
  6. your system default truststore (which a commercial certificate probably
  7. would be).
  1. urlid tls
  2. url jdbc:hsqldb:hsqls://db.admc.com:9001/lm2
  3. username blaine
  4. password asecret
  5. truststore /home/blaine/ca/db/db-trust.store


  1. Template for a Postgresql database
  2. urlid blainedb
  3. url jdbc:postgresql://idun.africawork.org/blainedb
  4. username blaine
  5. password losung1
  6. driver org.postgresql.Driver
  1. Template for a MySQL database. MySQL has poor JDBC support.
  2. urlid mysql-testdb
  3. url jdbc:mysql://hostname:3306/dbname
  4. username root
  5. username blaine
  6. password hiddenpwd
  7. driver com.mysql.jdbc.Driver
  1. Note that "databases" in SQL Server and Sybase are traditionally used for
  2. the same purpose as "schemas" with more SQL-compliant databases.
  1. Template for a Microsoft SQL Server database
  2. urlid msprojsvr
  3. url jdbc:microsoft:sqlserver://hostname;DatabaseName=DbName;SelectMethod=Cursor
  4. The SelectMethod setting is required to do more than one thing on a JDBC
  5. session (I guess Microsoft thought nobody would really use Java for
  6. anything other than a "hello world" program).
  7. This is for Microsoft's SQL Server 2000 driver (requires mssqlserver.jar
  8. and msutil.jar).
  9. driver com.microsoft.jdbc.sqlserver.SQLServerDriver
  10. username myuser
  11. password hiddenpwd
  1. Template for a Sybase database
  2. urlid sybase
  3. url jdbc:sybase:Tds:hostname:4100/dbname
  4. username blaine
  5. password hiddenpwd
  6. This is for the jConnect driver (requires jconn3.jar).
  7. driver com.sybase.jdbc3.jdbc.SybDriver
  1. Template for Embedded Derby / Java DB.
  2. urlid derby1
  3. url jdbc:derby:path/to/derby/directory;create=true
  4. username ${user.name}
  5. password any_noauthbydefault
  6. driver org.apache.derby.jdbc.EmbeddedDriver
  7. The embedded Derby driver requires derby.jar.
  8. There'a also the org.apache.derby.jdbc.ClientDriver driver with URL
  9. like jdbc:derby://<server>[:<port>]/databaseName, which requires
  10. derbyclient.jar.
  11. You can use \= to commit, since the Derby team decided (why???)
  12. not to implement the SQL standard statement "commit"!!
  13. Note that SqlTool can not shut down an embedded Derby database properly,
  14. since that requires an additional SQL connection just for that purpose.
  15. However, I've never lost data by not shutting it down properly.
  16. Other than not supporting this quirk of Derby, SqlTool is miles ahead of ij.

We will be using the "localhost-sa" sample urlid definition from the config file. The JDBC URL for this urlid is jdbc:hsqldb:hsql://localhost. That is the URL for the default database instance of a HSQLDB Server running on the default port of the local host. You can read about URLs to connect to other instances and other servers in the Advanced Topics chapter.

Run SqlTool.

   java -jar path/to/hsqldb.jar localhost-sa

If you get a prompt, then all is well. If security is of any concern to you at all, then you should change the privileged password in the database. Use the command SET PASSWORD command to change SA's password.

   set password "newpassword";

When you're finished playing, exit with the command \q.

If you changed the SA password, then you need to fix the password in the sqltool.rc file accordingly.

You can, of course, also access the database with any JDBC client program. See the First JDBC Client Example appendix. You will need to modify your classpath to include hsqldb.jar as well as your client class(es). You can also use the other HSQLDB client programs, such as org.hsqldb.util.DatabasManagerSwing, a graphical client with a similar purpose to SqlTool.

You can use any normal UNIX account to run the JDBC clients, including SqlTool, as long as the account has read access to the hsqldb.jar file and to an sqltool.rc file. See the SqlTool chapter about where to put sqltool.rc, how to execute sql files, and other SqlTool features.

Create additional Accounts

Connect to the database as SA (or any other Administrative user) and run CREATE USER to create new accounts for your database instance. HSQLDB accounts are database-instance-specific, not Server-specific.

For the current version of HSQLDB, only users with Role of DBA may create or own database objects. DBA members have privileges to do anything. Non-DBAs may be granted some privileges, but may never create or own database objects. (Before long, non-DBAs will be able to create objects if they have permission to do so in the target schema). When you first create a hsqldb database, it has only one database user-- SA, a DBA account, with an empty string password. You should set a password (as described above). You can create as many additional users as you wish. To make a user a DBA, you can use the "ADMIN" option to the CREATE USER command, or GRANT the DBA Role to the account after creating it.

If you create a user without the ADMIN tag (and without granting the DBA role to them) this user will be able to read the data dictionary tables, but will be able unable to create or own his own objects. He will have only the rights which the pseudo-user PUBLIC has. To give him more permissions, even rights to read objects, you can GRANT permissions for specific objects, grant Roles (which encompass a set of permissions), or grant the DBA Role itself.

Since only people with a database account may do anything at all with the database, it is often useful to permit other database users to view the data in your tables. To optimize performance, reduce contention, and minimize administration, it is often best to grant SELECT to PUBLIC on any object that needs to be accessed by multiple database users (with the significant exception of any data which you want to keep secret).

Shutdown

Do a clean database shutdown when you are finished with the database instance. You need to connect up as SA or some other Admin user, of course. With SqlTool, you can run

   java -jar path/to/hsqldb.jar --sql shutdown localhost-sa

You don't have to worry about stopping the Server because it shuts down automatically when all served database instances are shut down.

Running Hsqldb as a System Daemon

You can, of course, run HSQLDB through inittab on System V UNIXes, but usually an init script is more convenient and manageable. This section explains how to set up and use our UNIX init script. Our init script is only for use by root. (That is not to say that the Server will run as root-- it usually should not).

The main purpose of the init script is to start up a Server with the database instances specified in your server.properties file; and to shut down all of those instances plus additional urlids which you may (optionally) list in your init script config file. These urlids must all have entries in a sqltool.rc file. If, due to firewall issues, you want to run a WebServer instead of a Server, then make sure you have a healthy WebServer with a webserver.properties set up, adjust your URLs in sqltool.rc, and set TARGET_CLASS in the config file. (By following the commented examples in the config file, you can start up any number of Server and/or WebServer listeners with or without TLS ecryption).

After you have the init script set up, root can use it anytime to start or stop HSQLDB. (I.e., not just at system bootup or shutdown).

Portability of hsqldb init script

The primary design criterion of the init script is portability. It does not print pretty color startup/shutdown messages as is common in late-model Linuxes and HPUX; and it does not keep subsystem state files or use the startup/shutdown functions supplied by many UNIXes, because these features are all non-portable.

Offsetting these limitations, this one script does it's intended job great on the UNIX varieties I have tested, and can easily be modified to accommodate other UNIXes. While you don't have tight integration with OS-specific daemon administration guis, etc., you do have a well tested and well behaved script that gives good, utilitarian feedback.

Init script Setup Procedure

The strategy taken here is to get the init script to run your single Server or WebServer first (as specified by TARGET_CLASS). After that's working, you can customize the JVM that is run by running additional Servers in it, running your own application in it (embedding), or even overriding HSQLDB behavior with your own overriding classes.

  1.
     Copy the init script hsqldb from HSQLDB_HOME/bin into the directory where init scripts live on your variety of UNIX. The most common locations are /etc/init.d or /etc/rc.d/init.d on System V style UNIXes, /usr/local/etc/rc.d on BSD style UNIXes, and /Library/StartupItems/hsqldb on OS X (you'll need to create the directory for the last).
  2.
     Look at the comment towards the top of the init script which lists recommended locations for the configuration file for various UNIX platforms. Copy the sample config file HSQLDB_HOME/src/org/hsqldb/sample/sample-hsqldb.cfg to one of the listed locations (your choice). Edit the config file according to the instructions in it.
     # $Id: sample-hsqldb.cfg,v 1.16 2005/07/24 18:33:13 unsaved Exp $
     # Sample configuration file for HSQLDB database server.
     # See the "UNIX Quick Start" chapter of the Hsqldb User Guide.
     # N.b.!!!!  You must place this in the right location for your type of UNIX.
     # See the init script "hsqldb" to see where this must be placed and
     # what it should be renamed to.
     # This file is "sourced" by a Bourne shell, so use Bourne shell syntax.
     # This file WILL NOT WORK until you set (at least) the non-commented
     # variables to the appropriate values for your system.
     # Life will be easier if you avoid all filepaths with spaces or any other
     # funny characters.  Don't ask for support if you ignore this advice.
     # Thanks to Meikel Bisping for his contributions.  -- Blaine
     JAVA_EXECUTABLE=/usr/bin/java
     # Unless you copied a hsqldb.jar file from another system, this typically
     # resides at $HSQLDB_HOME/lib/hsqldb.jar, where $HSQLDB_HOME is your HSQLDB
     # software base directory.
     HSQLDB_JAR_PATH=/opt/hsqldb/lib/hsqldb.jar
     # Where the file "server.properties" resides.
     SERVER_HOME=/opt/hsqldb/data
     # What UNIX user the server will run as.
     # (The shutdown client is always run as root or the invoker of the init script).
     # Runs as root by default, but you should take the time to set database file
     # ownerships to another user and set that user name here.
     HSQLDB_OWNER=hsqldb
     # The HSQLDB jar file specified in HSQLDB_JAR_PATH above will automatically
     # be in the class path.  This arg specifies additional classpath elements.
     # To embed your own application, add your jar file(s) or class base
     # directories here, and add your main class to the INVOC_ADDL_ARGS setting
     # below.
     #SERVER_ADDL_CLASSPATH=/usr/local/dist/currencybank.jar
     # We require all Server/WebServer instances to be accessible within 
     # $MAX_START_SECS from when the Server/WebServer is started.
     # Defaults to 60.
     # Raise this is you are running lots of DB instances or have a slow server.
     #MAX_START_SECS=200
     # Time to allow for JVM to die after all HSQLDB instances stopped.
     # Defaults to 1.
     #MAX_TERMINATE_SECS=0
     # These are "urlid" values from a SqlTool authentication file
     # ** IN ADDITION TO THOSE IN YOUR server.properties OR webserver.properties **
     # file.  All server.urlid.X values from your properties file will automatically
     # be started/stopped/tested.  $SHUTDOWN_URLIDS is for additional urlids which
     # will stopped.  (Therefore, most users will not set this at all).
     # Separate multiple values with white space.  NO OTHER SPECIAL CHARACTERS!
     # Make sure to quote the entire value if it contains white space separator(s).
     # Defaults to none (i.e., only urlids set in properties file will be stopped).
     #SHUTDOWN_URLIDS='sa mygms'
     # SqlTool authentication file used only for shutdown.
     # The default value will be sqltool.rc in root's home directory, since it is 
     # root who runs the init script.
     # (See the SqlTool chapter of the HSQLDB User Guide if you don't understand 
     # this).
     #AUTH_FILE=/home/blaine/sqltool.rc
     # Set this to either 'WebServer' or 'Server'.  Defaults to Server.
     # The JVM that is started can invoke many classes (see the following item
     # about that), but this is the Server that is used (1) to check status,
     # (2) to shut down the JVM, (3) to get urlids for #1 from the 
     # server's server/webserver.properties file.
     #TARGET_CLASS=WebServer
     # Note that you don't specify the org.hsqldb package, since you have no 
     # choice in the matter (you can only run org.hsqldb.Server or 
     # org.hsqldb.WebServer).  If you specify additional classes with
     # INVOC_ADDL_ARGS (described next), you do need to specify the
     # full class name with package name.
     # This is where you specify exactly what your HSQLDB JVM will run.
     # The class org.hsqldb.util.MainInvoker will run the TARGET_CLASS
     # specified above with any arguments supplied here + any other classes
     # and arguments.  Every additional class (in addition to the TARGET_CLASS)
     # must be preceded with an empty string, so that MainInvoker will know
     # you are giving a class name.  MainInvoker will invoke the normal 
     # static main(String[]) method of each such class.  
     # By default, MainInvoker will just run TARGET_CLASS with no args.
     # Example that runs just the TARGET_CLASS with the specified arguments:
     #INVOC_ADDL_ARGS='-silent false'
     # Example that runs the TARGET_CLASS plus a WebServer:
     #INVOC_ADDL_ARGS='"" org.hsqldb.WebServer'
     # Note the empty string preceding the class name.
     # Example that starts TARGET_CLASS with an argument + a WebServer +
     # your own application with its args (i.e., the HSQLDB Servers are
     # "embedded" in your application).  (Set SERVER_ADDL_CLASSPATH too).:
     #INVOC_ADDL_ARGS='-silent false "" org.hsqldb.WebServer "" com.acme.Stone --env prod localhost'
     # Example to run a non-TLS server in same JVM with a TLS server.  In this
     # case, TARGET_CLASS is Server which will run in TLS mode by virtue of 
     # setting TLS_KEYSTORE and TLS_PASSWORD above.  The "additional" Server
     # here overrides the 'tls' and 'port' settings:
     #INVOC_ADDL_ARGS=" org.hsqldb.Server -port 9002 -tls false"
     # Note that you use nested quotes to group arguments and to specify the
     # empty-string delimiter.
     # For TLS encryption for your Server, set these two variables.
     # N.b.:  If you set these, then make this file unreadable to non-root users!!!!
     # See the TLS chapter of the HSQLDB User Guide, paying attention to the 
     # security warning(s).
     # If you are running with a private server cert, then you will also need to 
     # set "truststore" in the your SqlTool config file (location is set by the
     # AUTH_FILE variable in this file, or it must be at the default location for 
     # HSQLDB_OWNER).
     #TLS_KEYSTORE=/path/to/jks/server.store
     #TLS_PASSWORD=password
     # Any JVM args for the invocation of the JDBC client used to verify DB
     # instances and to shut them down (SqlToolSprayer).
     # This example specifies the location of a private trust store for TLS 
     # encryption.
     # For multiple args, put quotes around entire value.
     #CLIENT_JVMARGS=-Djavax.net.debug=ssl
     # Any JVM args for the server.
     # For multiple args, put quotes around entire value.
     #SERVER_JVMARGS=-Xmx512m
  3.
     Either copy HSQLDB_OWNER's sqltool.rc file into root's home directory, or set the value of AUTH_FILE to the absolute path of HSQLDB_OWNER's sqltool.rc file. This file is read (for stops) directly by root, even if you run hsqldb as non-root (by setting HSQLDB_OWNER in the config file). If you copy the file, make sure to use chmod to restrict permissions on the new copy. (The init script now enforces permissions on this file).
  4.
     Edit your server.properties file. For every server.database.X that you have defined, set a property of name server.urlid.X to the urlid for an Administrative user for that database instance.
     Example 3.1. server.properties fragment
         server.database.0=file://home/hsqldb/data/db1
         server.urlid.0=localhostdb1
     Warning
     Make sure to add a urlid for each and every database instance. If you don't then the init script will never know about databases that become inaccessible and will give false diagnostics.
     For this example, you would need to define the urlid localhostdb1 in your sqltool.rc file.
     Example 3.2. example sqltool.rc stanza
         urlid localhostdb1
         url jdbc:hsqldb:hsql://localhost
         username sa
         password secret
  5.
     Verify that the init script works.
     Just run
         /path/to/hsqldb
     as root to see the arguments you may use. Notice that you can run
         /path/to/hsqldb status
     at any time to see whether your HSQLDB Server is running.
     Re-run the script with each of the possible arguments to really test it good. If anything doesn't work right, then see the Troubleshooting the Init Script section.
  6.
     Tell your OS to run the init script upon system startup and shutdown. If you are using a UNIX variant that has /etc/rc.conf or /etc/rc.conf.local (like BSD variants and Gentoo), you must set "hsqldb_enable" to "YES" in either of those files. (Just run cd /etc; ls rc.conf rc.conf.local to see if you have one of these files). For good UNIXes that use System V style init, you must set up hard links or soft links either manually or with management tools (such as chkconfig or insserv) or Gui's (like run level editors).
     This paragraph is for Mac OS X users only. If you followed the instructions above, your init script should reside at /Library/StartupItems/hsqldb/hsqldb. Now copy the file StartupParameters.plist from the directory src/org.hsqldb/sample of your HSQLDB distribution to the same directory as the init script. As long as these two files reside in /Library/StartupItems/hsqldb, your init script is active (for portability reasons, it doesn't check for a setting in /etc/hostconfig). You can run it as a Startup Item by running
         SystemStarter {start|stop|restart} Hsqldb
     Hsqldb is the service name. See the man page for SystemStarter. To disable the init script, wipe out the /Library/StartupItems/hsqldb directory. Hard to believe, but the Mac people tell me that during system shutdown the Startup Items don't run at all. Therefore, if you don't want your data corrupted, make sure to run "SystemStarter stop Hsqldb" before shutting down your Mac.

Follow the examples in the config file to add additional classes to the server JVM's classpath and to execute additional classes in your JVM. (See the SERVER_ADDL_CLASSPATH and INVOC_ADDL_ARGS items).

Troubleshooting the Init Script

Do a ps to look for processes containing the string hsqldb, and try to connect to the database from any client. If the init script starts up your database successfully, but incorrectly reports that it has not, then your problem is with specification of urlid(s) or SqlTool setup. If your database really did not start, then skip to the next paragraph. Verify that the urlid(s) listed in the server.properties or webserver.properties are correct. and verify that you can run SqlTool as root to connect to the instances. (For the latter test, use the --rcfile switch if you are setting AUTH_FILE in the init script config file).

If your database really is not starting, then verify that you can su to the database owner account and start the database. The command su USERNAME -c ... won't work on most UNIXes unless the target user has a real login shell. Therefore, if you try to tighten up security by disabling this user's login shell, you will break the init script. If these possibilities don't pan out, then debug the init script or seek help, as described below.

To debug the init script, run it in verbose mode to see exactly what is happening (and perhaps manually run the steps that are suspect). To run an init script (in fact, any sh shell script) in verbose mode, use sh with the -x or -v switch, like

   sh -x path/to/hsqldb start

See the man page for sh if you don't know the difference between -v and -x.

If you want troubleshooting help, use the HSQLDB lists/forums or email me at blaine.simpson@admc.com. If you email me, make sure to include the revision number from your hsqldb init script (it's towards the top in the line that starts like "# $Id:"), and the output of a run of

   sh -x path/to/hsqldb start > /tmp/hstart.log 2>&1
Personal tools