Add Drone CI

This commit is contained in:
arberkatellari
2023-09-01 11:22:23 -04:00
committed by Dan Christian Bogos
parent 870b6e87ae
commit 05ede32f0f
28 changed files with 3476 additions and 0 deletions

View File

@@ -0,0 +1,356 @@
#!/bin/bash
set -eo pipefail
shopt -s nullglob
# logging functions
mysql_log() {
# return
local type="$1"; shift
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
}
mysql_note() {
mysql_log Note "$@"
}
mysql_warn() {
mysql_log Warn "$@" >&2
}
mysql_error() {
mysql_log ERROR "$@" >&2
exit 1
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
mysql_error "Both $var and $fileVar are set (but are exclusive)"
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# check to see if this file is being run or sourced from another script
_is_sourced() {
# https://unix.stackexchange.com/a/215279
[ "${#FUNCNAME[@]}" -ge 2 ] \
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
&& [ "${FUNCNAME[1]}" = 'source' ]
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
# process initializer files, based on file extensions
docker_process_init_files() {
# mysql here for backwards compatibility "${mysql[@]}"
mysql=( docker_process_sql )
echo
local f
for f; do
case "$f" in
*.sh)
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then
mysql_note "$0: running $f"
"$f"
else
mysql_note "$0: sourcing $f"
. "$f"
fi
;;
*.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;;
*.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;;
*.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;;
*) mysql_warn "$0: ignoring $f" ;;
esac
echo
done
}
mysql_check_config() {
local toRun=( "$@" --verbose --help --log-bin-index="$(mktemp -u)" ) errors
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors"
fi
}
# Fetch value from server config
# We use mysqld --verbose --help instead of my_print_defaults because the
# latter only show values present in config files, and not server defaults
mysql_get_config() {
local conf="$1"; shift
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null \
| awk -v conf="$conf" '$1 == conf && /^[^ \t]/ { sub(/^[^ \t]+[ \t]+/, ""); print; exit }'
# match "datadir /some/path with/spaces in/it here" but not "--xyz=abc\n datadir (xyz)"
}
# Do a temporary startup of the MySQL server, for init purposes
docker_temp_server_start() {
"$@" --skip-networking --socket="${SOCKET}" &
mysql_note "Waiting for server startup"
local i
for i in {30..0}; do
# only use the root password if the database has already been initializaed
# so that it won't try to fill in a password file when it hasn't been set yet
extraArgs=()
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
extraArgs+=( '--dont-use-mysql-root-password' )
fi
if docker_process_sql "${extraArgs[@]}" --database=mysql <<<'SELECT 1' &> /dev/null; then
break
fi
sleep 1
done
if [ "$i" = 0 ]; then
mysql_error "Unable to start server."
fi
}
# Stop the server. When using a local socket file mysqladmin will block until
# the shutdown is complete.
docker_temp_server_stop() {
if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then
mysql_error "Unable to shut down server."
fi
}
# Verify that the minimally required password settings are set for new databases.
docker_verify_minimum_env() {
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
mysql_error $'Database is uninitialized and password option is not specified\n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
fi
}
# creates folders for the database
# also ensures permission for user mysql of run as root
docker_create_db_directories() {
local user; user="$(id -u)"
# TODO other directories that are used by default? like /var/lib/mysql-files
# see https://github.com/docker-library/mysql/issues/562
mkdir -p "$DATADIR"
if [ "$user" = "0" ]; then
# this will cause less disk access than `chown -R`
find "$DATADIR" \! -user mysql -exec chown mysql '{}' +
fi
}
# initializes the database directory
docker_init_database_dir() {
mysql_note "Initializing database files"
installArgs=( --datadir="$DATADIR" --rpm --auth-root-authentication-method=normal )
if { mysql_install_db --help || :; } | grep -q -- '--skip-test-db'; then
# 10.3+
installArgs+=( --skip-test-db )
fi
# "Other options are passed to mysqld." (so we pass all "mysqld" arguments directly here)
mysql_install_db "${installArgs[@]}" "${@:2}"
mysql_note "Database files initialized"
}
# Loads various settings that are used elsewhere in the script
# This should be called after mysql_check_config, but before any other functions
docker_setup_env() {
# Get config
declare -g DATADIR SOCKET
DATADIR="$(mysql_get_config 'datadir' "$@")"
SOCKET="$(mysql_get_config 'socket' "$@")"
# Initialize values that might be stored in a file
file_env 'MYSQL_ROOT_HOST' '%'
file_env 'MYSQL_DATABASE'
file_env 'MYSQL_USER'
file_env 'MYSQL_PASSWORD'
file_env 'MYSQL_ROOT_PASSWORD'
declare -g DATABASE_ALREADY_EXISTS
if [ -d "$DATADIR/mysql" ]; then
DATABASE_ALREADY_EXISTS='true'
fi
}
# Execute sql script, passed via stdin
# usage: docker_process_sql [--dont-use-mysql-root-password] [mysql-cli-args]
# ie: docker_process_sql --database=mydb <<<'INSERT ...'
# ie: docker_process_sql --dont-use-mysql-root-password --database=mydb <my-file.sql
docker_process_sql() {
passfileArgs=()
if [ '--dont-use-mysql-root-password' = "$1" ]; then
passfileArgs+=( "$1" )
shift
fi
# args sent in can override this db, since they will be later in the command
if [ -n "$MYSQL_DATABASE" ]; then
set -- --database="$MYSQL_DATABASE" "$@"
fi
mysql --defaults-extra-file=<( _mysql_passfile "${passfileArgs[@]}") --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" "$@"
}
# Initializes database with timezone info and root password, plus optional extra db/user
docker_setup_db() {
# Load timezone info into database
if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
{
# Aria in 10.4+ is slow due to "transactional" (crash safety)
# https://jira.mariadb.org/browse/MDEV-23326
# https://github.com/docker-library/mariadb/issues/262
local tztables=( time_zone time_zone_leap_second time_zone_name time_zone_transition time_zone_transition_type )
for table in "${tztables[@]}"; do
echo "/*!100400 ALTER TABLE $table TRANSACTIONAL=0 */;"
done
# sed is for https://bugs.mysql.com/bug.php?id=20545
mysql_tzinfo_to_sql /usr/share/zoneinfo \
| sed 's/Local time zone must be set--see zic manual page/FCTY/'
for table in "${tztables[@]}"; do
echo "/*!100400 ALTER TABLE $table TRANSACTIONAL=1 */;"
done
} | docker_process_sql --dont-use-mysql-root-password --database=mysql
# tell docker_process_sql to not use MYSQL_ROOT_PASSWORD since it is not set yet
fi
# Generate random root password
if [ -n "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
mysql_note "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
fi
# Sets root password and creates root users for non-localhost hosts
local rootCreate=
# default root to listen for connections from anywhere
if [ -n "$MYSQL_ROOT_HOST" ] && [ "$MYSQL_ROOT_HOST" != 'localhost' ]; then
# no, we don't care if read finds a terminating character in this heredoc
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151
read -r -d '' rootCreate <<-EOSQL || true
CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
GRANT ALL ON *.* TO 'root'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
EOSQL
fi
# tell docker_process_sql to not use MYSQL_ROOT_PASSWORD since it is just now being set
docker_process_sql --dont-use-mysql-root-password --database=mysql <<-EOSQL
-- What's done in this file shouldn't be replicated
-- or products like mysql-fabric won't work
SET @@SESSION.SQL_LOG_BIN=0;
DELETE FROM mysql.user WHERE user NOT IN ('mysql.sys', 'mariadb.sys', 'mysqlxsys', 'root') OR host NOT IN ('localhost') ;
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASSWORD}') ;
-- 10.1: https://github.com/MariaDB/server/blob/d925aec1c10cebf6c34825a7de50afe4e630aff4/scripts/mysql_secure_installation.sh#L347-L365
-- 10.5: https://github.com/MariaDB/server/blob/00c3a28820c67c37ebbca72691f4897b57f2eed5/scripts/mysql_secure_installation.sh#L351-L369
DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%' ;
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ;
FLUSH PRIVILEGES ;
${rootCreate}
DROP DATABASE IF EXISTS test ;
EOSQL
# Creates a custom database and user if specified
if [ -n "$MYSQL_DATABASE" ]; then
mysql_note "Creating database ${MYSQL_DATABASE}"
docker_process_sql --database=mysql <<<"CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;"
fi
if [ -n "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ]; then
mysql_note "Creating user ${MYSQL_USER}"
docker_process_sql --database=mysql <<<"CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;"
if [ -n "$MYSQL_DATABASE" ]; then
mysql_note "Giving user ${MYSQL_USER} access to schema ${MYSQL_DATABASE}"
docker_process_sql --database=mysql <<<"GRANT ALL ON \`${MYSQL_DATABASE//_/\\_}\`.* TO '$MYSQL_USER'@'%' ;"
fi
fi
}
_mysql_passfile() {
# echo the password to the "file" the client uses
# the client command will use process substitution to create a file on the fly
# ie: --defaults-extra-file=<( _mysql_passfile )
if [ '--dont-use-mysql-root-password' != "$1" ] && [ -n "$MYSQL_ROOT_PASSWORD" ]; then
cat <<-EOF
[client]
password="${MYSQL_ROOT_PASSWORD}"
EOF
fi
}
# check arguments for an option that would cause mysqld to stop
# return true if there is one
_mysql_want_help() {
local arg
for arg; do
case "$arg" in
-'?'|--help|--print-defaults|-V|--version)
return 0
;;
esac
done
return 1
}
_main() {
# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
set -- mysqld "$@"
fi
# skip setup if they aren't running mysqld or want an option that stops mysqld
if [ "$1" = 'mysqld' ] && ! _mysql_want_help "$@"; then
mysql_note "Entrypoint script for MySQL Server ${MARIADB_VERSION} started."
mysql_check_config "$@"
# Load various environment variables
docker_setup_env "$@"
docker_create_db_directories
# If container is started as root user, restart as dedicated mysql user
if [ "$(id -u)" = "0" ]; then
mysql_note "Switching to dedicated user 'mysql'"
exec gosu mysql "$BASH_SOURCE" "$@"
fi
# there's no database, so it needs to be initialized
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
# check dir permissions to reduce likelihood of half-initialized database
# ls /docker-entrypoint-initdb.d/ > /dev/null
docker_init_database_dir "$@"
mysql_note "Starting temporary server"
docker_temp_server_start "$@"
mysql_note "Temporary server started."
docker_setup_db
# docker_process_init_files /docker-entrypoint-initdb.d/*
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
echo
mysql_note "MySQL init process done. Ready for start up."
echo
fi
fi
exec "$@" > /logs/mariadb.log 2>&1 &
}
# If we are sourced from elsewhere, don't perform any further actions
if ! _is_sourced; then
_main "$@"
fi

