LucidDbAsDaemonService
Contents |
Introduction
LucidDB is a hybrid application consisting of Java (LucidDB) and C++ pieces (Fennel & Farrago), running it as a service involves either using a bash script or a Java Service Wrapper to cause the Java piece of LucidDB to load, which will cause the C++ piece to engage.
There are two methods of accomplishing running LucidDB as a daemon in Linux. There may be more than one method for doing this in Windows, but the most obvious one would be to use a java service wrapper which takes care of the startup and shutdown of the java application at the right times. The easiest way of running LucidDB as a service/daemon on Linux is by using Method 1. Method 2 presents an example configuration using Tanuki Software's Java Service Wrapper [Corporate Home Page]. This can be accomplished using the free version of their software.
Method 1 - Bash Script - Easy
Introduction
When you run the script that will be created, it gives off zero communication on screen. The ampersand character is critical to telling the script to background the process execution. To shutdown the server after starting it via script is to connect to it as sa (system administrator) and issue a command to tell LucidDB to shut down. See the section [[1]]
Procedure
Create a script called $LUCIDDB_HOME/bin/lucidDbServerDaemon with the following content:
#!/bin/sh
BIN_DIR=$(cd `dirname $0`; pwd)
. $BIN_DIR/defineFarragoRuntime.sh
# 1. close stdin - LucidDbServer will interpet it as "run in daemon mode"
# 2. run LucidDbServer in the background thus making it a real daemon
${JAVA_EXEC} ${JAVA_ARGS} org.luciddb.session.LucidDbServer >&- <&- 2>&-
When you run the above script, you will see no output at all. To run it and return to a terminal prompt, you will type the following:
./lucidDbServerDaemon &
Making LucidDB start at boot
You can add a line to the file /etc/rc.local that executes the script just created in the previous step. Your file may look something like this when finished.
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. su www-data -c "/opt/lucid/bin/lucidDbServerDaemon" exit 0
Source of inspiration for the above script.
Method 2 - Java Service Wrapper - Harder
Introduction
The appeal of the Java Service Wrapper approach is that it is available on other operating systems, especially Microsoft Windows.
C:\luciddb-0.9.4\bin\classpath.genwhich appears for you right after you run the command
C:\luciddb-0.9.4\install\install.batIt is advised to avoid spaces in directory and filenames.
Procedure
A video of the procedure of setting up LucidDB to use the wrapper is here: [Installing LucidDB as a daemon in Linux].
Most of the video above are applicable to MS Windows for the actual configuration of the Java Service Wrapper. Making the service wrapper itself run under windows is not shown in the video, but should be fairly straightforward. Tanuki's documentation is strong in this area.
Information on how to set up LucidDB to run as a service on Windows or daemon on Unix can be found in this mailing list post. This post inspired the video presented above.
Shutting Down The Server
Once LucidDB is running as a daemon, there is no familiar !quit command that can be issued to the server piece. To stop the server, you simply connect with a SQL client and issue the command:
-- kill sessions and shut down JVM after 5 seconds call sys_root.shutdown_database(true, 5000);
This will tell Lucid to shut down in 5 seconds after the command is executed. More information about this command can be found at LucidDbSysRoot_SHUTDOWN_DATABASE which is in a subtopic called System Procedures located here LucidDbSystemProcedures.
External Information Resources Consulted
Bash Tip: Closing File Descriptors
Bash Tip: Closing File Descriptors - Blog Article
Posted by apokalyptik on Wednesday, October 24th, 2007 at 5:05 PM
Last accessed to update this page: Sept 27, 2011 at permalink [3]
Below see the content directly taken from the site mentioned above which talks about the syntax of "closing stdin" and expounds on these concepts.
I recently found that you can close bash file descriptors fairly easily, it goes like this:
exec 0>&- # close stdin exec 1>&- # close stdout exec 2>&- # close stderr
Which makes it easy to daemonize things using only bash (lets face it there are times when you JUST don’t need anything more than a simple bash script, you just need it backgrounded/daemonized). Take this example of a daemon that copies any new files created in a directory to another place on the filesystem
#!/bin/bash
##
## Shell Daemon For: Backup /root/
## (poorly coded, quick and dirty, example)
##
PIDFILE="/var/run/rootmirror.pid"
LOGFILE="/log/log/rootmirror-%Y-%m-%d.log"
NOHUP="/usr/bin/nohup"
CRONOLOG="/usr/bin/cronolog"
case $1 in
start)
exec 0>&- # close stdin
exec 1>&- # close stdout
exec 2>&- # close stderr
$NOHUP $0 run | $CRONOLOG $LOGFILE >> /dev/null &
;;
stop)
/bin/kill $(cat $PIDFILE)
;;
run)
pgrep -f "$0 $1" > $PIDFILE
while [ true ]; do
event=$(inotifywait -q -e close_write --format "%f" /root/)
( cp -v "/root/$event" "/var/lib/rootmirror/$event" )&
done
;;
*)
echo "$0 [ start | stop ]"
exit 0
;;
esac
One especially nice detail here is that this wont hang while exiting your SSH session after you start it up (a big pet peeve of mine).