root@RTPProxy:/usr/local/opensips_proxy/sbin# vim opensipsdbctl
opensipsctlrc文件中包含数据库配置的信息,要想让opensips支持mysql数据库,在编译安装的时候就要支持mysql模块:
方法如下:
1、修改opensips中的Makefile.conf,在exclude_modules中去掉db_mysql,在include_modules中添加db_mysql,然后重新编译安装。要添加支持的模块都可以这样操作。
2、编译时指定,make include_modules=”db_mysql” modules prefix=/ 。
在编译安装之前,需要安装mysql的开发包,要不编译通不过。
$sudo apt-get install libmysqlclient-dev。
#!/bin/sh
#
# $Id$
#
# opensips control tool for maintaining opensips databases
#
#===================================================================
PATH=$PATH:/usr/local/opensips_proxy//sbin//
# for testing only, please don't enable this in production environments
# as this introduce security risks
TEST="false"
### include resource files, if any
if [ -f /etc/opensips/opensipsctlrc ]; then
. /etc/opensips/opensipsctlrc
fi
if [ -f /usr/local/opensips_proxy//etc/opensips//opensipsctlrc ]; then
. /usr/local/opensips_proxy//etc/opensips//opensipsctlrc
fi
if [ -f ~/.opensipsctlrc ]; then
. ~/.opensipsctlrc
fi
if [ $TEST = "true" ]; then
if [ -f ./opensipsctlrc ]; then
. ./opensipsctlrc
elif [ -f scripts/opensipsctlrc ]; then
. scripts/opensipsctlrc
fi
fi
if [ -z $SHELL_TESTED ] && [ -z $NOHLPRINT ] ; then
if [ -x /bin/bash ]; then
# bash is available
export SHELL_TESTED=yes
exec /bin/bash $0 $@
else
NOHLPRINT=yes
fi
fi
### version for this script
VERSION='$Revision: 3997 $'
if [ -z "$MYDIR" ] ; then
MYDIR=`dirname $0`
fi
if [ -z "$MYLIBDIR" ] ; then
MYLIBDIR="/usr/local/opensips_proxy//lib64/opensips/opensipsctl"
if [ ! -d "$MYLIBDIR" ]; then
MYLIBDIR=$MYDIR
fi
fi
##### ------------------------------------------------ #####
if [ -f "$MYLIBDIR/opensipsdbctl.base" ]; then
. "$MYLIBDIR/opensipsdbctl.base"
else
echo -e "Cannot load core functions '$MYLIBDIR/opensipsdbctl.base' - exiting ...\n"
exit -1
fi
### DBENGINE
#
unset USED_DBENGINE
if [ -z "$DBENGINE" ] ; then
merr "database engine not specified, please setup one in the config script"
exit 1
fi
MYSQL|mysql|MySQL)
if [ -f "$MYLIBDIR/opensipsdbctl.mysql" ]; then
. "$MYLIBDIR/opensipsdbctl.mysql"
USED_DBENGINE="mysql"
else
fi
if [ -f "$MYLIBDIR/opensipsdbctl.pgsql" ]; then
. "$MYLIBDIR/opensipsdbctl.pgsql"
USED_DBENGINE="postgres"
else
fi
;;
. "$MYLIBDIR/opensipsdbctl.oracle"
USED_DBENGINE="oracle"
else
fi
;;
DBTEXT|dbtext|textdb)
if [ -f "$MYLIBDIR/opensipsdbctl.dbtext" ]; then
. "$MYLIBDIR/opensipsdbctl.dbtext"
USED_DBENGINE="dbtext"
DBNAME=$DB_PATH
else
fi
;;
DB_BERKELEY|db_berkeley|BERKELEY|berkeley)
if [ -f "$MYLIBDIR/opensipsdbctl.db_berkeley" ]; then
. "$MYLIBDIR/opensipsdbctl.db_berkeley"
USED_DBENGINE="berkeley"
DBNAME=$DB_PATH
else
fi
;;
esac
if [ -z "$USED_DBENGINE" ] ; then
merr "database engine not loaded - tried '$DBENGINE'"
exit 1
else
mdbg "database engine '$USED_DBENGINE' loaded"
fi
# dump all rows
opensips_dump() # pars: <database name>
{
if [ $# -ne 2 ] ; then
merr "opensips_dump function takes two param"
exit 1
fi
if [ "$USED_DBENGINE" = "oracle" ]; then
oracle_dump $1 $2
elif [ "$PW" = "" ] ; then
$DUMP_CMD $1 > $2
else
$DUMP_CMD "-p$PW" $1 > $2
fi
if [ "$?" -ne 0 ]; then
merr "db dump failed"
exit 1
fi
minfo "db dump successful"
}
opensips_restore() #pars: <database name> <filename>
{
if [ $# -ne 2 ] ; then
merr "opensips_restore function takes two params"
exit 1
fi
if [ "$USED_DBENGINE" = "oracle" ]; then
oracle_restore $1 $2
else
sql_query $1 < $2
fi
if [ "$?" -ne 0 ]; then
merr "db restore failed"
exit 1
fi
minfo "db restore successful"
}
opensips_pframework_create() #pars: none
{
if [ "$ANSWER" != "y" ]; then
exit 1
fi
fi
touch $DEFAULT_CFG_DIR/pi_framework_sample
if [ $? -ne 0 ] ; then
merr "Unable to create $DEFAULT_CFG_DIR/pi_framework_sample"
exit 1
fi
if [ -d "$DATA_DIR/pi_http" ] ; then
PI_MODULES="$STANDARD_MODULES"
else
merr "Please install first the pi_http module"
exit 1
fi
get_answer $INSTALL_EXTRA_TABLES "Add provisionning framework for extra tables? (y/n): "
if [ "$ANSWER" = "y" ]; then
PI_MODULES="$PI_MODULES $EXTRA_MODULES"
fi
if [ "$ANSWER" = "y" ]; then
PI_PRESENCE_MODULES="TRUE"
fi
cat $DATA_DIR/pi_http/pi_framework-00 > $DEFAULT_CFG_DIR/pi_framework_sample
for TABLE in $PI_MODULES; do
if [ -e $DATA_DIR/pi_http/$TABLE-table ]; then
cat $DATA_DIR/pi_http/$TABLE-table >> $DEFAULT_CFG_DIR/pi_framework_sample
else
merr "Unable to configure: $TABLE - missing table descriptor"
fi
done
if [ "$PI_PRESENCE_MODULES" = "TRUE" ]; then
if [ -e $DATA_DIR/pi_http/presence-table ]; then
cat $DATA_DIR/pi_http/presence-table >> $DEFAULT_CFG_DIR/pi_framework_sample
else
merr "Unable to configure: presence - missing table descriptor"
fi
if [ -e $DATA_DIR/pi_http/rls-table ]; then
cat $DATA_DIR/pi_http/rls-table >> $DEFAULT_CFG_DIR/pi_framework_sample
else
merr "Unable to configure: rls - missing table descriptor"
fi
fi
cat $DATA_DIR/pi_http/pi_framework-01 >> $DEFAULT_CFG_DIR/pi_framework_sample
for TABLE in $PI_MODULES; do
if [ -e $DATA_DIR/pi_http/$TABLE-mod ]; then
cat $DATA_DIR/pi_http/$TABLE-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
else
merr "Unable to configure: $TABLE - missing mod descriptor"
fi
done
if [ "$PI_PRESENCE_MODULES" = "TRUE" ]; then
if [ -e $DATA_DIR/pi_http/presence-mod ]; then
cat $DATA_DIR/pi_http/presence-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
else
merr "Unable to configure: presence - missing mod descriptor"
fi
if [ -e $DATA_DIR/pi_http/rls-mod ]; then
cat $DATA_DIR/pi_http/rls-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
else
merr "Unable to configure: rls - missing mod descriptor"
fi
fi
cat $DATA_DIR/pi_http/pi_framework-02 >> $DEFAULT_CFG_DIR/pi_framework_sample
minfo "Sample provisionning framework saved as: $DEFAULT_CFG_DIR/pi_framework_sample"
}
opensips_pframework() #pars: <action>
{
if [ $# -ne 1 ] ; then
merr "opensips_pframework function takes one parameter"
exit 1
fi
case $1 in
create)
shift
opensips_pframework_create "$@"
exit $?
;;
*)
merr "Unexpected pframework action: $1"
;;
esac
}
case $1 in
migrate)
if [ "$USED_DBENGINE" != "mysql" ] ; then
merr "The \"$1\" operation is not supported for $USED_DBENGINE (MYSQL only)"
exit 1
fi
minfo "MySQL DB migration tool for OpenSIPS 1.11.x databases\n\
----------------------------------------------------------------------"
mwarn "\
We recommend using this tool ONLY in order to upgrade an existing\n\
OpenSIPS 1.11.x MySQL database to 2.1 schema. Behaviour when automatically\n\
migrating earlier DB versions (1.8, 1.9, 1.10) to 2.1 is undefined"
read -p"Do you wish to continue? (y/N) " ANS
[ "$ANS" != "y" -a "$ANS" != "Y" ] && exit 1
if [ $# -ne 3 ] ; then
exit 1
fi
# create new database
minfo "Creating new database \"$3\" ..."
NO_USER_INIT="yes"
opensips_create $3
if [ "$?" -ne 0 ] ; then
echo "migrate: creating new database failed"
exit 1
fi
# migrate data
minfo "Migrating data from \"$2\" to \"$3\" ..."
migrate_db $2 $3
minfo "Migration successfully completed."
exit 0;
;;
copy)
# copy database to some other name
if [ "$USED_DBENGINE" = "berkeley" -o "$USED_DBENGINE" = "dbtext" ] ; then
merr "$USED_DBENGINE don't support this operation"
exit 1
fi
shift
if [ $# -ne 1 ]; then
usage
exit 1
fi
tmp_file=`mktemp /tmp/opensipsdbctl.XXXXXXXXXX` || exit 1
opensips_dump $DBNAME $tmp_file
ret=$?
if [ "$ret" -ne 0 ]; then
rm $tmp_file
exit $ret
fi
NO_USER_INIT="yes"
opensips_create $1
ret=$?
if [ "$ret" -ne 0 ]; then
rm $tmp_file
exit $ret
fi
opensips_restore $1 $tmp_file
ret=$?
rm -f $tmp_file
exit $ret
;;
backup)
if [ "$USED_DBENGINE" = "berkeley" -o "$USED_DBENGINE" = "dbtext" ] ; then
merr "$USED_DBENGINE don't support this operation"
exit 1
fi
# backup current database
shift
if [ $# -ne 1 ]; then
usage
exit 1
fi
opensips_dump $DBNAME $1
exit $?
;;
restore)
if [ "$USED_DBENGINE" = "berkeley" -o "$USED_DBENGINE" = "dbtext" ] ; then
merr "$USED_DBENGINE don't support this operation"
exit 1
fi
# restore database from a backup
shift
if [ $# -ne 1 ]; then
usage
exit 1
fi
opensips_restore $DBNAME $1
exit $?
;;
create)
# create new database structures
shift
if [ $# -eq 1 ] ; then
DBNAME="$1"
fi
opensips_create $DBNAME
exit $?
;;
presence)
presence_create $DBNAME
exit $?
;;
extra)
extra_create $DBNAME
exit $?
;;
drop)
# delete opensips database
# create new database structures
shift
if [ $# -eq 1 ] ; then
DBNAME="$1"
fi
opensips_drop $DBNAME
exit $?
;;
reinit)
# delete database and create a new one
# create new database structures
shift
if [ $# -eq 1 ] ; then
DBNAME="$1"
fi
opensips_drop $DBNAME
ret=$?
if [ "$ret" -ne 0 ]; then
exit $ret
fi
opensips_create $DBNAME
exit $?
;;
bdb|db_berkeley)
shift
opensips_berkeley "$@"
exit $?
;;
pframework)
shift
opensips_pframework "$@"
exit $?
;;
version)
echo "$0 $VERSION"
;;
*)
merr "$0: Uknown command - \"$1\""
usage
exit 1;
;;
esac