View File

@@ -0,0 +1,9 @@
db = db.getSiblingDB('cgrates')
db.createUser(
{
user: "cgrates",
pwd: "CGRateS.org",
roles: [ { role: "dbAdmin", db: "cgrates" } ]
}
)

View File

@@ -0,0 +1,14 @@
#! /usr/bin/env sh
mongo --quiet create_user.js
cu=$?
if [ $cu = 0 ]; then
echo ""
echo "\t+++ CGR-DB successfully set-up! +++"
echo ""
exit 0
fi

View File

@@ -0,0 +1,50 @@
USE `cgrates`;
ALTER TABLE `cdrs_primary`
CHANGE COLUMN tbid `id` int(11) NOT NULL auto_increment first ,
CHANGE `cgrid` `cgrid` char(40) NOT NULL after `id` ,
ADD COLUMN `pdd` decimal(12,9) NOT NULL after `setup_time` ,
CHANGE `answer_time` `answer_time` datetime NULL after `pdd` ,
ADD COLUMN `supplier` varchar(128) NOT NULL after `usage` ,
ADD COLUMN `disconnect_cause` varchar(64) NOT NULL after `supplier` ,
ADD COLUMN `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP after `disconnect_cause` ,
ADD COLUMN `deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' after `created_at` ,
ADD KEY `answer_time_idx`(`answer_time`) ,
ADD KEY `deleted_at_idx`(`deleted_at`) ,
DROP KEY `PRIMARY`, ADD PRIMARY KEY(`id`) ;
ALTER TABLE `cdrs_extra`
CHANGE COLUMN tbid `id` int(11) NOT NULL auto_increment first ,
CHANGE `cgrid` `cgrid` char(40) NOT NULL after `id` ,
ADD COLUMN `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP after `extra_fields` ,
ADD COLUMN `deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' after `created_at`,
ADD UNIQUE KEY `cgrid`(`cgrid`) ,
ADD KEY `deleted_at_idx`(`deleted_at`) ,
DROP KEY `PRIMARY`, ADD PRIMARY KEY(`id`) ;
ALTER TABLE `cost_details`
CHANGE COLUMN tbid `id` int(11) NOT NULL auto_increment first ,
CHANGE `cost_source` `cost_source` varchar(64) NOT NULL after `timespans` ,
ADD COLUMN `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP after `cost_source` ,
ADD COLUMN `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' after `created_at` ,
ADD COLUMN `deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' after `updated_at` ,
DROP COLUMN `cost_time` ,
ADD KEY `deleted_at_idx`(`deleted_at`) ,
DROP KEY `PRIMARY`, ADD PRIMARY KEY(`id`) ;
ALTER TABLE `rated_cdrs`
CHANGE COLUMN tbid `id` int(11) NOT NULL auto_increment first ,
CHANGE `cgrid` `cgrid` char(40) NOT NULL after `id` ,
CHANGE `category` `category` varchar(32) NOT NULL after `tenant` ,
ADD COLUMN `pdd` decimal(12,9) NOT NULL after `setup_time` ,
CHANGE `answer_time` `answer_time` datetime NULL after `pdd` ,
ADD COLUMN `supplier` varchar(128) NOT NULL after `usage` ,
ADD COLUMN `disconnect_cause` varchar(64) NOT NULL after `supplier` ,
CHANGE `cost` `cost` decimal(20,4) NULL after `disconnect_cause` ,
ADD COLUMN `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP after `extra_info` ,
ADD COLUMN `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' after `created_at` ,
ADD COLUMN `deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' after `updated_at` ,
DROP COLUMN `mediation_time` ,
ADD KEY `deleted_at_idx`(`deleted_at`) ,
DROP KEY `PRIMARY`, ADD PRIMARY KEY(`id`) ;

