1-1. We provide a cubrid script for auto start database processes.
Please get download a script file from :
http://svn.cubrid.org/websvn/filedetails.php?repname=cubridscripts&path=/cubrid_scripts/cubrid
#!/bin/bash
#
# cubrid This shell script takes care of starting and stopping
# the CUBRID service
#
# chkconfig: 2345 98 05
# description: cubrid start/stop script
#
# ts:4
### BEGIN INIT INFO
#
# Short-Description: CUBRID
# Provides: CUBRID
# Default-Start: 3 5
# Default-Stop: 0 6
### END INIT INFO
# Source function library.
. /etc/init.d/functions
# return code
CUBRID_SUCCESS=0
CUBRID_FAILED=1
US=`uname -n`
WHOAMI=`whoami`
RETVAL=0
prog=cubrid
_old_IFS=" $IFS"
### user specific environment ##################
CUBRID_USER=cubrid
if $WHOAMI = "root" ; then
CUBRID_DATABASES=`su - $CUBRID_USER -c 'printenv CUBRID_DATABASES'`
CUBRID_HOME=`su - $CUBRID_USER -c 'printenv CUBRID'`
else
CUBRID_USER=$WHOAMI
CUBRID_HOME=$CUBRID
export PATH=$PATH:$CUBRID_HOME/bin
fi
RFNAME=/tmp/.$prog.$CUBRID_USER
################################################
sudo_cubrid() {
"$#" -ne 1 && return
if $WHOAMI = "root" ; then
su - $CUBRID_USER -c "$1"
else
sh -c "$1"
fi
}
save_IFS() {
_old_IFS=" $IFS" # save $IFS
}
restore_IFS() {
if -z "$_old_IFS" # restore old $IFS
then
unset IFS
else
IFS="$_old_IFS"
fi
}
check_config()
{
# CHECK ha-mode
cubrid_conf_file=$CUBRID_HOME/conf/cubrid.conf
-r $cubrid_conf_file || exit
eval "$(sed $cubrid_conf_file -n -e 's/\(.*\)\b.*=\ *\(.*\)/\1="\2"/p')"
if $ha_mode"x" != "x" && $ha_mode = "yes" -o $ha_mode = "on" -o $ha_mode = "role-change" ; then
return $CUBRID_FAILED
fi
return $CUBRID_SUCCESS
}
service_start() {
sudo_cubrid "cubrid service start 2>&1 >$RFNAME"
grep -wqs "fail" $RFNAME
RETVAL=$?
$RETVAL -ne 0 || return $CUBRID_FAILED
return $CUBRID_SUCCESS
}
service_stop() {
sudo_cubrid "cubrid service stop 2>&1 >$RFNAME"
grep -wqs "fail" $RFNAME
RETVAL=$?
$RETVAL -ne 0 || return $CUBRID_FAILED
return $CUBRID_SUCCESS
}
service_status()
{
sudo_cubrid "cubrid service status"
}
start() {
check_config
RETVAL=$?
if $RETVAL -eq $CUBRID_SUCCESS ; then
service_start
RETVAL=$?
fi
if $RETVAL -eq $CUBRID_SUCCESS ; then
echo -n $"Starting $prog: "
success
echo
else
service_stop
echo -n $"Starting $prog: "
failure
echo
fi
$WHOAMI = "root" && touch /var/lock/subsys/$prog
}
stop() {
check_config
RETVAL=$?
if $RETVAL -eq $CUBRID_SUCCESS ; then
service_stop
RETVAL=$?
fi
if $RETVAL -eq $CUBRID_SUCCESS ; then
echo -n $"Stopping $prog: "
success
echo
else
echo -n $"Stopping $prog: "
failure
echo
fi
}
restart() {
check_config
RETVAL=$?
if $RETVAL -eq $CUBRID_SUCCESS ; then
service_stop
service_start
RETVAL=$?
fi
if $RETVAL -eq $CUBRID_SUCCESS ; then
echo -n $"Restarting $prog: "
success
echo
else
echo -n $"Restarting $prog: "
failure
echo
fi
}
status() {
check_config
RETVAL=$?
if $RETVAL -eq $CUBRID_SUCCESS ; then
service_status
RETVAL=$?
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage $0 {start|stop|restart|status}"
exit 1
esac
exit 0
1-2. Copy cubrid file into /etc/init.d/
1-3. You should modify "CUBRID_USER= " part in the file if you install CUBRID with a different user(Default username: cubrid).
### user specific environment ################## CUBRID_USER=cubrid
1-4. Grant a execution permission by a following command:
chmod a+x cubrid
1-5. Run chkconfig commans as follows:
chkconfig --add cubrid chkconfig --level 0345 cubrid on chkconfig --list | grep cubrid
1-6. If your configuration is correct, you will encounter followings on a prompt. Now your script will work on whenever your server starts-up.
cubrid 0:on 1:off 2:on 3:on 4:on 5:on 6:off
1-7. Let's see if your script works correctly.
/etc/init.d/cubrid start
CUBRID provides one more convenient feature. You can specify databases, brokers, manageer processes as CUBRID SERVICE. If so, your command "cubrid service start" or "cubrid service stop" will run each of process you specified in cubrid.conf .
To start a database process only, type the following command in the terminal. Remember that all these operations can also be performed in GUI based CUBRID Manager, if you prefer.
cubrid server start my_database
If you use particular databases very often, you may configure CUBRID to auto start them when CUBRID Server is started. The configuration file is located in $CUBRID/conf/cubrid.conf. The default locations are C:\CUBRID\conf\cubrid.conf on Windows and /opt/cubrid/conf/cubrid.conf on Linux. Find the line which is commented out like:
#server=foo,bar
Uncomment this line by removing the hash (#) sign, and instead of default foo,bar list your databases separated by commas like:
server=my_database,my_other_database
Next time you restart CUBRID Server, the configured database(s) will be automatically started for you. In fact, each database will be auto started with the same "cubrid server start" command you usually use to manually start the database.
As a side note, you should know that in order to start a database, the server process must be running (the "server" keyword in "cubrid server start" command). The server process is usually automatically started by CUBRID Service upon "cubrid service start". To make this sure, check if "server" keyword is listed in the following line in the same cubrid.conf configuration file.
service=server,broker,manager