View File

@@ -0,0 +1,52 @@
--
-- Table structure for table `cdrs`
--
DROP TABLE IF EXISTS cdrs;
CREATE TABLE cdrs (
id int(11) NOT NULL AUTO_INCREMENT,
cgrid varchar(40) NOT NULL,
run_id varchar(64) NOT NULL,
origin_host varchar(64) NOT NULL,
source varchar(64) NOT NULL,
origin_id varchar(128) NOT NULL,
tor varchar(16) NOT NULL,
request_type varchar(24) NOT NULL,
tenant varchar(64) NOT NULL,
category varchar(64) NOT NULL,
account varchar(128) NOT NULL,
subject varchar(128) NOT NULL,
destination varchar(128) NOT NULL,
setup_time datetime NOT NULL,
answer_time datetime NULL,
`usage` BIGINT NOT NULL,
extra_fields text NOT NULL,
cost_source varchar(64) NOT NULL,
cost DECIMAL(20,4) NOT NULL,
cost_details MEDIUMTEXT,
extra_info text,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
deleted_at TIMESTAMP NULL,
PRIMARY KEY (id),
UNIQUE KEY cdrrun (cgrid, run_id)
);
DROP TABLE IF EXISTS session_costs;
CREATE TABLE session_costs (
id int(11) NOT NULL AUTO_INCREMENT,
cgrid varchar(40) NOT NULL,
run_id varchar(64) NOT NULL,
origin_host varchar(64) NOT NULL,
origin_id varchar(128) NOT NULL,
cost_source varchar(64) NOT NULL,
`usage` BIGINT NOT NULL,
cost_details MEDIUMTEXT,
created_at TIMESTAMP NULL,
deleted_at TIMESTAMP NULL,
PRIMARY KEY (`id`),
UNIQUE KEY costid (cgrid, run_id),
KEY origin_idx (origin_host, origin_id),
KEY run_origin_idx (run_id, origin_id),
KEY deleted_at_idx (deleted_at)
);

View File

@@ -0,0 +1,10 @@
--
-- Sample db and users creation. Replace here with your own details
--
DROP DATABASE IF EXISTS cgrates;
CREATE DATABASE cgrates;
CREATE USER IF NOT EXISTS 'cgrates'@'localhost' IDENTIFIED BY 'CGRateS.org';
GRANT ALL PRIVILEGES ON cgrates.* TO 'cgrates'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

View File

@@ -0,0 +1,7 @@
--
-- extra DB for ees and ers
DROP DATABASE IF EXISTS cgrates2;
CREATE DATABASE cgrates2;
GRANT ALL on cgrates2.* TO 'cgrates'@'localhost' IDENTIFIED BY 'CGRateS.org';

View File

@@ -0,0 +1,491 @@
--
-- Table structure for table `tp_timings`
--
DROP TABLE IF EXISTS `tp_timings`;
CREATE TABLE `tp_timings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`years` varchar(255) NOT NULL,
`months` varchar(255) NOT NULL,
`month_days` varchar(255) NOT NULL,
`week_days` varchar(255) NOT NULL,
`time` varchar(32) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
KEY `tpid_tmid` (`tpid`,`tag`),
UNIQUE KEY `tpid_tag` (`tpid`,`tag`)
);
--
-- Table structure for table `tp_destinations`
--
DROP TABLE IF EXISTS `tp_destinations`;
CREATE TABLE `tp_destinations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`prefix` varchar(24) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
KEY `tpid_dstid` (`tpid`,`tag`),
UNIQUE KEY `tpid_dest_prefix` (`tpid`,`tag`,`prefix`)
);
--
-- Table structure for table `tp_rates`
--
DROP TABLE IF EXISTS `tp_rates`;
CREATE TABLE `tp_rates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`connect_fee` decimal(7,4) NOT NULL,
`rate` decimal(10,4) NOT NULL,
`rate_unit` varchar(16) NOT NULL,
`rate_increment` varchar(16) NOT NULL,
`group_interval_start` varchar(16) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_tprate` (`tpid`,`tag`,`group_interval_start`),
KEY `tpid` (`tpid`),
KEY `tpid_rtid` (`tpid`,`tag`)
);
--
-- Table structure for table `destination_rates`
--
DROP TABLE IF EXISTS `tp_destination_rates`;
CREATE TABLE `tp_destination_rates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`destinations_tag` varchar(64) NOT NULL,
`rates_tag` varchar(64) NOT NULL,
`rounding_method` varchar(255) NOT NULL,
`rounding_decimals` tinyint(4) NOT NULL,
`max_cost` decimal(7,4) NOT NULL,
`max_cost_strategy` varchar(16) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
KEY `tpid_drid` (`tpid`,`tag`),
UNIQUE KEY `tpid_drid_dstid` (`tpid`,`tag`,`destinations_tag`)
);
--
-- Table structure for table `tp_rating_plans`
--
DROP TABLE IF EXISTS `tp_rating_plans`;
CREATE TABLE `tp_rating_plans` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`destrates_tag` varchar(64) NOT NULL,
`timing_tag` varchar(64) NOT NULL,
`weight` DECIMAL(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
KEY `tpid_rpl` (`tpid`,`tag`),
UNIQUE KEY `tpid_rplid_destrates_timings_weight` (`tpid`,`tag`,`destrates_tag`,`timing_tag`)
);
--
-- Table structure for table `tp_rate_profiles`
--
DROP TABLE IF EXISTS `tp_rating_profiles`;
CREATE TABLE `tp_rating_profiles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`loadid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`category` varchar(32) NOT NULL,
`subject` varchar(64) NOT NULL,
`activation_time` varchar(26) NOT NULL,
`rating_plan_tag` varchar(64) NOT NULL,
`fallback_subjects` varchar(64),
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
KEY `tpid_loadid` (`tpid`, `loadid`),
UNIQUE KEY `tpid_loadid_tenant_category_subj_atime` (`tpid`,`loadid`, `tenant`,`category`,`subject`,`activation_time`)
);
--
-- Table structure for table `tp_shared_groups`
--
DROP TABLE IF EXISTS `tp_shared_groups`;
CREATE TABLE `tp_shared_groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`account` varchar(64) NOT NULL,
`strategy` varchar(24) NOT NULL,
`rating_subject` varchar(24) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_shared_group` (`tpid`,`tag`,`account`,`strategy`,`rating_subject`)
);
--
-- Table structure for table `tp_actions`
--
DROP TABLE IF EXISTS `tp_actions`;
CREATE TABLE `tp_actions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`action` varchar(24) NOT NULL,
`extra_parameters` varchar(256) NOT NULL,
`filters` varchar(256) NOT NULL,
`balance_tag` varchar(64) NOT NULL,
`balance_type` varchar(24) NOT NULL,
`categories` varchar(32) NOT NULL,
`destination_tags` varchar(64) NOT NULL,
`rating_subject` varchar(64) NOT NULL,
`shared_groups` varchar(64) NOT NULL,
`expiry_time` varchar(26) NOT NULL,
`timing_tags` varchar(128) NOT NULL,
`units` varchar(256) NOT NULL,
`balance_weight` varchar(10) NOT NULL,
`balance_blocker` varchar(5) NOT NULL,
`balance_disabled` varchar(24) NOT NULL,
`weight` DECIMAL(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_action` (`tpid`,`tag`,`action`,`balance_tag`,`balance_type`,`expiry_time`,`timing_tags`,`destination_tags`,`shared_groups`,`balance_weight`,`weight`)
);
--
-- Table structure for table `tp_action_timings`
--
DROP TABLE IF EXISTS `tp_action_plans`;
CREATE TABLE `tp_action_plans` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`actions_tag` varchar(64) NOT NULL,
`timing_tag` varchar(64) NOT NULL,
`weight` DECIMAL(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_action_schedule` (`tpid`,`tag`,`actions_tag`,`timing_tag`)
);
--
-- Table structure for table `tp_action_triggers`
--
DROP TABLE IF EXISTS `tp_action_triggers`;
CREATE TABLE `tp_action_triggers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tag` varchar(64) NOT NULL,
`unique_id` varchar(64) NOT NULL,
`threshold_type` char(64) NOT NULL,
`threshold_value` DECIMAL(20,4) NOT NULL,
`recurrent` BOOLEAN NOT NULL,
`min_sleep` varchar(16) NOT NULL,
`expiry_time` varchar(26) NOT NULL,
`activation_time` varchar(26) NOT NULL,
`balance_tag` varchar(64) NOT NULL,
`balance_type` varchar(24) NOT NULL,
`balance_categories` varchar(32) NOT NULL,
`balance_destination_tags` varchar(64) NOT NULL,
`balance_rating_subject` varchar(64) NOT NULL,
`balance_shared_groups` varchar(64) NOT NULL,
`balance_expiry_time` varchar(26) NOT NULL,
`balance_timing_tags` varchar(128) NOT NULL,
`balance_weight` varchar(10) NOT NULL,
`balance_blocker` varchar(5) NOT NULL,
`balance_disabled` varchar(5) NOT NULL,
`actions_tag` varchar(64) NOT NULL,
`weight` DECIMAL(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_trigger_definition` (`tpid`,`tag`,`balance_tag`,`balance_type`,`threshold_type`,`threshold_value`,`balance_destination_tags`,`actions_tag`)
);
--
-- Table structure for table `tp_account_actions`
--
DROP TABLE IF EXISTS `tp_account_actions`;
CREATE TABLE `tp_account_actions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`loadid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`account` varchar(64) NOT NULL,
`action_plan_tag` varchar(64),
`action_triggers_tag` varchar(64),
`allow_negative` BOOLEAN NOT NULL,
`disabled` BOOLEAN NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_account` (`tpid`,`loadid`,`tenant`,`account`)
);
--
-- Table structure for table `tp_resources`
--
DROP TABLE IF EXISTS tp_resources;
CREATE TABLE tp_resources (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`usage_ttl` varchar(32) NOT NULL,
`limit` varchar(64) NOT NULL,
`allocation_message` varchar(64) NOT NULL,
`blocker` BOOLEAN NOT NULL,
`stored` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,
`threshold_ids` varchar(64) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_resource` (`tpid`,`tenant`, `id`,`filter_ids` )
);
--
-- Table structure for table `tp_stats`
--
DROP TABLE IF EXISTS tp_stats;
CREATE TABLE tp_stats (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`queue_length` int(11) NOT NULL,
`ttl` varchar(32) NOT NULL,
`min_items` int(11) NOT NULL,
`metric_ids` varchar(128) NOT NULL,
`metric_filter_ids` varchar(64) NOT NULL,
`stored` BOOLEAN NOT NULL,
`blocker` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,
`threshold_ids` varchar(64) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_stats` (`tpid`, `tenant`, `id`, `filter_ids`,`metric_ids`)
);
--
-- Table structure for table `tp_threshold_cfgs`
--
DROP TABLE IF EXISTS tp_thresholds;
CREATE TABLE tp_thresholds (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`max_hits` int(11) NOT NULL,
`min_hits` int(11) NOT NULL,
`min_sleep` varchar(16) NOT NULL,
`blocker` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,
`action_ids` varchar(64) NOT NULL,
`async` BOOLEAN NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_thresholds` (`tpid`,`tenant`, `id`,`filter_ids`,`action_ids`)
);
--
-- Table structure for table `tp_filter`
--
DROP TABLE IF EXISTS tp_filters;
CREATE TABLE tp_filters (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`type` varchar(16) NOT NULL,
`element` varchar(64) NOT NULL,
`values` varchar(256) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_filters` (`tpid`,`tenant`, `id`, `type`, `element`)
);
--
-- Table structure for table `tp_routes`
--
DROP TABLE IF EXISTS tp_routes;
CREATE TABLE tp_routes (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`sorting` varchar(32) NOT NULL,
`sorting_parameters` varchar(64) NOT NULL,
`route_id` varchar(32) NOT NULL,
`route_filter_ids` varchar(64) NOT NULL,
`route_account_ids` varchar(64) NOT NULL,
`route_ratingplan_ids` varchar(64) NOT NULL,
`route_rate_profile_ids` varchar(64) NOT NULL,
`route_resource_ids` varchar(64) NOT NULL,
`route_stat_ids` varchar(64) NOT NULL,
`route_weight` decimal(8,2) NOT NULL,
`route_blocker` BOOLEAN NOT NULL,
`route_parameters` varchar(64) NOT NULL,
`weight` decimal(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_routes` (`tpid`,`tenant`,
`id`,`filter_ids`,`route_id`,`route_filter_ids`,`route_account_ids`,
`route_ratingplan_ids`,`route_resource_ids`,`route_stat_ids` )
);
--
-- Table structure for table `tp_attributes`
--
DROP TABLE IF EXISTS tp_attributes;
CREATE TABLE tp_attributes (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`contexts` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`attribute_filter_ids` varchar(64) NOT NULL,
`path` varchar(64) NOT NULL,
`type` varchar(64) NOT NULL,
`value` varchar(64) NOT NULL,
`blocker` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_attributes` (`tpid`,`tenant`,
`id`,`filter_ids`,`path`,`value` )
);
--
-- Table structure for table `tp_chargers`
--
DROP TABLE IF EXISTS tp_chargers;
CREATE TABLE tp_chargers (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`run_id` varchar(64) NOT NULL,
`attribute_ids` varchar(64) NOT NULL,
`weight` decimal(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_chargers` (`tpid`,`tenant`,
`id`,`filter_ids`,`run_id`,`attribute_ids`)
);
--
-- Table structure for table `tp_dispatchers`
--
DROP TABLE IF EXISTS tp_dispatcher_profiles;
CREATE TABLE tp_dispatcher_profiles (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`subsystems` varchar(64) NOT NULL,
`filter_ids` varchar(64) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`strategy` varchar(64) NOT NULL,
`strategy_parameters` varchar(64) NOT NULL,
`conn_id` varchar(64) NOT NULL,
`conn_filter_ids` varchar(64) NOT NULL,
`conn_weight` decimal(8,2) NOT NULL,
`conn_blocker` BOOLEAN NOT NULL,
`conn_parameters` varchar(64) NOT NULL,
`weight` decimal(8,2) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_dispatcher_profiles` (`tpid`,`tenant`,
`id`,`filter_ids`,`strategy`,`conn_id`,`conn_filter_ids`)
);
--
-- Table structure for table `tp_dispatchers`
--
DROP TABLE IF EXISTS tp_dispatcher_hosts;
CREATE TABLE tp_dispatcher_hosts (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tpid` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
`id` varchar(64) NOT NULL,
`address` varchar(64) NOT NULL,
`transport` varchar(64) NOT NULL,
`connect_attempts` int(11) NOT NULL,
`reconnects` int(11) NOT NULL,
`max_reconnect_interval` varchar(64) NOT NULL,
`connect_timeout` varchar(64) NOT NULL,
`reply_timeout` varchar(64) NOT NULL,
`tls` BOOLEAN NOT NULL,
`client_key` varchar(64) NOT NULL,
`client_certificate` varchar(64) NOT NULL,
`ca_certificate` varchar(64) NOT NULL,
`created_at` TIMESTAMP,
PRIMARY KEY (`pk`),
KEY `tpid` (`tpid`),
UNIQUE KEY `unique_tp_dispatchers_hosts` (`tpid`,`tenant`,
`id`,`address`)
);
--
-- Table structure for table `versions`
--
DROP TABLE IF EXISTS versions;
CREATE TABLE versions (
`id` int(11) NOT NULL AUTO_INCREMENT,
`item` varchar(64) NOT NULL,
`version` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_item` (`id`,`item`)
);

View File

@@ -0,0 +1,57 @@
/*
This script will migrate CDRs from the old CGRateS tables to the new cdrs table
but it only migrate CDRs where the duration is > 0.
If you need CDRs also with duration is = 0 you can make the appropriate change in the line beginning WHERE cdrs_primary.usage
Also the script will process 10,000 CDRs before committing to save system resources
especially in systems where they are millions of CDRs to be migrated
You can increase or lower the value of step in the line after BEGIN below.
You have to use 'CALL cgrates.migration();' to execute the script. If named other then default use that database name.
*/
DELIMITER //
CREATE PROCEDURE `migration`()
BEGIN
/* DECLARE variables */
DECLARE max_cdrs bigint;
DECLARE start_id bigint;
DECLARE end_id bigint;
DECLARE step bigint;
/* Optimize table for performance */
ALTER TABLE cdrs DISABLE KEYS;
SET autocommit=0;
SET unique_checks=0;
SET foreign_key_checks=0;
/* You must change the step var to commit every step rows inserted */
SET step := 10000;
SET start_id := 0;
SET end_id := start_id + step;
SET max_cdrs = (select max(id) from rated_cdrs);
WHILE (start_id <= max_cdrs) DO
INSERT INTO
cdrs(cgrid,run_id,origin_host,source,origin_id,tor,request_type,tenant,category,account,subject,destination,setup_time,pdd,answer_time,`usage`,supplier,disconnect_cause,extra_fields,cost_source,cost,cost_details,extra_info, created_at, updated_at, deleted_at)
SELECT cdrs_primary.cgrid,rated_cdrs.runid as run_id,cdrs_primary.cdrhost as origin_host,cdrs_primary.cdrsource as source,cdrs_primary.accid as origin_id, cdrs_primary.tor,rated_cdrs.reqtype as request_type, rated_cdrs.tenant,rated_cdrs.category, rated_cdrs.account, rated_cdrs.subject, rated_cdrs.destination,rated_cdrs.setup_time,rated_cdrs.pdd,rated_cdrs.answer_time,rated_cdrs.`usage`,rated_cdrs.supplier,rated_cdrs.disconnect_cause,cdrs_extra.extra_fields,cost_details.cost_source,rated_cdrs.cost,cost_details.timespans as cost_details,rated_cdrs.extra_info,rated_cdrs.created_at,rated_cdrs.updated_at, rated_cdrs.deleted_at
FROM rated_cdrs
INNER JOIN cdrs_primary ON rated_cdrs.cgrid = cdrs_primary.cgrid
INNER JOIN cdrs_extra ON rated_cdrs.cgrid = cdrs_extra.cgrid
INNER JOIN cost_details ON rated_cdrs.cgrid = cost_details.cgrid
WHERE cdrs_primary.`usage` > '0'
AND not exists (select 1 from cdrs where cdrs.cgrid = cdrs_primary.cgrid AND cdrs.run_id=rated_cdrs.runid)
AND rated_cdrs.id >= start_id
AND rated_cdrs.id < end_id
GROUP BY cgrid, run_id, origin_id;
SET start_id = start_id + step;
SET end_id = end_id + step;
END WHILE;
/* SET Table for live usage */
SET autocommit=1;
SET unique_checks=1;
SET foreign_key_checks=1;
ALTER TABLE cdrs ENABLE KEYS;
OPTIMIZE TABLE cdrs;
END //
DELIMITER ;

View File

@@ -0,0 +1,29 @@
#! /usr/bin/env sh
if test $# -lt 2; then
echo ""
echo "setup_cgr_db.sh <db_user> <db_password> [<db_host>]"
echo ""
exit 0
fi
host=$3
if [ -z "$3" ]; then
host="localhost"
fi
DIR="$(dirname "$(readlink -f "$0")")"
mysql -u $1 -p$2 -h $host < "$DIR"/create_db_with_users.sql
cu=$?
mysql -u $1 -p$2 -h $host -D cgrates < "$DIR"/create_cdrs_tables.sql
cdrt=$?
mysql -u $1 -p$2 -h $host -D cgrates < "$DIR"/create_tariffplan_tables.sql
tpt=$?
if [ $cu = 0 ] && [ $cdrt = 0 ] && [ $tpt = 0 ]; then
echo "\n\t+++ CGR-DB successfully set-up! +++\n"
exit 0
fi

View File

@@ -0,0 +1,25 @@
#! /usr/bin/env sh
if test $# -lt 2; then
echo ""
echo "setup_cgr_db.sh <db_user> <db_password> [<db_host>]"
echo ""
exit 0
fi
host=$3
if [ -z "$3" ]; then
host="localhost"
fi
DIR="$(dirname "$(readlink -f "$0")")"
mysql -u $1 -p$2 -h $host < "$DIR"/create_ers_db.sql
cu=$?
if [ $cu = 0 ]; then
echo "\n\t+++ CGR-DB successfully set-up! +++\n"
exit 0
fi

View File

@@ -0,0 +1,59 @@
--
-- Table structure for table `cdrs`
--
DROP TABLE IF EXISTS cdrs;
CREATE TABLE cdrs (
id SERIAL PRIMARY KEY,
cgrid VARCHAR(40) NOT NULL,
run_id VARCHAR(64) NOT NULL,
origin_host VARCHAR(64) NOT NULL,
source VARCHAR(64) NOT NULL,
origin_id VARCHAR(128) NOT NULL,
tor VARCHAR(16) NOT NULL,
request_type VARCHAR(24) NOT NULL,
tenant VARCHAR(64) NOT NULL,
category VARCHAR(64) NOT NULL,
account VARCHAR(128) NOT NULL,
subject VARCHAR(128) NOT NULL,
destination VARCHAR(128) NOT NULL,
setup_time TIMESTAMP WITH TIME ZONE NOT NULL,
answer_time TIMESTAMP WITH TIME ZONE NULL,
usage BIGINT NOT NULL,
extra_fields jsonb NOT NULL,
cost_source VARCHAR(64) NOT NULL,
cost NUMERIC(20,4) DEFAULT NULL,
cost_details jsonb,
extra_info text,
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE NULL,
deleted_at TIMESTAMP WITH TIME ZONE NULL,
UNIQUE (cgrid, run_id)
);
;
DROP INDEX IF EXISTS deleted_at_cp_idx;
CREATE INDEX deleted_at_cp_idx ON cdrs (deleted_at);
DROP TABLE IF EXISTS session_costs;
CREATE TABLE session_costs (
id SERIAL PRIMARY KEY,
cgrid VARCHAR(40) NOT NULL,
run_id VARCHAR(64) NOT NULL,
origin_host VARCHAR(64) NOT NULL,
origin_id VARCHAR(128) NOT NULL,
cost_source VARCHAR(64) NOT NULL,
usage BIGINT NOT NULL,
cost_details jsonb,
created_at TIMESTAMP WITH TIME ZONE,
deleted_at TIMESTAMP WITH TIME ZONE NULL,
UNIQUE (cgrid, run_id)
);
DROP INDEX IF EXISTS cgrid_sessionscost_idx;
CREATE INDEX cgrid_sessionscost_idx ON session_costs (cgrid, run_id);
DROP INDEX IF EXISTS origin_sessionscost_idx;
CREATE INDEX origin_sessionscost_idx ON session_costs (origin_host, origin_id);
DROP INDEX IF EXISTS run_origin_sessionscost_idx;
CREATE INDEX run_origin_sessionscost_idx ON session_costs (run_id, origin_id);
DROP INDEX IF EXISTS deleted_at_sessionscost_idx;
CREATE INDEX deleted_at_sessionscost_idx ON session_costs (deleted_at);

View File

@@ -0,0 +1,10 @@
#!/bin/bash
#
# Sample db and users creation. Replace here with your own details
#
sudo -u postgres dropdb -e cgrates
sudo -u postgres dropuser -e cgrates
sudo -u postgres psql -c "CREATE USER cgrates password 'CGRateS.org';"
sudo -u postgres createdb -e -O cgrates cgrates

View File

@@ -0,0 +1,5 @@
#!/bin/bash
# extra DB for ers
sudo -u postgres dropdb -e cgrates2
sudo -u postgres createdb -e -O cgrates cgrates2

View File

@@ -0,0 +1,478 @@
--
-- Table structure for table `tp_timings`
--
DROP TABLE IF EXISTS tp_timings;
CREATE TABLE tp_timings (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
years VARCHAR(255) NOT NULL,
months VARCHAR(255) NOT NULL,
month_days VARCHAR(255) NOT NULL,
week_days VARCHAR(255) NOT NULL,
time VARCHAR(32) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag)
);
CREATE INDEX tptimings_tpid_idx ON tp_timings (tpid);
CREATE INDEX tptimings_idx ON tp_timings (tpid,tag);
--
-- Table structure for table `tp_destinations`
--
DROP TABLE IF EXISTS tp_destinations;
CREATE TABLE tp_destinations (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
prefix VARCHAR(24) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, prefix)
);
CREATE INDEX tpdests_tpid_idx ON tp_destinations (tpid);
CREATE INDEX tpdests_idx ON tp_destinations (tpid,tag);
--
-- Table structure for table `tp_rates`
--
DROP TABLE IF EXISTS tp_rates;
CREATE TABLE tp_rates (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
connect_fee NUMERIC(7,4) NOT NULL,
rate NUMERIC(10,4) NOT NULL,
rate_unit VARCHAR(16) NOT NULL,
rate_increment VARCHAR(16) NOT NULL,
group_interval_start VARCHAR(16) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, group_interval_start)
);
CREATE INDEX tprates_tpid_idx ON tp_rates (tpid);
CREATE INDEX tprates_idx ON tp_rates (tpid,tag);
--
-- Table structure for table `destination_rates`
--
DROP TABLE IF EXISTS tp_destination_rates;
CREATE TABLE tp_destination_rates (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
destinations_tag VARCHAR(64) NOT NULL,
rates_tag VARCHAR(64) NOT NULL,
rounding_method VARCHAR(255) NOT NULL,
rounding_decimals SMALLINT NOT NULL,
max_cost NUMERIC(7,4) NOT NULL,
max_cost_strategy VARCHAR(16) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag , destinations_tag)
);
CREATE INDEX tpdestrates_tpid_idx ON tp_destination_rates (tpid);
CREATE INDEX tpdestrates_idx ON tp_destination_rates (tpid,tag);
--
-- Table structure for table `tp_rating_plans`
--
DROP TABLE IF EXISTS tp_rating_plans;
CREATE TABLE tp_rating_plans (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
destrates_tag VARCHAR(64) NOT NULL,
timing_tag VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, destrates_tag, timing_tag)
);
CREATE INDEX tpratingplans_tpid_idx ON tp_rating_plans (tpid);
CREATE INDEX tpratingplans_idx ON tp_rating_plans (tpid,tag);
--
-- Table structure for table `tp_rate_profiles`
--
DROP TABLE IF EXISTS tp_rating_profiles;
CREATE TABLE tp_rating_profiles (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
loadid VARCHAR(64) NOT NULL,
tenant VARCHAR(64) NOT NULL,
category VARCHAR(32) NOT NULL,
subject VARCHAR(64) NOT NULL,
activation_time VARCHAR(26) NOT NULL,
rating_plan_tag VARCHAR(64) NOT NULL,
fallback_subjects VARCHAR(64),
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, loadid, tenant, category, subject, activation_time)
);
CREATE INDEX tpratingprofiles_tpid_idx ON tp_rating_profiles (tpid);
CREATE INDEX tpratingprofiles_idx ON tp_rating_profiles (tpid,loadid,tenant,category,subject);
--
-- Table structure for table `tp_shared_groups`
--
DROP TABLE IF EXISTS tp_shared_groups;
CREATE TABLE tp_shared_groups (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
account VARCHAR(64) NOT NULL,
strategy VARCHAR(24) NOT NULL,
rating_subject VARCHAR(24) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, account , strategy , rating_subject)
);
CREATE INDEX tpsharedgroups_tpid_idx ON tp_shared_groups (tpid);
CREATE INDEX tpsharedgroups_idx ON tp_shared_groups (tpid,tag);
--
-- Table structure for table `tp_actions`
--
DROP TABLE IF EXISTS tp_actions;
CREATE TABLE tp_actions (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
action VARCHAR(24) NOT NULL,
extra_parameters VARCHAR(256) NOT NULL,
filters VARCHAR(256) NOT NULL,
balance_tag VARCHAR(64) NOT NULL,
balance_type VARCHAR(24) NOT NULL,
categories VARCHAR(32) NOT NULL,
destination_tags VARCHAR(64) NOT NULL,
rating_subject VARCHAR(64) NOT NULL,
shared_groups VARCHAR(64) NOT NULL,
expiry_time VARCHAR(26) NOT NULL,
timing_tags VARCHAR(128) NOT NULL,
units VARCHAR(256) NOT NULL,
balance_weight VARCHAR(10) NOT NULL,
balance_blocker VARCHAR(5) NOT NULL,
balance_disabled VARCHAR(5) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, action, balance_tag, balance_type, expiry_time, timing_tags, destination_tags, shared_groups, balance_weight, weight)
);
CREATE INDEX tpactions_tpid_idx ON tp_actions (tpid);
CREATE INDEX tpactions_idx ON tp_actions (tpid,tag);
--
-- Table structure for table `tp_action_timings`
--
DROP TABLE IF EXISTS tp_action_plans;
CREATE TABLE tp_action_plans (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
actions_tag VARCHAR(64) NOT NULL,
timing_tag VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, actions_tag, timing_tag)
);
CREATE INDEX tpactionplans_tpid_idx ON tp_action_plans (tpid);
CREATE INDEX tpactionplans_idx ON tp_action_plans (tpid,tag);
--
-- Table structure for table tp_action_triggers
--
DROP TABLE IF EXISTS tp_action_triggers;
CREATE TABLE tp_action_triggers (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
tag VARCHAR(64) NOT NULL,
unique_id VARCHAR(64) NOT NULL,
threshold_type VARCHAR(64) NOT NULL,
threshold_value NUMERIC(20,4) NOT NULL,
recurrent BOOLEAN NOT NULL,
min_sleep VARCHAR(16) NOT NULL,
expiry_time VARCHAR(26) NOT NULL,
activation_time VARCHAR(26) NOT NULL,
balance_tag VARCHAR(64) NOT NULL,
balance_type VARCHAR(24) NOT NULL,
balance_categories VARCHAR(32) NOT NULL,
balance_destination_tags VARCHAR(64) NOT NULL,
balance_rating_subject VARCHAR(64) NOT NULL,
balance_shared_groups VARCHAR(64) NOT NULL,
balance_expiry_time VARCHAR(26) NOT NULL,
balance_timing_tags VARCHAR(128) NOT NULL,
balance_weight VARCHAR(10) NOT NULL,
balance_blocker VARCHAR(5) NOT NULL,
balance_disabled VARCHAR(5) NOT NULL,
actions_tag VARCHAR(64) NOT NULL,
weight NUMERIC(8,2) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, tag, balance_tag, balance_type, threshold_type, threshold_value, balance_destination_tags, actions_tag)
);
CREATE INDEX tpactiontrigers_tpid_idx ON tp_action_triggers (tpid);
CREATE INDEX tpactiontrigers_idx ON tp_action_triggers (tpid,tag);
--
-- Table structure for table tp_account_actions
--
DROP TABLE IF EXISTS tp_account_actions;
CREATE TABLE tp_account_actions (
id SERIAL PRIMARY KEY,
tpid VARCHAR(64) NOT NULL,
loadid VARCHAR(64) NOT NULL,
tenant VARCHAR(64) NOT NULL,
account VARCHAR(64) NOT NULL,
action_plan_tag VARCHAR(64),
action_triggers_tag VARCHAR(64),
allow_negative BOOLEAN NOT NULL,
disabled BOOLEAN NOT NULL,
created_at TIMESTAMP WITH TIME ZONE,
UNIQUE (tpid, loadid, tenant, account)
);
CREATE INDEX tpaccountactions_tpid_idx ON tp_account_actions (tpid);
CREATE INDEX tpaccountactions_idx ON tp_account_actions (tpid,loadid,tenant,account);
--
-- Table structure for table `tp_resources`
--
DROP TABLE IF EXISTS tp_resources;
CREATE TABLE tp_resources (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant"varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"usage_ttl" varchar(32) NOT NULL,
"limit" varchar(64) NOT NULL,
"allocation_message" varchar(64) NOT NULL,
"blocker" BOOLEAN NOT NULL,
"stored" BOOLEAN NOT NULL,
"weight" NUMERIC(8,2) NOT NULL,
"threshold_ids" varchar(64) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_resources_idx ON tp_resources (tpid);
CREATE INDEX tp_resources_unique ON tp_resources ("tpid", "tenant", "id", "filter_ids");
--
-- Table structure for table `tp_stats`
--
DROP TABLE IF EXISTS tp_stats;
CREATE TABLE tp_stats (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant"varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"queue_length" INTEGER NOT NULL,
"ttl" varchar(32) NOT NULL,
"min_items" INTEGER NOT NULL,
"metric_ids" VARCHAR(128) NOT NULL,
"metric_filter_ids" VARCHAR(128) NOT NULL,
"stored" BOOLEAN NOT NULL,
"blocker" BOOLEAN NOT NULL,
"weight" decimal(8,2) NOT NULL,
"threshold_ids" varchar(64) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_stats_idx ON tp_stats (tpid);
CREATE INDEX tp_stats_unique ON tp_stats ("tpid","tenant", "id", "filter_ids","metric_ids");
--
-- Table structure for table `tp_threshold_cfgs`
--
DROP TABLE IF EXISTS tp_thresholds;
CREATE TABLE tp_thresholds (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant"varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"max_hits" INTEGER NOT NULL,
"min_hits" INTEGER NOT NULL,
"min_sleep" varchar(16) NOT NULL,
"blocker" BOOLEAN NOT NULL,
"weight" decimal(8,2) NOT NULL,
"action_ids" varchar(64) NOT NULL,
"async" BOOLEAN NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_thresholds_idx ON tp_thresholds (tpid);
CREATE INDEX tp_thresholds_unique ON tp_thresholds ("tpid","tenant", "id","filter_ids","action_ids");
--
-- Table structure for table `tp_filter`
--
DROP TABLE IF EXISTS tp_filters;
CREATE TABLE tp_filters (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant" varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"type" varchar(16) NOT NULL,
"element" varchar(64) NOT NULL,
"values" varchar(256) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_filters_idx ON tp_filters (tpid);
CREATE INDEX tp_filters_unique ON tp_filters ("tpid","tenant", "id", "type", "element");
--
-- Table structure for table `tp_routes`
--
DROP TABLE IF EXISTS tp_routes;
CREATE TABLE tp_routes (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant"varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"sorting" varchar(32) NOT NULL,
"sorting_parameters" varchar(64) NOT NULL,
"route_id" varchar(32) NOT NULL,
"route_filter_ids" varchar(64) NOT NULL,
"route_account_ids" varchar(64) NOT NULL,
"route_ratingplan_ids" varchar(64) NOT NULL,
"route_resource_ids" varchar(64) NOT NULL,
"route_stat_ids" varchar(64) NOT NULL,
"route_weight" decimal(8,2) NOT NULL,
"route_blocker" BOOLEAN NOT NULL,
"route_parameters" varchar(64) NOT NULL,
"weight" decimal(8,2) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_routes_idx ON tp_routes (tpid);
CREATE INDEX tp_routes_unique ON tp_routes ("tpid", "tenant", "id",
"filter_ids","route_id","route_filter_ids","route_account_ids",
"route_ratingplan_ids","route_resource_ids","route_stat_ids");
--
-- Table structure for table `tp_attributes`
--
DROP TABLE IF EXISTS tp_attributes;
CREATE TABLE tp_attributes (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant"varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"contexts" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"attribute_filter_ids" varchar(64) NOT NULL,
"path" varchar(64) NOT NULL,
"type" varchar(64) NOT NULL,
"value" varchar(64) NOT NULL,
"blocker" BOOLEAN NOT NULL,
"weight" decimal(8,2) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_attributes_ids ON tp_attributes (tpid);
CREATE INDEX tp_attributes_unique ON tp_attributes ("tpid", "tenant", "id",
"filter_ids","path","value");
--
-- Table structure for table `tp_chargers`
--
DROP TABLE IF EXISTS tp_chargers;
CREATE TABLE tp_chargers (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant"varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"run_id" varchar(64) NOT NULL,
"attribute_ids" varchar(64) NOT NULL,
"weight" decimal(8,2) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_chargers_ids ON tp_chargers (tpid);
CREATE INDEX tp_chargers_unique ON tp_chargers ("tpid", "tenant", "id",
"filter_ids","run_id","attribute_ids");
--
-- Table structure for table `tp_dispatchers`
--
DROP TABLE IF EXISTS tp_dispatcher_profiles;
CREATE TABLE tp_dispatcher_profiles (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant" varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"subsystems" varchar(64) NOT NULL,
"filter_ids" varchar(64) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"strategy" varchar(64) NOT NULL,
"strategy_parameters" varchar(64) NOT NULL,
"conn_id" varchar(64) NOT NULL,
"conn_filter_ids" varchar(64) NOT NULL,
"conn_weight" decimal(8,2) NOT NULL,
"conn_blocker" BOOLEAN NOT NULL,
"conn_parameters" varchar(64) NOT NULL,
"weight" decimal(8,2) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_dispatcher_profiles_ids ON tp_dispatcher_profiles (tpid);
CREATE INDEX tp_dispatcher_profiles_unique ON tp_dispatcher_profiles ("tpid", "tenant", "id",
"filter_ids","strategy","conn_id","conn_filter_ids");
--
-- Table structure for table `tp_dispatchers`
--
DROP TABLE IF EXISTS tp_dispatcher_hosts;
CREATE TABLE tp_dispatcher_hosts (
"pk" SERIAL PRIMARY KEY,
"tpid" varchar(64) NOT NULL,
"tenant" varchar(64) NOT NULL,
"id" varchar(64) NOT NULL,
"address" varchar(64) NOT NULL,
"transport" varchar(64) NOT NULL,
"connect_attempts" INTEGER NOT NULL,
"reconnects" INTEGER NOT NULL,
"max_reconnect_interval" varchar(64) NOT NULL,
"connect_timeout" varchar(64) NOT NULL,
"reply_timeout" varchar(64) NOT NULL,
"tls" BOOLEAN NOT NULL,
"client_key" varchar(64) NOT NULL,
"client_certificate" varchar(64) NOT NULL,
"ca_certificate" varchar(64) NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE
);
CREATE INDEX tp_dispatchers_hosts_ids ON tp_dispatcher_hosts (tpid);
CREATE INDEX tp_dispatcher_hosts_unique ON tp_dispatcher_hosts ("tpid", "tenant", "id",
"address");
--
-- Table structure for table `versions`
--
DROP TABLE IF EXISTS versions;
CREATE TABLE versions (
"id" SERIAL PRIMARY KEY,
"item" varchar(64) NOT NULL,
"version" INTEGER NOT NULL,
UNIQUE ("id","item")
);

View File

@@ -0,0 +1,42 @@
/*
This script will migrate CDRs from the old CGRateS tables to the new cdrs table
but it only migrate CDRs where the duration is > 0.
If you need CDRs also with duration is = 0 you can make the appropriate change in the line beginning WHERE cdrs_primary.usage
Also the script will process 10,000 CDRs before committing to save system resources
especially in systems where they are millions of CDRs to be migrated
You can increase or lower the value of step in the line after BEGIN below.
*/
DO $$
DECLARE
max_cdrs bigint;
start_id bigint;
end_id bigint;
step bigint;
BEGIN
/* You must change the step var to commit every step rows inserted */
step := 10000;
start_id := 0;
end_id := start_id + step;
select max(id) INTO max_cdrs from rated_cdrs;
WHILE start_id <= max_cdrs
LOOP
--RAISE NOTICE '%', (to_char(start_id, '99999999') || '-' || to_char(end_id, '99999999'));
INSERT INTO
cdrs(cgrid,run_id,origin_host,source,origin_id,tor,request_type,tenant,category,account,subject,destination,setup_time,pdd,answer_time,usage,supplier,disconnect_cause,extra_fields,cost_source,cost,cost_details,extra_info, created_at, updated_at, deleted_at)
SELECT cdrs_primary.cgrid,rated_cdrs.runid as run_id,cdrs_primary.cdrhost as origin_host,cdrs_primary.cdrsource as source,cdrs_primary.accid as origin_id, cdrs_primary.tor,rated_cdrs.reqtype as request_type, rated_cdrs.tenant,rated_cdrs.category, rated_cdrs.account, rated_cdrs.subject, rated_cdrs.destination,rated_cdrs.setup_time,rated_cdrs.pdd,rated_cdrs.answer_time,rated_cdrs.usage,rated_cdrs.supplier,rated_cdrs.disconnect_cause,cdrs_extra.extra_fields,cost_details.cost_source,rated_cdrs.cost,cost_details.timespans as cost_details,rated_cdrs.extra_info,rated_cdrs.created_at,rated_cdrs.updated_at, rated_cdrs.deleted_at
FROM rated_cdrs
INNER JOIN cdrs_primary ON rated_cdrs.cgrid = cdrs_primary.cgrid
INNER JOIN cdrs_extra ON rated_cdrs.cgrid = cdrs_extra.cgrid
INNER JOIN cost_details ON rated_cdrs.cgrid = cost_details.cgrid
WHERE cdrs_primary.usage > '0'
AND not exists (select 1 from cdrs c where c.cgrid = cdrs_primary.cgrid)
AND rated_cdrs.id >= start_id
AND rated_cdrs.id < end_id
;
start_id = start_id + step;
end_id = end_id + step;
END LOOP;
END
$$;

View File

@@ -0,0 +1,30 @@
#! /usr/bin/env sh
user=$1
if [ -z "$1" ]; then
user="cgrates"
fi
host=$2
if [ -z "$2" ]; then
host="localhost"
fi
DIR="$(dirname "$(readlink -f "$0")")"
"$DIR"/create_db_with_users.sh
export PGPASSWORD="CGRateS.org"
psql -U $user -h $host -d cgrates -f "$DIR"/create_cdrs_tables.sql
cdrt=$?
psql -U $user -h $host -d cgrates -f "$DIR"/create_tariffplan_tables.sql
tpt=$?
if [ $cdrt = 0 ] && [ $tpt = 0 ]; then
echo "\n\t+++ CGR-DB successfully set-up! +++\n"
exit 0
fi

View File

@@ -0,0 +1,29 @@
#!/bin/bash
if [ $# -ne 2 ]; then
exit 1
fi
if [ $1 != "rabbitmq-server" ]; then
exit 1
fi
case "$2" in
"restart")
rabbitmqctl stop >/logs/rabbitmq.log 2>&1
rabbitmq-server >/logs/rabbitmq.log 2>&1 &
sleep 5s
echo "Done restart"
exit 0;;
"start")
rabbitmq-server >/logs/rabbitmq.log 2>&1 &
sleep 5s
echo "Done start"
exit 0;;
"stop")
rabbitmqctl stop >/logs/rabbitmq.log 2>&1
echo "Done stop"
exit 0;;
*)
exit 1;;
esac